Skip to content

Commit a5f8712

Browse files
claudiolorfra98
authored andcommitted
fix: liqoctl template checks allow optional fields
1 parent 37236f6 commit a5f8712

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/liqoctl/network/cluster.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)