Skip to content

Commit 6541992

Browse files
committed
fixup! refactor: set CoreDNS based on struct not nil
1 parent 70d1b43 commit 6541992

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

docs/content/customization/generic/dns.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,32 @@ Applying this configuration will result in the following value being set:
4848
imageRepository: "my-registry.io/my-org/my-repo"
4949
imageTag: "v1.11.3_custom.0"
5050
```
51+
52+
The CoreDNS version can also be updated automatically. To do this, set `coreDNS` to an empty object:
53+
54+
```yaml
55+
apiVersion: cluster.x-k8s.io/v1beta1
56+
kind: Cluster
57+
metadata:
58+
name: <NAME>
59+
spec:
60+
topology:
61+
variables:
62+
- name: clusterConfig
63+
value:
64+
dns:
65+
coreDNS: {}
66+
```
67+
68+
Applying this configuration will result in the following value being set,
69+
with the version of the CoreDNS image being set based on the cluster's Kubernetes version:
70+
71+
- `KubeadmControlPlaneTemplate`:
72+
73+
- ```yaml
74+
spec:
75+
kubeadmConfigSpec:
76+
clusterConfiguration:
77+
dns:
78+
imageTag: "v1.11.3"
79+
```

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ func (h *coreDNSPatchHandler) Mutate(
7171
h.variableFieldPath...,
7272
)
7373
if err != nil {
74-
if !variables.IsNotFoundError(err) {
75-
return err
74+
if variables.IsNotFoundError(err) {
75+
log.V(5).Info("coreDNS variable not defined")
76+
return nil
7677
}
77-
log.V(5).Info("coreDNS variable not defined")
78+
return err
7879
}
7980

8081
log = log.WithValues(

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,34 @@ var _ = Describe("Generate CoreDNS patches", func() {
4646
testDefs := []testObj{
4747
{
4848
patchTest: capitest.PatchTestDef{
49-
Name: "unset variable",
49+
Name: "unset variable",
50+
},
51+
cluster: clusterv1.Cluster{
52+
ObjectMeta: metav1.ObjectMeta{
53+
Name: "test-cluster",
54+
Namespace: request.Namespace,
55+
Labels: map[string]string{
56+
clusterv1.ProviderNameLabel: "nutanix",
57+
},
58+
},
59+
Spec: clusterv1.ClusterSpec{
60+
Topology: &clusterv1.Topology{
61+
Version: "1.30.100",
62+
},
63+
},
64+
},
65+
},
66+
{
67+
patchTest: capitest.PatchTestDef{
68+
Name: "variable with defaults",
69+
Vars: []runtimehooksv1.Variable{
70+
capitest.VariableWithValue(
71+
v1alpha1.ClusterConfigVariableName,
72+
v1alpha1.CoreDNS{},
73+
v1alpha1.DNSVariableName,
74+
VariableName,
75+
),
76+
},
5077
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
5178
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
5279
Operation: "add",
@@ -205,8 +232,16 @@ var _ = Describe("Generate CoreDNS patches", func() {
205232
},
206233
{
207234
patchTest: capitest.PatchTestDef{
208-
Name: "error if cannot find default CoreDNS version",
209-
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
235+
Name: "error if cannot find default CoreDNS version",
236+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
237+
Vars: []runtimehooksv1.Variable{
238+
capitest.VariableWithValue(
239+
v1alpha1.ClusterConfigVariableName,
240+
v1alpha1.CoreDNS{},
241+
v1alpha1.DNSVariableName,
242+
VariableName,
243+
),
244+
},
210245
ExpectedFailure: true,
211246
},
212247
cluster: clusterv1.Cluster{

0 commit comments

Comments
 (0)