... | ... |
@@ -119,8 +119,10 @@ func validate(cmd *cobra.Command, f *clientcmd.Factory, args []string) error { |
119 | 119 |
supportsTCP := false |
120 | 120 |
for _, port := range svc.Spec.Ports { |
121 | 121 |
if port.Protocol == kapi.ProtocolTCP { |
122 |
- // Pass service target port as the route port |
|
123 |
- cmd.Flags().Set("port", port.TargetPort.String()) |
|
122 |
+ if len(port.Name) > 0 { |
|
123 |
+ // Pass service port name as the route target port, if it is named |
|
124 |
+ cmd.Flags().Set("target-port", port.Name) |
|
125 |
+ } |
|
124 | 126 |
supportsTCP = true |
125 | 127 |
break |
126 | 128 |
} |
... | ... |
@@ -2,7 +2,6 @@ package generator |
2 | 2 |
|
3 | 3 |
import ( |
4 | 4 |
"fmt" |
5 |
- "strings" |
|
6 | 5 |
|
7 | 6 |
kapi "k8s.io/kubernetes/pkg/api" |
8 | 7 |
"k8s.io/kubernetes/pkg/kubectl" |
... | ... |
@@ -23,8 +22,7 @@ func (RouteGenerator) ParamNames() []kubectl.GeneratorParam { |
23 | 23 |
return []kubectl.GeneratorParam{ |
24 | 24 |
{"labels", false}, |
25 | 25 |
{"default-name", true}, |
26 |
- {"port", false}, |
|
27 |
- {"ports", false}, |
|
26 |
+ {"target-port", false}, |
|
28 | 27 |
{"name", false}, |
29 | 28 |
{"hostname", false}, |
30 | 29 |
} |
... | ... |
@@ -62,16 +60,7 @@ func (RouteGenerator) Generate(genericParams map[string]interface{}) (runtime.Ob |
62 | 62 |
} |
63 | 63 |
} |
64 | 64 |
|
65 |
- var portString string |
|
66 |
- portString, found = params["port"] |
|
67 |
- if !found || len(portString) == 0 { |
|
68 |
- portString = strings.Split(params["ports"], ",")[0] |
|
69 |
- } |
|
70 |
- if len(portString) == 0 { |
|
71 |
- return nil, fmt.Errorf("exposed service does not have any target ports specified") |
|
72 |
- } |
|
73 |
- |
|
74 |
- return &api.Route{ |
|
65 |
+ route := &api.Route{ |
|
75 | 66 |
ObjectMeta: kapi.ObjectMeta{ |
76 | 67 |
Name: name, |
77 | 68 |
Labels: labels, |
... | ... |
@@ -81,9 +70,15 @@ func (RouteGenerator) Generate(genericParams map[string]interface{}) (runtime.Ob |
81 | 81 |
To: kapi.ObjectReference{ |
82 | 82 |
Name: params["default-name"], |
83 | 83 |
}, |
84 |
- Port: &api.RoutePort{ |
|
85 |
- TargetPort: util.NewIntOrStringFromString(portString), |
|
86 |
- }, |
|
87 | 84 |
}, |
88 |
- }, nil |
|
85 |
+ } |
|
86 |
+ |
|
87 |
+ portString := params["target-port"] |
|
88 |
+ if len(portString) > 0 { |
|
89 |
+ route.Spec.Port = &api.RoutePort{ |
|
90 |
+ TargetPort: util.NewIntOrStringFromString(portString), |
|
91 |
+ } |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ return route, nil |
|
89 | 95 |
} |
... | ... |
@@ -23,6 +23,8 @@ func TestGenerateRoute(t *testing.T) { |
23 | 23 |
"name": "test", |
24 | 24 |
"default-name": "someservice", |
25 | 25 |
"port": "80", |
26 |
+ "ports": "80,443", |
|
27 |
+ "target-port": "svcportname", |
|
26 | 28 |
"hostname": "www.example.com", |
27 | 29 |
}, |
28 | 30 |
expected: routeapi.Route{ |
... | ... |
@@ -40,7 +42,7 @@ func TestGenerateRoute(t *testing.T) { |
40 | 40 |
Port: &routeapi.RoutePort{ |
41 | 41 |
TargetPort: util.IntOrString{ |
42 | 42 |
Kind: util.IntstrString, |
43 |
- StrVal: "80", |
|
43 |
+ StrVal: "svcportname", |
|
44 | 44 |
}, |
45 | 45 |
}, |
46 | 46 |
}, |
... | ... |
@@ -51,6 +53,7 @@ func TestGenerateRoute(t *testing.T) { |
51 | 51 |
"labels": "foo=bar", |
52 | 52 |
"name": "test", |
53 | 53 |
"default-name": "someservice", |
54 |
+ "port": "80", |
|
54 | 55 |
"ports": "80,443", |
55 | 56 |
"hostname": "www.example.com", |
56 | 57 |
}, |
... | ... |
@@ -66,12 +69,6 @@ func TestGenerateRoute(t *testing.T) { |
66 | 66 |
To: api.ObjectReference{ |
67 | 67 |
Name: "someservice", |
68 | 68 |
}, |
69 |
- Port: &routeapi.RoutePort{ |
|
70 |
- TargetPort: util.IntOrString{ |
|
71 |
- Kind: util.IntstrString, |
|
72 |
- StrVal: "80", |
|
73 |
- }, |
|
74 |
- }, |
|
75 | 69 |
}, |
76 | 70 |
}, |
77 | 71 |
}, |
... | ... |
@@ -68,7 +68,8 @@ os::cmd::expect_success 'oc create -f test/integration/fixtures/test-service.jso |
68 | 68 |
os::cmd::expect_failure 'oc expose service frontend --create-external-load-balancer' |
69 | 69 |
os::cmd::expect_failure 'oc expose service frontend --port=40 --type=NodePort' |
70 | 70 |
os::cmd::expect_success 'oc expose service frontend' |
71 |
-os::cmd::expect_success_and_text 'oc get route frontend' 'name=frontend' |
|
71 |
+os::cmd::expect_success_and_text "oc get route frontend --output-version=v1 --template='{{.spec.to.name}}'" "frontend" # routes to correct service |
|
72 |
+os::cmd::expect_success_and_text "oc get route frontend --output-version=v1 --template='{{.spec.port.targetPort}}'" "<no value>" # no target port for services with unnamed ports |
|
72 | 73 |
os::cmd::expect_success 'oc delete svc,route -l name=frontend' |
73 | 74 |
# Test that external services are exposable |
74 | 75 |
os::cmd::expect_success 'oc create -f test/fixtures/external-service.yaml' |
... | ... |
@@ -79,7 +80,7 @@ os::cmd::expect_success 'oc delete svc external' |
79 | 79 |
# Expose multiport service and verify we set a port in the route |
80 | 80 |
os::cmd::expect_success 'oc create -f test/fixtures/multiport-service.yaml' |
81 | 81 |
os::cmd::expect_success 'oc expose svc/frontend --name route-with-set-port' |
82 |
-os::cmd::expect_success "os::util::get_object_assert 'route route-with-set-port' '{{.spec.port.targetPort}}' '8080'" |
|
82 |
+os::cmd::expect_success_and_text "oc get route route-with-set-port --template='{{.spec.port.targetPort}}' --output-version=v1" "web" |
|
83 | 83 |
echo "expose: ok" |
84 | 84 |
|
85 | 85 |
os::cmd::expect_success 'oc delete all --all' |