diff --git a/charts/cluster-api-runtime-extensions-nutanix/addons/ccm/nutanix/values-template.yaml b/charts/cluster-api-runtime-extensions-nutanix/addons/ccm/nutanix/values-template.yaml index 707a1b4af..fe34d44b1 100644 --- a/charts/cluster-api-runtime-extensions-nutanix/addons/ccm/nutanix/values-template.yaml +++ b/charts/cluster-api-runtime-extensions-nutanix/addons/ccm/nutanix/values-template.yaml @@ -4,9 +4,9 @@ prismCentralInsecure: {{ .PrismCentralInsecure }} {{- with .PrismCentralAdditionalTrustBundle }} prismCentralAdditionalTrustBundle: "{{ . }}" {{- end }} -{{- with .ControlPlaneEndpointHost }} -ignoredNodeIPs: [ {{ printf "%q" . }} ] - {{- end }} +{{- with .IPsToIgnore }} +ignoredNodeIPs: [ {{ joinQuoted . }} ] +{{- end }} # The Secret containing the credentials will be created by the handler. createSecret: false diff --git a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go index a6e1ebbf3..4c9b12fc9 100644 --- a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go +++ b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go @@ -8,6 +8,7 @@ import ( "context" "errors" "fmt" + "strings" "text/template" "github.com/go-logr/logr" @@ -140,7 +141,15 @@ func templateValuesFunc( nutanixConfig *v1alpha1.NutanixSpec, ) func(*clusterv1.Cluster, string) (string, error) { return func(_ *clusterv1.Cluster, valuesTemplate string) (string, error) { - helmValuesTemplate, err := template.New("").Parse(valuesTemplate) + joinQuoted := template.FuncMap{ + "joinQuoted": func(items []string) string { + for i, item := range items { + items[i] = fmt.Sprintf("%q", item) + } + return strings.Join(items, ", ") + }, + } + helmValuesTemplate, err := template.New("").Funcs(joinQuoted).Parse(valuesTemplate) if err != nil { return "", fmt.Errorf("failed to parse Helm values template: %w", err) } @@ -150,7 +159,7 @@ func templateValuesFunc( PrismCentralPort uint16 PrismCentralInsecure bool PrismCentralAdditionalTrustBundle string - ControlPlaneEndpointHost string + IPsToIgnore []string } address, port, err := nutanixConfig.PrismCentralEndpoint.ParseURL() @@ -162,7 +171,7 @@ func templateValuesFunc( PrismCentralPort: port, PrismCentralInsecure: nutanixConfig.PrismCentralEndpoint.Insecure, PrismCentralAdditionalTrustBundle: nutanixConfig.PrismCentralEndpoint.AdditionalTrustBundle, - ControlPlaneEndpointHost: nutanixConfig.ControlPlaneEndpoint.Host, + IPsToIgnore: ipsToIgnore(nutanixConfig), } var b bytes.Buffer @@ -174,3 +183,17 @@ func templateValuesFunc( return b.String(), nil } } + +func ipsToIgnore(nutanixConfig *v1alpha1.NutanixSpec) []string { + toIgnore := []string{nutanixConfig.ControlPlaneEndpoint.Host} + // Also ignore the virtual IP if it is set. + if nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec != nil && + nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration != nil && + nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration.Address != "" { + toIgnore = append( + toIgnore, + nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration.Address, + ) + } + return toIgnore +} diff --git a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go index 3059f7c43..2daccbb1c 100644 --- a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go +++ b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go @@ -39,6 +39,16 @@ prismCentralPort: 9440 prismCentralInsecure: true ignoredNodeIPs: [ "1.2.3.4" ] +# The Secret containing the credentials will be created by the handler. +createSecret: false +secretName: nutanix-ccm-credentials +` + + expectedWithVirtualIPSet = `prismCentralEndPoint: prism-central.nutanix.com +prismCentralPort: 9440 +prismCentralInsecure: true +ignoredNodeIPs: [ "1.2.3.4", "5.6.7.8" ] + # The Secret containing the credentials will be created by the handler. createSecret: false secretName: nutanix-ccm-credentials @@ -127,6 +137,41 @@ func Test_templateValues(t *testing.T) { in: valuesTemplate, expected: expectedWithoutAdditionalTrustBundle, }, + { + name: "With VirtualIP Set", + clusterConfig: &apivariables.ClusterConfigSpec{ + Addons: &apivariables.Addons{ + GenericAddons: v1alpha1.GenericAddons{ + CCM: &v1alpha1.CCM{ + Credentials: &v1alpha1.CCMCredentials{ + SecretRef: v1alpha1.LocalObjectReference{ + Name: "creds", + }, + }, + }, + }, + }, + Nutanix: &v1alpha1.NutanixSpec{ + PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ + URL: fmt.Sprintf( + "https://prism-central.nutanix.com:%d", + v1alpha1.DefaultPrismCentralPort, + ), + Insecure: true, + }, + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ + Host: "1.2.3.4", + VirtualIPSpec: &v1alpha1.ControlPlaneVirtualIPSpec{ + Configuration: &v1alpha1.ControlPlaneVirtualIPConfiguration{ + Address: "5.6.7.8", + }, + }, + }, + }, + }, + in: valuesTemplate, + expected: expectedWithVirtualIPSet, + }, } for idx := range tests { tt := tests[idx]