Skip to content

Commit 3cdfdfc

Browse files
authored
Merge pull request kubernetes#94506 from neolit123/1.20-coredns-remove-supported-version-check
kubeadm: remove the CoreDNS check for supported image digests
2 parents 0edbf25 + 4bb75a4 commit 3cdfdfc

File tree

2 files changed

+3
-64
lines changed

2 files changed

+3
-64
lines changed

cmd/kubeadm/app/phases/addons/dns/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ go_library(
4646
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
4747
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
4848
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
49-
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
5049
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
5150
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
5251
"//vendor/github.com/caddyserver/caddy/caddyfile:go_default_library",

cmd/kubeadm/app/phases/addons/dns/dns.go

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"net"
24-
"regexp"
2524
"strings"
26-
"time"
2725

2826
"github.com/caddyserver/caddy/caddyfile"
2927
"github.com/coredns/corefile-migration/migration"
@@ -35,7 +33,6 @@ import (
3533
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3634
kuberuntime "k8s.io/apimachinery/pkg/runtime"
3735
"k8s.io/apimachinery/pkg/types"
38-
"k8s.io/apimachinery/pkg/util/wait"
3936
clientset "k8s.io/client-go/kubernetes"
4037
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
4138
"k8s.io/klog/v2"
@@ -270,22 +267,15 @@ func createCoreDNSAddon(deploymentBytes, serviceBytes, configBytes []byte, clien
270267
return errors.Wrap(err, "unable to fetch CoreDNS current installed version and ConfigMap.")
271268
}
272269

273-
canMigrateCorefile, err := isCoreDNSVersionSupported(client)
274-
if err != nil {
275-
return err
276-
}
277-
278270
corefileMigrationRequired, err := isCoreDNSConfigMapMigrationRequired(corefile, currentInstalledCoreDNSVersion)
279271
if err != nil {
280272
return err
281273
}
282274

283-
if !canMigrateCorefile {
284-
klog.Warningf("the CoreDNS Configuration will not be migrated due to unsupported version of CoreDNS. " +
285-
"The existing CoreDNS Corefile configuration and deployment has been retained.")
286-
}
275+
// Assume that migration is always possible, rely on migrateCoreDNSCorefile() to fail if not.
276+
canMigrateCorefile := true
287277

288-
if corefileMigrationRequired && canMigrateCorefile {
278+
if corefileMigrationRequired {
289279
if err := migrateCoreDNSCorefile(client, coreDNSConfigMap, corefile, currentInstalledCoreDNSVersion); err != nil {
290280
// Errors in Corefile Migration is verified during preflight checks. This part will be executed when a user has chosen
291281
// to ignore preflight check errors.
@@ -394,56 +384,6 @@ func isCoreDNSConfigMapMigrationRequired(corefile, currentInstalledCoreDNSVersio
394384
return isMigrationRequired, nil
395385
}
396386

397-
var (
398-
// imageDigestMatcher is used to match the SHA256 digest from the ImageID of the CoreDNS pods
399-
imageDigestMatcher = regexp.MustCompile(`^.*(?i:sha256:([[:alnum:]]{64}))$`)
400-
)
401-
402-
func isCoreDNSVersionSupported(client clientset.Interface) (bool, error) {
403-
var lastError error
404-
var pods []v1.Pod
405-
406-
pollTimeout := 10 * time.Second
407-
err := wait.PollImmediate(kubeadmconstants.APICallRetryInterval, pollTimeout, func() (bool, error) {
408-
coreDNSPodList, err := client.CoreV1().Pods(metav1.NamespaceSystem).List(
409-
context.TODO(),
410-
metav1.ListOptions{
411-
LabelSelector: "k8s-app=kube-dns",
412-
},
413-
)
414-
if err != nil {
415-
lastError = err
416-
return false, nil
417-
}
418-
419-
for _, pod := range coreDNSPodList.Items {
420-
if pod.Status.Phase != v1.PodRunning {
421-
lastError = errors.New("found non-running CoreDNS pods")
422-
return false, nil
423-
}
424-
}
425-
pods = coreDNSPodList.Items
426-
return true, nil
427-
})
428-
429-
if err != nil {
430-
return false, errors.Wrapf(lastError, "could not list the running CoreDNS pods after %v", pollTimeout)
431-
}
432-
433-
for _, pod := range pods {
434-
imageID := imageDigestMatcher.FindStringSubmatch(pod.Status.ContainerStatuses[0].ImageID)
435-
if len(imageID) != 2 {
436-
return false, errors.Errorf("pod %s unable to match SHA256 digest ID in %q", pod.GetName(), pod.Status.ContainerStatuses[0].ImageID)
437-
}
438-
// The actual digest should be at imageID[1]
439-
if !migration.Released(imageID[1]) {
440-
return false, errors.Errorf("unknown digest %q for pod %s", imageID[1], pod.GetName())
441-
}
442-
}
443-
444-
return true, nil
445-
}
446-
447387
func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefile, currentInstalledCoreDNSVersion string) error {
448388
// Since the current configuration present is not the default version, try and migrate it.
449389
updatedCorefile, err := migration.Migrate(currentInstalledCoreDNSVersion, kubeadmconstants.CoreDNSVersion, corefile, false)

0 commit comments

Comments
 (0)