@@ -23,6 +23,7 @@ import (
23
23
"net"
24
24
"regexp"
25
25
"strings"
26
+ "time"
26
27
27
28
"github.com/caddyserver/caddy/caddyfile"
28
29
"github.com/coredns/corefile-migration/migration"
@@ -34,6 +35,7 @@ import (
34
35
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35
36
kuberuntime "k8s.io/apimachinery/pkg/runtime"
36
37
"k8s.io/apimachinery/pkg/types"
38
+ "k8s.io/apimachinery/pkg/util/wait"
37
39
clientset "k8s.io/client-go/kubernetes"
38
40
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
39
41
"k8s.io/klog/v2"
@@ -398,29 +400,48 @@ var (
398
400
)
399
401
400
402
func isCoreDNSVersionSupported (client clientset.Interface ) (bool , error ) {
401
- isValidVersion := true
402
- coreDNSPodList , err := client .CoreV1 ().Pods (metav1 .NamespaceSystem ).List (
403
- context .TODO (),
404
- metav1.ListOptions {
405
- LabelSelector : "k8s-app=kube-dns" ,
406
- },
407
- )
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
+
408
429
if err != nil {
409
- return false , errors .Wrap ( err , "unable to list CoreDNS pods" )
430
+ return false , errors .Wrapf ( lastError , "could not list the running CoreDNS pods after %v" , pollTimeout )
410
431
}
411
432
412
- for _ , pod := range coreDNSPodList . Items {
433
+ for _ , pod := range pods {
413
434
imageID := imageDigestMatcher .FindStringSubmatch (pod .Status .ContainerStatuses [0 ].ImageID )
414
435
if len (imageID ) != 2 {
415
- return false , errors .Errorf ("unable to match SHA256 digest ID in %q" , pod .Status .ContainerStatuses [0 ].ImageID )
436
+ return false , errors .Errorf ("pod %s unable to match SHA256 digest ID in %q" , pod . GetName () , pod .Status .ContainerStatuses [0 ].ImageID )
416
437
}
417
438
// The actual digest should be at imageID[1]
418
439
if ! migration .Released (imageID [1 ]) {
419
- isValidVersion = false
440
+ return false , errors . Errorf ( "unknown digest %q for pod %s" , imageID [ 1 ], pod . GetName ())
420
441
}
421
442
}
422
443
423
- return isValidVersion , nil
444
+ return true , nil
424
445
}
425
446
426
447
func migrateCoreDNSCorefile (client clientset.Interface , cm * v1.ConfigMap , corefile , currentInstalledCoreDNSVersion string ) error {
0 commit comments