Skip to content

Commit c19e050

Browse files
authored
Merge pull request kubernetes#94299 from zouyee/pending
fix kubeadm update coredns with skip pending pod
2 parents 92ba3eb + fc0bda5 commit c19e050

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ 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",
4950
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
5051
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
5152
"//vendor/github.com/caddyserver/caddy/caddyfile:go_default_library",

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net"
2424
"regexp"
2525
"strings"
26+
"time"
2627

2728
"github.com/caddyserver/caddy/caddyfile"
2829
"github.com/coredns/corefile-migration/migration"
@@ -34,6 +35,7 @@ import (
3435
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3536
kuberuntime "k8s.io/apimachinery/pkg/runtime"
3637
"k8s.io/apimachinery/pkg/types"
38+
"k8s.io/apimachinery/pkg/util/wait"
3739
clientset "k8s.io/client-go/kubernetes"
3840
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
3941
"k8s.io/klog/v2"
@@ -398,29 +400,48 @@ var (
398400
)
399401

400402
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+
408429
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)
410431
}
411432

412-
for _, pod := range coreDNSPodList.Items {
433+
for _, pod := range pods {
413434
imageID := imageDigestMatcher.FindStringSubmatch(pod.Status.ContainerStatuses[0].ImageID)
414435
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)
416437
}
417438
// The actual digest should be at imageID[1]
418439
if !migration.Released(imageID[1]) {
419-
isValidVersion = false
440+
return false, errors.Errorf("unknown digest %q for pod %s", imageID[1], pod.GetName())
420441
}
421442
}
422443

423-
return isValidVersion, nil
444+
return true, nil
424445
}
425446

426447
func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefile, currentInstalledCoreDNSVersion string) error {

0 commit comments

Comments
 (0)