Skip to content

Commit 16191db

Browse files
committed
skip deployment update if migration fails
1 parent 7074f28 commit 16191db

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,13 @@ func createCoreDNSAddon(deploymentBytes, serviceBytes, configBytes []byte, clien
236236
if err != nil {
237237
return errors.Wrap(err, "unable to fetch CoreDNS current installed version and ConfigMap.")
238238
}
239+
240+
var hasCoreDNSMigrationFailed bool
239241
if IsCoreDNSConfigMapMigrationRequired(corefile) {
240242
if err := migrateCoreDNSCorefile(client, coreDNSConfigMap, corefile, currentInstalledCoreDNSVersion); err != nil {
241243
// Errors in Corefile Migration is verified during preflight checks. This part will be executed when a user has chosen
242244
// to ignore preflight check errors.
245+
hasCoreDNSMigrationFailed = true
243246
klog.Warningf("the CoreDNS Configuration was not migrated: %v. The existing CoreDNS Corefile configuration has been retained.", err)
244247
if err := apiclient.CreateOrRetainConfigMap(client, coreDNSConfigMap, kubeadmconstants.CoreDNSConfigMap); err != nil {
245248
return err
@@ -286,9 +289,16 @@ func createCoreDNSAddon(deploymentBytes, serviceBytes, configBytes []byte, clien
286289
return errors.Wrapf(err, "%s Deployment", unableToDecodeCoreDNS)
287290
}
288291

289-
// Create the Deployment for CoreDNS or update it in case it already exists
290-
if err := apiclient.CreateOrUpdateDeployment(client, coreDNSDeployment); err != nil {
291-
return err
292+
// Create the deployment for CoreDNS or retain it in case the CoreDNS migration has failed during upgrade
293+
if hasCoreDNSMigrationFailed {
294+
if err := apiclient.CreateOrRetainDeployment(client, coreDNSDeployment, kubeadmconstants.CoreDNSDeploymentName); err != nil {
295+
return err
296+
}
297+
} else {
298+
// Create the Deployment for CoreDNS or update it in case it already exists
299+
if err := apiclient.CreateOrUpdateDeployment(client, coreDNSDeployment); err != nil {
300+
return err
301+
}
292302
}
293303

294304
coreDNSService := &v1.Service{}

cmd/kubeadm/app/phases/upgrade/preflight.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func checkMigration(client clientset.Interface) error {
108108

109109
_, err = migration.Migrate(currentInstalledCoreDNSversion, kubeadmconstants.CoreDNSVersion, corefile, false)
110110
if err != nil {
111-
return errors.Wrap(err, "the CoreDNS configuration will not be migrated, and may be incompatible with the upgraded version of CoreDNS")
111+
return errors.Wrap(err, "CoreDNS will not be upgraded")
112112
}
113113
return nil
114114
}

cmd/kubeadm/app/util/apiclient/idempotency.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ func CreateOrUpdateDeployment(client clientset.Interface, deploy *apps.Deploymen
147147
return nil
148148
}
149149

150+
// CreateOrRetainDeployment creates a Deployment if the target resource doesn't exist. If the resource exists already, this function will retain the resource instead.
151+
func CreateOrRetainDeployment(client clientset.Interface, deploy *apps.Deployment, deployName string) error {
152+
if _, err := client.AppsV1().Deployments(deploy.ObjectMeta.Namespace).Get(deployName, metav1.GetOptions{}); err != nil {
153+
if !apierrors.IsNotFound(err) {
154+
return nil
155+
}
156+
if _, err := client.AppsV1().Deployments(deploy.ObjectMeta.Namespace).Create(deploy); err != nil {
157+
if !apierrors.IsAlreadyExists(err) {
158+
return errors.Wrap(err, "unable to create deployment")
159+
}
160+
}
161+
}
162+
return nil
163+
}
164+
150165
// CreateOrUpdateDaemonSet creates a DaemonSet if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
151166
func CreateOrUpdateDaemonSet(client clientset.Interface, ds *apps.DaemonSet) error {
152167
if _, err := client.AppsV1().DaemonSets(ds.ObjectMeta.Namespace).Create(ds); err != nil {

0 commit comments

Comments
 (0)