From d4de1a571ab9a1fab429902702c1619ea8e6f921 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 27 Mar 2020 21:15:55 +0200 Subject: [PATCH] kubeadm: skip kube-proxy and DNS upgrades on missing ConfigMaps If the kube-proxy/dns ConfigMap are missing, show warnings and assume that these addons were skipped during "kubeadm init", and that their redeployment on upgrade is not desired. TODO: remove this once "kubeadm upgrade apply" phases are supported: https://github.com/kubernetes/kubeadm/issues/1318 --- cmd/kubeadm/app/phases/upgrade/postupgrade.go | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/cmd/kubeadm/app/phases/upgrade/postupgrade.go b/cmd/kubeadm/app/phases/upgrade/postupgrade.go index 59aa76ccd54..3e6c068a4b5 100644 --- a/cmd/kubeadm/app/phases/upgrade/postupgrade.go +++ b/cmd/kubeadm/app/phases/upgrade/postupgrade.go @@ -28,6 +28,7 @@ import ( errorsutil "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/version" clientset "k8s.io/client-go/kubernetes" + "k8s.io/klog" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" "k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns" @@ -100,18 +101,68 @@ func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitCon errs = append(errs, err) } - // Upgrade kube-dns/CoreDNS and kube-proxy - if err := dns.EnsureDNSAddon(&cfg.ClusterConfiguration, client); err != nil { - errs = append(errs, err) + // If the coredns / kube-dns ConfigMaps are missing, show a warning and assume that the + // DNS addon was skipped during "kubeadm init", and that its redeployment on upgrade is not desired. + // + // TODO: remove this once "kubeadm upgrade apply" phases are supported: + // https://github.com/kubernetes/kubeadm/issues/1318 + var missingCoreDNSConfigMap, missingKubeDNSConfigMap bool + if _, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get( + context.TODO(), + kubeadmconstants.CoreDNSConfigMap, + metav1.GetOptions{}, + ); err != nil && apierrors.IsNotFound(err) { + missingCoreDNSConfigMap = true } - // Remove the old DNS deployment if a new DNS service is now used (kube-dns to CoreDNS or vice versa) - if err := removeOldDNSDeploymentIfAnotherDNSIsUsed(&cfg.ClusterConfiguration, client, dryRun); err != nil { - errs = append(errs, err) + if _, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get( + context.TODO(), + kubeadmconstants.KubeDNSConfigMap, + metav1.GetOptions{}, + ); err != nil && apierrors.IsNotFound(err) { + missingKubeDNSConfigMap = true + } + if missingCoreDNSConfigMap && missingKubeDNSConfigMap { + klog.Warningf("the ConfigMaps %q/%q in the namespace %q were not found. "+ + "Assuming that a DNS server was not deployed for this cluster. "+ + "Note that once 'kubeadm upgrade apply' supports phases you "+ + "will have to skip the DNS upgrade manually", + kubeadmconstants.CoreDNSConfigMap, + kubeadmconstants.KubeDNSConfigMap, + metav1.NamespaceSystem) + } else { + // Upgrade CoreDNS/kube-dns + if err := dns.EnsureDNSAddon(&cfg.ClusterConfiguration, client); err != nil { + errs = append(errs, err) + } + // Remove the old DNS deployment if a new DNS service is now used (kube-dns to CoreDNS or vice versa) + if err := removeOldDNSDeploymentIfAnotherDNSIsUsed(&cfg.ClusterConfiguration, client, dryRun); err != nil { + errs = append(errs, err) + } } - if err := proxy.EnsureProxyAddon(&cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, client); err != nil { - errs = append(errs, err) + // If the kube-proxy ConfigMap is missing, show a warning and assume that kube-proxy + // was skipped during "kubeadm init", and that its redeployment on upgrade is not desired. + // + // TODO: remove this once "kubeadm upgrade apply" phases are supported: + // https://github.com/kubernetes/kubeadm/issues/1318 + if _, err := client.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get( + context.TODO(), + kubeadmconstants.KubeProxyConfigMap, + metav1.GetOptions{}, + ); err != nil && apierrors.IsNotFound(err) { + klog.Warningf("the ConfigMap %q in the namespace %q was not found. "+ + "Assuming that kube-proxy was not deployed for this cluster. "+ + "Note that once 'kubeadm upgrade apply' supports phases you "+ + "will have to skip the kube-proxy upgrade manually", + kubeadmconstants.KubeProxyConfigMap, + metav1.NamespaceSystem) + } else { + // Upgrade kube-proxy + if err := proxy.EnsureProxyAddon(&cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, client); err != nil { + errs = append(errs, err) + } } + return errorsutil.NewAggregate(errs) }