Merge pull request #89593 from neolit123/1.19-skip-kube-proxy-on-upgrade
kubeadm: skip kube-proxy/dns upgrades on missing ConfigMaps
This commit is contained in:
		@@ -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,7 +101,36 @@ func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitCon
 | 
			
		||||
		errs = append(errs, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Upgrade kube-dns/CoreDNS and kube-proxy
 | 
			
		||||
	// 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
 | 
			
		||||
	}
 | 
			
		||||
	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)
 | 
			
		||||
		}
 | 
			
		||||
@@ -108,10 +138,31 @@ func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitCon
 | 
			
		||||
		if err := removeOldDNSDeploymentIfAnotherDNSIsUsed(&cfg.ClusterConfiguration, client, dryRun); 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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user