mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
fix kubeadm update coredns with skip pending pod
This commit is contained in:
parent
0b92e8b16d
commit
fc0bda5a3c
@ -46,6 +46,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
|
||||||
"//vendor/github.com/caddyserver/caddy/caddyfile:go_default_library",
|
"//vendor/github.com/caddyserver/caddy/caddyfile:go_default_library",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/caddyfile"
|
"github.com/caddyserver/caddy/caddyfile"
|
||||||
"github.com/coredns/corefile-migration/migration"
|
"github.com/coredns/corefile-migration/migration"
|
||||||
@ -34,6 +35,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
kuberuntime "k8s.io/apimachinery/pkg/runtime"
|
kuberuntime "k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
@ -398,29 +400,48 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func isCoreDNSVersionSupported(client clientset.Interface) (bool, error) {
|
func isCoreDNSVersionSupported(client clientset.Interface) (bool, error) {
|
||||||
isValidVersion := true
|
var lastError error
|
||||||
coreDNSPodList, err := client.CoreV1().Pods(metav1.NamespaceSystem).List(
|
var pods []v1.Pod
|
||||||
context.TODO(),
|
|
||||||
metav1.ListOptions{
|
pollTimeout := 10 * time.Second
|
||||||
LabelSelector: "k8s-app=kube-dns",
|
err := wait.PollImmediate(kubeadmconstants.APICallRetryInterval, pollTimeout, func() (bool, error) {
|
||||||
},
|
coreDNSPodList, err := client.CoreV1().Pods(metav1.NamespaceSystem).List(
|
||||||
)
|
context.TODO(),
|
||||||
|
metav1.ListOptions{
|
||||||
|
LabelSelector: "k8s-app=kube-dns",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
lastError = err
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pod := range coreDNSPodList.Items {
|
||||||
|
if pod.Status.Phase != v1.PodRunning {
|
||||||
|
lastError = errors.New("found non-running CoreDNS pods")
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pods = coreDNSPodList.Items
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "unable to list CoreDNS pods")
|
return false, errors.Wrapf(lastError, "could not list the running CoreDNS pods after %v", pollTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pod := range coreDNSPodList.Items {
|
for _, pod := range pods {
|
||||||
imageID := imageDigestMatcher.FindStringSubmatch(pod.Status.ContainerStatuses[0].ImageID)
|
imageID := imageDigestMatcher.FindStringSubmatch(pod.Status.ContainerStatuses[0].ImageID)
|
||||||
if len(imageID) != 2 {
|
if len(imageID) != 2 {
|
||||||
return false, errors.Errorf("unable to match SHA256 digest ID in %q", pod.Status.ContainerStatuses[0].ImageID)
|
return false, errors.Errorf("pod %s unable to match SHA256 digest ID in %q", pod.GetName(), pod.Status.ContainerStatuses[0].ImageID)
|
||||||
}
|
}
|
||||||
// The actual digest should be at imageID[1]
|
// The actual digest should be at imageID[1]
|
||||||
if !migration.Released(imageID[1]) {
|
if !migration.Released(imageID[1]) {
|
||||||
isValidVersion = false
|
return false, errors.Errorf("unknown digest %q for pod %s", imageID[1], pod.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return isValidVersion, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefile, currentInstalledCoreDNSVersion string) error {
|
func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefile, currentInstalledCoreDNSVersion string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user