Skip to content

Commit 272b078

Browse files
committed
feat: insert nutanix cert sans
1 parent 1f04b72 commit 272b078

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

api/v1alpha1/clusterconfig_types.go

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

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

4248
// ClusterConfig is the Schema for the clusterconfigs API.
@@ -271,8 +277,10 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
271277
return clusterv1.VariableSchema{
272278
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
273279
Description: fmt.Sprintf(
274-
"Extra Subject Alternative Names for the API Server signing cert. For Docker %v are injected automatically.",
280+
//nolint:lll // its a user facing message
281+
"Subject Alternative Names for the API Server signing cert. For Docker %v are injected automatically. For Nutanix %v are injected automatically.",
275282
DefaultDockerCertSANs,
283+
DefaultNutanixCertSANs,
276284
),
277285
Type: "array",
278286
UniqueItems: true,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ func (h *extraAPIServerCertSANsPatchHandler) Mutate(
7474
if !found {
7575
log.V(5).Info("Extra API server cert SANs variable not defined")
7676
}
77-
apiCertSANs := extraAPIServerCertSANsVar
7877
if len(apiCertSANs) == 0 {
7978
log.Info("No APIServerSANs to apply")
8079
return nil
@@ -121,6 +120,8 @@ func getDefaultAPIServerSANs(cluster *clusterv1.Cluster) []string {
121120
switch utils.GetProvider(cluster) {
122121
case "docker":
123122
return v1alpha1.DefaultDockerCertSANs
123+
case "nutanix":
124+
return v1alpha1.DefaultNutanixCertSANs
124125
default:
125126
return nil
126127
}

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)