@@ -28,6 +28,7 @@ import (
28
28
errorsutil "k8s.io/apimachinery/pkg/util/errors"
29
29
"k8s.io/apimachinery/pkg/util/version"
30
30
clientset "k8s.io/client-go/kubernetes"
31
+ "k8s.io/klog"
31
32
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
32
33
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
33
34
"k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns"
@@ -100,18 +101,68 @@ func PerformPostUpgradeTasks(client clientset.Interface, cfg *kubeadmapi.InitCon
100
101
errs = append (errs , err )
101
102
}
102
103
103
- // Upgrade kube-dns/CoreDNS and kube-proxy
104
- if err := dns .EnsureDNSAddon (& cfg .ClusterConfiguration , client ); err != nil {
105
- errs = append (errs , err )
104
+ // If the coredns / kube-dns ConfigMaps are missing, show a warning and assume that the
105
+ // DNS addon was skipped during "kubeadm init", and that its redeployment on upgrade is not desired.
106
+ //
107
+ // TODO: remove this once "kubeadm upgrade apply" phases are supported:
108
+ // https://github.com/kubernetes/kubeadm/issues/1318
109
+ var missingCoreDNSConfigMap , missingKubeDNSConfigMap bool
110
+ if _ , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (
111
+ context .TODO (),
112
+ kubeadmconstants .CoreDNSConfigMap ,
113
+ metav1.GetOptions {},
114
+ ); err != nil && apierrors .IsNotFound (err ) {
115
+ missingCoreDNSConfigMap = true
106
116
}
107
- // Remove the old DNS deployment if a new DNS service is now used (kube-dns to CoreDNS or vice versa)
108
- if err := removeOldDNSDeploymentIfAnotherDNSIsUsed (& cfg .ClusterConfiguration , client , dryRun ); err != nil {
109
- errs = append (errs , err )
117
+ if _ , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (
118
+ context .TODO (),
119
+ kubeadmconstants .KubeDNSConfigMap ,
120
+ metav1.GetOptions {},
121
+ ); err != nil && apierrors .IsNotFound (err ) {
122
+ missingKubeDNSConfigMap = true
123
+ }
124
+ if missingCoreDNSConfigMap && missingKubeDNSConfigMap {
125
+ klog .Warningf ("the ConfigMaps %q/%q in the namespace %q were not found. " +
126
+ "Assuming that a DNS server was not deployed for this cluster. " +
127
+ "Note that once 'kubeadm upgrade apply' supports phases you " +
128
+ "will have to skip the DNS upgrade manually" ,
129
+ kubeadmconstants .CoreDNSConfigMap ,
130
+ kubeadmconstants .KubeDNSConfigMap ,
131
+ metav1 .NamespaceSystem )
132
+ } else {
133
+ // Upgrade CoreDNS/kube-dns
134
+ if err := dns .EnsureDNSAddon (& cfg .ClusterConfiguration , client ); err != nil {
135
+ errs = append (errs , err )
136
+ }
137
+ // Remove the old DNS deployment if a new DNS service is now used (kube-dns to CoreDNS or vice versa)
138
+ if err := removeOldDNSDeploymentIfAnotherDNSIsUsed (& cfg .ClusterConfiguration , client , dryRun ); err != nil {
139
+ errs = append (errs , err )
140
+ }
110
141
}
111
142
112
- if err := proxy .EnsureProxyAddon (& cfg .ClusterConfiguration , & cfg .LocalAPIEndpoint , client ); err != nil {
113
- errs = append (errs , err )
143
+ // If the kube-proxy ConfigMap is missing, show a warning and assume that kube-proxy
144
+ // was skipped during "kubeadm init", and that its redeployment on upgrade is not desired.
145
+ //
146
+ // TODO: remove this once "kubeadm upgrade apply" phases are supported:
147
+ // https://github.com/kubernetes/kubeadm/issues/1318
148
+ if _ , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (
149
+ context .TODO (),
150
+ kubeadmconstants .KubeProxyConfigMap ,
151
+ metav1.GetOptions {},
152
+ ); err != nil && apierrors .IsNotFound (err ) {
153
+ klog .Warningf ("the ConfigMap %q in the namespace %q was not found. " +
154
+ "Assuming that kube-proxy was not deployed for this cluster. " +
155
+ "Note that once 'kubeadm upgrade apply' supports phases you " +
156
+ "will have to skip the kube-proxy upgrade manually" ,
157
+ kubeadmconstants .KubeProxyConfigMap ,
158
+ metav1 .NamespaceSystem )
159
+ } else {
160
+ // Upgrade kube-proxy
161
+ if err := proxy .EnsureProxyAddon (& cfg .ClusterConfiguration , & cfg .LocalAPIEndpoint , client ); err != nil {
162
+ errs = append (errs , err )
163
+ }
114
164
}
165
+
115
166
return errorsutil .NewAggregate (errs )
116
167
}
117
168
0 commit comments