Skip to content

Commit 50b8d49

Browse files
authored
Merge pull request #2725 from gab-satchi/2723-unset-dns
🐛 Allows dns image tag to be unset
2 parents 8b29a9a + 697dee0 commit 50b8d49

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,13 @@ func (in *KubeadmControlPlane) validateCoreDNSVersion(prev *KubeadmControlPlane)
266266
if in.Spec.KubeadmConfigSpec.ClusterConfiguration == nil || prev.Spec.KubeadmConfigSpec.ClusterConfiguration == nil {
267267
return allErrs
268268
}
269-
if prev.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS.ImageTag == "" {
269+
//return if either current or target versions is empty
270+
if prev.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS.ImageTag == "" || in.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS.ImageTag == "" {
270271
return allErrs
271272
}
272-
dns := &in.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS
273+
targetDNS := &in.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS
273274
//return if the type is anything other than empty (default), or CoreDNS.
274-
if dns.Type != "" && dns.Type != kubeadmv1.CoreDNS {
275+
if targetDNS.Type != "" && targetDNS.Type != kubeadmv1.CoreDNS {
275276
return allErrs
276277
}
277278

@@ -286,13 +287,13 @@ func (in *KubeadmControlPlane) validateCoreDNSVersion(prev *KubeadmControlPlane)
286287
return allErrs
287288
}
288289

289-
toVersion, err := util.ParseMajorMinorPatch(dns.ImageTag)
290+
toVersion, err := util.ParseMajorMinorPatch(targetDNS.ImageTag)
290291
if err != nil {
291292
allErrs = append(allErrs,
292293
field.Invalid(
293294
field.NewPath("spec", "kubeadmConfigSpec", "clusterConfiguration", "dns", "imageTag"),
294-
dns.ImageTag,
295-
fmt.Sprintf("failed to parse CoreDNS target version: %v", dns.ImageTag),
295+
targetDNS.ImageTag,
296+
fmt.Sprintf("failed to parse CoreDNS target version: %v", targetDNS.ImageTag),
296297
),
297298
)
298299
return allErrs

controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
309309
},
310310
}
311311

312+
unsetCoreDNSToVersion := dns.DeepCopy()
313+
unsetCoreDNSToVersion.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS = kubeadmv1beta1.DNS{
314+
ImageMeta: kubeadmv1beta1.ImageMeta{
315+
ImageRepository: "",
316+
ImageTag: "",
317+
},
318+
}
319+
312320
certificatesDir := before.DeepCopy()
313321
certificatesDir.Spec.KubeadmConfigSpec.ClusterConfiguration.CertificatesDir = "a new certificates directory"
314322

@@ -505,6 +513,12 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
505513
before: dns,
506514
kcp: validCoreDNSCustomToVersion,
507515
},
516+
{
517+
name: "should succeed when CoreDNS ImageTag is unset",
518+
expectErr: false,
519+
before: dns,
520+
kcp: unsetCoreDNSToVersion,
521+
},
508522
{
509523
name: "should succeed when using an valid DNS build",
510524
expectErr: false,

0 commit comments

Comments
 (0)