@@ -21,9 +21,7 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
"net"
24
- "regexp"
25
24
"strings"
26
- "time"
27
25
28
26
"github.com/caddyserver/caddy/caddyfile"
29
27
"github.com/coredns/corefile-migration/migration"
@@ -35,7 +33,6 @@ import (
35
33
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
36
34
kuberuntime "k8s.io/apimachinery/pkg/runtime"
37
35
"k8s.io/apimachinery/pkg/types"
38
- "k8s.io/apimachinery/pkg/util/wait"
39
36
clientset "k8s.io/client-go/kubernetes"
40
37
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
41
38
"k8s.io/klog/v2"
@@ -270,22 +267,15 @@ func createCoreDNSAddon(deploymentBytes, serviceBytes, configBytes []byte, clien
270
267
return errors .Wrap (err , "unable to fetch CoreDNS current installed version and ConfigMap." )
271
268
}
272
269
273
- canMigrateCorefile , err := isCoreDNSVersionSupported (client )
274
- if err != nil {
275
- return err
276
- }
277
-
278
270
corefileMigrationRequired , err := isCoreDNSConfigMapMigrationRequired (corefile , currentInstalledCoreDNSVersion )
279
271
if err != nil {
280
272
return err
281
273
}
282
274
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
287
277
288
- if corefileMigrationRequired && canMigrateCorefile {
278
+ if corefileMigrationRequired {
289
279
if err := migrateCoreDNSCorefile (client , coreDNSConfigMap , corefile , currentInstalledCoreDNSVersion ); err != nil {
290
280
// Errors in Corefile Migration is verified during preflight checks. This part will be executed when a user has chosen
291
281
// to ignore preflight check errors.
@@ -394,56 +384,6 @@ func isCoreDNSConfigMapMigrationRequired(corefile, currentInstalledCoreDNSVersio
394
384
return isMigrationRequired , nil
395
385
}
396
386
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
-
447
387
func migrateCoreDNSCorefile (client clientset.Interface , cm * v1.ConfigMap , corefile , currentInstalledCoreDNSVersion string ) error {
448
388
// Since the current configuration present is not the default version, try and migrate it.
449
389
updatedCorefile , err := migration .Migrate (currentInstalledCoreDNSVersion , kubeadmconstants .CoreDNSVersion , corefile , false )
0 commit comments