Skip to content

Commit 4aac4b5

Browse files
authored
feat: adds nutanix SANs via patchHandler (#522)
<!-- Copyright 2023 D2iQ, Inc. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> **What problem does this PR solve?**: **Which issue(s) this PR fixes**: https://jira.nutanix.com/browse/D2IQ-100519 **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 489ef6b commit 4aac4b5

File tree

5 files changed

+72
-11
lines changed

5 files changed

+72
-11
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ const (
3131
CCMProviderNutanix = "nutanix"
3232
)
3333

34-
var DefaultDockerCertSANs = []string{
35-
"localhost",
36-
"127.0.0.1",
37-
"0.0.0.0",
38-
"host.docker.internal",
39-
}
34+
var (
35+
DefaultDockerCertSANs = []string{
36+
"localhost",
37+
"127.0.0.1",
38+
"0.0.0.0",
39+
"host.docker.internal",
40+
}
41+
42+
DefaultNutanixCertSANs = []string{
43+
"localhost",
44+
"127.0.0.1",
45+
"0.0.0.0",
46+
}
47+
)
4048

4149
// +kubebuilder:object:root=true
4250

@@ -272,8 +280,10 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
272280
return clusterv1.VariableSchema{
273281
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
274282
Description: fmt.Sprintf(
275-
"Extra Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically.",
283+
//nolint:lll // its a user facing message
284+
"Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically. For Nutanix %s are injected automatically.",
276285
strings.Join(DefaultDockerCertSANs, ","),
286+
strings.Join(DefaultNutanixCertSANs, ","),
277287
),
278288
Type: "array",
279289
UniqueItems: true,

charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ spec:
122122
kubeadmConfigSpec:
123123
clusterConfiguration:
124124
apiServer:
125-
certSANs:
126-
- localhost
127-
- 127.0.0.1
128-
- 0.0.0.0
129125
extraArgs:
130126
cloud-provider: external
131127
tls-cipher-suites: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256

hack/examples/bases/nutanix/clusterclass/kustomization.yaml.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ patches:
3030
- op: "remove"
3131
path: "/spec/variables"
3232

33+
- target:
34+
kind: KubeadmControlPlaneTemplate
35+
patch: |-
36+
- op: "remove"
37+
path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/apiServer/certSANs"
38+
3339
# FIXME: Debug why some of the patches are needed.
3440
# When the handler runs, it sends back multiple patches for individual fields.
3541
# But CAPI fails applying them because of missing value.

pkg/handlers/generic/mutation/extraapiservercertsans/inject.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (h *extraAPIServerCertSANsPatchHandler) Mutate(
9595
"variableValue",
9696
apiCertSANs,
9797
)
98+
if len(apiCertSANs) == 0 {
99+
log.V(5).Info("No APIServerSANs to apply")
100+
return nil
101+
}
98102

99103
return patches.MutateIfApplicable(
100104
obj, vars, &holderRef, selectors.ControlPlane(), log,
@@ -117,6 +121,8 @@ func getDefaultAPIServerSANs(cluster *clusterv1.Cluster) []string {
117121
switch utils.GetProvider(cluster) {
118122
case "docker":
119123
return v1alpha1.DefaultDockerCertSANs
124+
case "nutanix":
125+
return v1alpha1.DefaultNutanixCertSANs
120126
default:
121127
return nil
122128
}

pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,49 @@ var _ = Describe("Generate Extra API server certificate patches", func() {
130130
},
131131
},
132132
},
133+
{
134+
patchTest: capitest.PatchTestDef{
135+
Name: "extra API server cert SANs set with Nutanix",
136+
Vars: []runtimehooksv1.Variable{
137+
capitest.VariableWithValue(
138+
clusterconfig.MetaVariableName,
139+
v1alpha1.ClusterConfigSpec{
140+
GenericClusterConfig: v1alpha1.GenericClusterConfig{
141+
ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{
142+
"a.b.c.example.com",
143+
},
144+
},
145+
},
146+
),
147+
},
148+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
149+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
150+
Operation: "add",
151+
Path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration",
152+
ValueMatcher: gomega.HaveKeyWithValue(
153+
"apiServer",
154+
gomega.HaveKeyWithValue(
155+
"certSANs",
156+
[]interface{}{
157+
"0.0.0.0",
158+
"127.0.0.1",
159+
"a.b.c.example.com",
160+
"localhost",
161+
},
162+
),
163+
),
164+
}},
165+
},
166+
cluster: clusterv1.Cluster{
167+
ObjectMeta: metav1.ObjectMeta{
168+
Name: "test-cluster",
169+
Namespace: metav1.NamespaceDefault,
170+
Labels: map[string]string{
171+
clusterv1.ProviderNameLabel: "nutanix",
172+
},
173+
},
174+
},
175+
},
133176
}
134177

135178
// create test node for each case

0 commit comments

Comments
 (0)