Skip to content

Commit 9d7d0a7

Browse files
committed
feat: insert nutanix cert sans
1 parent 15e4a09 commit 9d7d0a7

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ var DefaultDockerCertSANs = []string{
3838
"host.docker.internal",
3939
}
4040

41+
var DefaultNutanixCertSANs = []string{
42+
"localhost",
43+
"127.0.0.1",
44+
"0.0.0.0",
45+
}
46+
4147
// +kubebuilder:object:root=true
4248

4349
// ClusterConfig is the Schema for the clusterconfigs API.
@@ -272,8 +278,10 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
272278
return clusterv1.VariableSchema{
273279
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
274280
Description: fmt.Sprintf(
275-
"Extra Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically.",
281+
//nolint:lll // its a user facing message
282+
"Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically. For Nutanix %s are injected automatically.",
276283
strings.Join(DefaultDockerCertSANs, ","),
284+
strings.Join(DefaultNutanixCertSANs, ","),
277285
),
278286
Type: "array",
279287
UniqueItems: true,

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.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)