Skip to content

Commit 6053278

Browse files
committed
fix: error on missing CoreDNS version
1 parent 9a38896 commit 6053278

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package coredns
55

66
import (
77
"context"
8+
"errors"
89

910
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1011
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -27,6 +28,8 @@ const (
2728
VariableName = "coreDNS"
2829
)
2930

31+
var ErrDefaultCoreDNSVersionNotFound = errors.New("could not determine default CoreDNS version based on the Kubernetes version")
32+
3033
type coreDNSPatchHandler struct {
3134
variableName string
3235
variableFieldPath []string
@@ -113,7 +116,7 @@ func (h *coreDNSPatchHandler) Mutate(
113116
cluster.Spec.Topology.Version,
114117
)
115118
if !found {
116-
log.Info("Default CoreDNS version not found for Kubernetes version")
119+
return ErrDefaultCoreDNSVersionNotFound
117120
}
118121
dns.ImageTag = defaultCoreDNSVersion
119122
}

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,71 @@ var _ = Describe("Generate CoreDNS patches", func() {
203203
},
204204
},
205205
},
206+
{
207+
patchTest: capitest.PatchTestDef{
208+
Name: "error if cannot find default CoreDNS version",
209+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
210+
ExpectedFailure: true,
211+
},
212+
cluster: clusterv1.Cluster{
213+
ObjectMeta: metav1.ObjectMeta{
214+
Name: "test-cluster",
215+
Namespace: request.Namespace,
216+
Labels: map[string]string{
217+
clusterv1.ProviderNameLabel: "nutanix",
218+
},
219+
},
220+
Spec: clusterv1.ClusterSpec{
221+
Topology: &clusterv1.Topology{
222+
Version: "1.100.100",
223+
},
224+
},
225+
},
226+
},
227+
{
228+
patchTest: capitest.PatchTestDef{
229+
Name: "no error if cannot find default CoreDNS version but variable is set",
230+
Vars: []runtimehooksv1.Variable{
231+
capitest.VariableWithValue(
232+
v1alpha1.ClusterConfigVariableName,
233+
v1alpha1.CoreDNS{
234+
Image: &v1alpha1.Image{
235+
Repository: "my-registry.io/my-org/my-repo",
236+
Tag: "v1.11.3_custom.0",
237+
},
238+
},
239+
v1alpha1.DNSVariableName,
240+
VariableName,
241+
),
242+
},
243+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
244+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{
245+
Operation: "add",
246+
Path: "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration",
247+
ValueMatcher: gomega.HaveKeyWithValue(
248+
"dns",
249+
map[string]interface{}{
250+
"imageRepository": "my-registry.io/my-org/my-repo",
251+
"imageTag": "v1.11.3_custom.0",
252+
},
253+
),
254+
}},
255+
},
256+
cluster: clusterv1.Cluster{
257+
ObjectMeta: metav1.ObjectMeta{
258+
Name: "test-cluster",
259+
Namespace: request.Namespace,
260+
Labels: map[string]string{
261+
clusterv1.ProviderNameLabel: "nutanix",
262+
},
263+
},
264+
Spec: clusterv1.ClusterSpec{
265+
Topology: &clusterv1.Topology{
266+
Version: "1.100.100",
267+
},
268+
},
269+
},
270+
},
206271
}
207272

208273
// create test node for each case

0 commit comments

Comments
 (0)