@@ -301,8 +301,11 @@ func (c *Cluster) checkTemplateServerServiceNodePort(template *unstructured.Unst
301301
302302 _ , err = maps .GetNestedField (port , "nodePort" )
303303 if err != nil {
304- return fmt .Errorf ("unable to get spec.template.spec.service.spec.ports[0].nodePort int the server template, " +
305- "since you specified the flag \" --server-service-nodeport\" you need to add the \" nodePort\" field in the template" )
304+ // If the field is missing, it might be optional (represented by leading ?). If not, raise an error
305+ if _ , errOptional := maps .GetNestedField (port , "?nodePort" ); errOptional != nil {
306+ return fmt .Errorf ("unable to get spec.template.spec.service.spec.ports[0].nodePort int the server template, " +
307+ "since you specified the flag \" --server-service-nodeport\" you need to add the \" nodePort\" field in the template" )
308+ }
306309 }
307310
308311 return nil
@@ -312,11 +315,14 @@ func (c *Cluster) checkTemplateServerServiceLoadBalancer(template *unstructured.
312315 return nil
313316 }
314317
315- path := "spec.template.spec.service.spec.loadBalancerIP "
316- _ , err := maps .GetNestedField (template .Object , path )
318+ servicePath := "spec.template.spec.service.spec"
319+ _ , err := maps .GetNestedField (template .Object , fmt . Sprintf ( "%s.loadBalancerIP" , servicePath ) )
317320 if err != nil {
318- return fmt .Errorf ("unable to get %s of the server template, " +
319- "since you specified the flag \" --server-service-loadbalancerip\" you need to add the \" loadBalancerIP\" field in the template" , path )
321+ // If the field is missing, it might be optional (represented by leading ?). If not, raise an error
322+ if _ , errOptional := maps .GetNestedField (template .Object , fmt .Sprintf ("%s.?loadBalancerIP" , servicePath )); errOptional != nil {
323+ return fmt .Errorf ("unable to get %s of the server template, " +
324+ "since you specified the flag \" --server-service-loadbalancerip\" you need to add the \" loadBalancerIP\" field in the template" , servicePath )
325+ }
320326 }
321327 return nil
322328}
0 commit comments