Skip to content

Commit dae3dae

Browse files
committed
fix: also ignore VirtualIP in Nutanix CCM
1 parent 47f91f4 commit dae3dae

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

charts/cluster-api-runtime-extensions-nutanix/addons/ccm/nutanix/values-template.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ prismCentralInsecure: {{ .PrismCentralInsecure }}
44
{{- with .PrismCentralAdditionalTrustBundle }}
55
prismCentralAdditionalTrustBundle: "{{ . }}"
66
{{- end }}
7-
{{- with .ControlPlaneEndpointHost }}
8-
ignoredNodeIPs: [ {{ printf "%q" . }} ]
9-
{{- end }}
7+
{{- with .IPsToIgnore }}
8+
ignoredNodeIPs: [ {{ joinQuoted . }} ]
9+
{{- end }}
1010

1111
# The Secret containing the credentials will be created by the handler.
1212
createSecret: false

pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"errors"
1010
"fmt"
11+
"strings"
1112
"text/template"
1213

1314
"github.com/go-logr/logr"
@@ -140,7 +141,15 @@ func templateValuesFunc(
140141
nutanixConfig *v1alpha1.NutanixSpec,
141142
) func(*clusterv1.Cluster, string) (string, error) {
142143
return func(_ *clusterv1.Cluster, valuesTemplate string) (string, error) {
143-
helmValuesTemplate, err := template.New("").Parse(valuesTemplate)
144+
joinQuoted := template.FuncMap{
145+
"joinQuoted": func(items []string) string {
146+
for i, item := range items {
147+
items[i] = fmt.Sprintf("%q", item)
148+
}
149+
return strings.Join(items, ", ")
150+
},
151+
}
152+
helmValuesTemplate, err := template.New("").Funcs(joinQuoted).Parse(valuesTemplate)
144153
if err != nil {
145154
return "", fmt.Errorf("failed to parse Helm values template: %w", err)
146155
}
@@ -150,7 +159,7 @@ func templateValuesFunc(
150159
PrismCentralPort uint16
151160
PrismCentralInsecure bool
152161
PrismCentralAdditionalTrustBundle string
153-
ControlPlaneEndpointHost string
162+
IPsToIgnore []string
154163
}
155164

156165
address, port, err := nutanixConfig.PrismCentralEndpoint.ParseURL()
@@ -162,7 +171,7 @@ func templateValuesFunc(
162171
PrismCentralPort: port,
163172
PrismCentralInsecure: nutanixConfig.PrismCentralEndpoint.Insecure,
164173
PrismCentralAdditionalTrustBundle: nutanixConfig.PrismCentralEndpoint.AdditionalTrustBundle,
165-
ControlPlaneEndpointHost: nutanixConfig.ControlPlaneEndpoint.Host,
174+
IPsToIgnore: ipsToIgnore(nutanixConfig),
166175
}
167176

168177
var b bytes.Buffer
@@ -174,3 +183,14 @@ func templateValuesFunc(
174183
return b.String(), nil
175184
}
176185
}
186+
187+
func ipsToIgnore(nutanixConfig *v1alpha1.NutanixSpec) []string {
188+
toIgnore := []string{nutanixConfig.ControlPlaneEndpoint.Host}
189+
// Also ignore the virtual IP if it is set.
190+
if nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec != nil &&
191+
nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration != nil &&
192+
nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration.Address != "" {
193+
toIgnore = append(toIgnore, nutanixConfig.ControlPlaneEndpoint.VirtualIPSpec.Configuration.Address)
194+
}
195+
return toIgnore
196+
}

pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ prismCentralPort: 9440
3939
prismCentralInsecure: true
4040
ignoredNodeIPs: [ "1.2.3.4" ]
4141
42+
# The Secret containing the credentials will be created by the handler.
43+
createSecret: false
44+
secretName: nutanix-ccm-credentials
45+
`
46+
47+
expectedWithVirtualIPSet = `prismCentralEndPoint: prism-central.nutanix.com
48+
prismCentralPort: 9440
49+
prismCentralInsecure: true
50+
ignoredNodeIPs: [ "1.2.3.4", "5.6.7.8" ]
51+
4252
# The Secret containing the credentials will be created by the handler.
4353
createSecret: false
4454
secretName: nutanix-ccm-credentials
@@ -127,6 +137,41 @@ func Test_templateValues(t *testing.T) {
127137
in: valuesTemplate,
128138
expected: expectedWithoutAdditionalTrustBundle,
129139
},
140+
{
141+
name: "With VirtualIP Set",
142+
clusterConfig: &apivariables.ClusterConfigSpec{
143+
Addons: &apivariables.Addons{
144+
GenericAddons: v1alpha1.GenericAddons{
145+
CCM: &v1alpha1.CCM{
146+
Credentials: &v1alpha1.CCMCredentials{
147+
SecretRef: v1alpha1.LocalObjectReference{
148+
Name: "creds",
149+
},
150+
},
151+
},
152+
},
153+
},
154+
Nutanix: &v1alpha1.NutanixSpec{
155+
PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{
156+
URL: fmt.Sprintf(
157+
"https://prism-central.nutanix.com:%d",
158+
v1alpha1.DefaultPrismCentralPort,
159+
),
160+
Insecure: true,
161+
},
162+
ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{
163+
Host: "1.2.3.4",
164+
VirtualIPSpec: &v1alpha1.ControlPlaneVirtualIPSpec{
165+
Configuration: &v1alpha1.ControlPlaneVirtualIPConfiguration{
166+
Address: "5.6.7.8",
167+
},
168+
},
169+
},
170+
},
171+
},
172+
in: valuesTemplate,
173+
expected: expectedWithVirtualIPSet,
174+
},
130175
}
131176
for idx := range tests {
132177
tt := tests[idx]

0 commit comments

Comments
 (0)