@@ -100,14 +100,15 @@ func validate(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
100
100
if len (cmdutil .GetFlagString (cmd , "protocol" )) == 0 {
101
101
cmd .Flags ().Set ("protocol" , "TCP" )
102
102
}
103
- return validateFlags (cmd , "service/v1" )
103
+ return validateFlags (cmd , generator )
104
104
case "" :
105
105
// Default exposing services as a route
106
- cmd .Flags ().Set ("generator" , "route/v1" )
106
+ generator = "route/v1"
107
+ cmd .Flags ().Set ("generator" , generator )
107
108
fallthrough
108
109
case "route/v1" :
109
110
// We need to validate services exposed as routes
110
- if err := validateFlags (cmd , "route/v1" ); err != nil {
111
+ if err := validateFlags (cmd , generator ); err != nil {
111
112
return err
112
113
}
113
114
svc , err := kc .Services (info .Namespace ).Get (info .Name )
@@ -118,12 +119,14 @@ func validate(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
118
119
supportsTCP := false
119
120
for _ , port := range svc .Spec .Ports {
120
121
if port .Protocol == kapi .ProtocolTCP {
122
+ // Pass service target port as the route port
123
+ cmd .Flags ().Set ("port" , port .TargetPort .String ())
121
124
supportsTCP = true
122
125
break
123
126
}
124
127
}
125
128
if ! supportsTCP {
126
- return fmt .Errorf ("service %s doesn't support TCP" , info .Name )
129
+ return fmt .Errorf ("service %q doesn't support TCP" , info .Name )
127
130
}
128
131
}
129
132
@@ -133,14 +136,15 @@ func validate(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
133
136
return fmt .Errorf ("cannot expose a %s as a route" , mapping .Kind )
134
137
case "" :
135
138
// Default exposing everything except services as a service
136
- cmd .Flags ().Set ("generator" , "service/v1" )
139
+ generator = "service/v2"
140
+ cmd .Flags ().Set ("generator" , generator )
137
141
fallthrough
138
142
case "service/v1" , "service/v2" :
139
143
// Set default protocol back for generating services
140
144
if len (cmdutil .GetFlagString (cmd , "protocol" )) == 0 {
141
145
cmd .Flags ().Set ("protocol" , "TCP" )
142
146
}
143
- return validateFlags (cmd , "service/v1" )
147
+ return validateFlags (cmd , generator )
144
148
}
145
149
}
146
150
@@ -179,6 +183,12 @@ func validateFlags(cmd *cobra.Command, generator string) error {
179
183
if len (cmdutil .GetFlagString (cmd , "port" )) != 0 {
180
184
invalidFlags = append (invalidFlags , "--port" )
181
185
}
186
+ if len (cmdutil .GetFlagString (cmd , "load-balancer-ip" )) != 0 {
187
+ invalidFlags = append (invalidFlags , "--load-balancer-ip" )
188
+ }
189
+ if len (cmdutil .GetFlagString (cmd , "session-affinity" )) != 0 {
190
+ invalidFlags = append (invalidFlags , "--session-affinity" )
191
+ }
182
192
if cmdutil .GetFlagBool (cmd , "create-external-load-balancer" ) {
183
193
invalidFlags = append (invalidFlags , "--create-external-load-balancer" )
184
194
}
0 commit comments