Skip to content

feat: adds nutanix SANs via patchHandler #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions api/v1alpha1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ const (
CCMProviderNutanix = "nutanix"
)

var DefaultDockerCertSANs = []string{
"localhost",
"127.0.0.1",
"0.0.0.0",
"host.docker.internal",
}
var (
DefaultDockerCertSANs = []string{
"localhost",
"127.0.0.1",
"0.0.0.0",
"host.docker.internal",
}

DefaultNutanixCertSANs = []string{
"localhost",
"127.0.0.1",
"0.0.0.0",
}
)

// +kubebuilder:object:root=true

Expand Down Expand Up @@ -272,8 +280,10 @@ func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: fmt.Sprintf(
"Extra Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically.",
//nolint:lll // its a user facing message
"Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically. For Nutanix %s are injected automatically.",
strings.Join(DefaultDockerCertSANs, ","),
strings.Join(DefaultNutanixCertSANs, ","),
),
Type: "array",
UniqueItems: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ spec:
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
certSANs:
- localhost
- 127.0.0.1
- 0.0.0.0
extraArgs:
cloud-provider: external
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ patches:
- op: "remove"
path: "/spec/variables"

- target:
kind: KubeadmControlPlaneTemplate
patch: |-
- op: "remove"
path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/apiServer/certSANs"

# FIXME: Debug why some of the patches are needed.
# When the handler runs, it sends back multiple patches for individual fields.
# But CAPI fails applying them because of missing value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (h *extraAPIServerCertSANsPatchHandler) Mutate(
"variableValue",
apiCertSANs,
)
if len(apiCertSANs) == 0 {
log.V(5).Info("No APIServerSANs to apply")
return nil
}

return patches.MutateIfApplicable(
obj, vars, &holderRef, selectors.ControlPlane(), log,
Expand All @@ -117,6 +121,8 @@ func getDefaultAPIServerSANs(cluster *clusterv1.Cluster) []string {
switch utils.GetProvider(cluster) {
case "docker":
return v1alpha1.DefaultDockerCertSANs
case "nutanix":
return v1alpha1.DefaultNutanixCertSANs
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,49 @@ var _ = Describe("Generate Extra API server certificate patches", func() {
},
},
},
{
patchTest: capitest.PatchTestDef{
Name: "extra API server cert SANs set with Nutanix",
Vars: []runtimehooksv1.Variable{
capitest.VariableWithValue(
clusterconfig.MetaVariableName,
v1alpha1.ClusterConfigSpec{
GenericClusterConfig: v1alpha1.GenericClusterConfig{
ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{
"a.b.c.example.com",
},
},
},
),
},
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
Operation: "add",
Path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration",
ValueMatcher: gomega.HaveKeyWithValue(
"apiServer",
gomega.HaveKeyWithValue(
"certSANs",
[]interface{}{
"0.0.0.0",
"127.0.0.1",
"a.b.c.example.com",
"localhost",
},
),
),
}},
},
cluster: clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: metav1.NamespaceDefault,
Labels: map[string]string{
clusterv1.ProviderNameLabel: "nutanix",
},
},
},
},
}

// create test node for each case
Expand Down