Skip to content

Commit 8067dd8

Browse files
committed
kubeadm: fix the bug that 'kubeadm upgrade' hangs in single node cluster
1 parent 9c15432 commit 8067dd8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cmd/kubeadm/app/phases/upgrade/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ go_library(
4040
"//staging/src/k8s.io/api/core/v1:go_default_library",
4141
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
4242
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
43+
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
4344
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
4445
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
4546
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
"k8s.io/apimachinery/pkg/fields"
2728
errorsutil "k8s.io/apimachinery/pkg/util/errors"
2829
"k8s.io/apimachinery/pkg/util/version"
2930
clientset "k8s.io/client-go/kubernetes"
@@ -119,8 +120,15 @@ func removeOldDNSDeploymentIfAnotherDNSIsUsed(cfg *kubeadmapi.ClusterConfigurati
119120
deploymentToDelete = kubeadmconstants.KubeDNSDeploymentName
120121
}
121122

122-
// If we're dry-running, we don't need to wait for the new DNS addon to become ready
123-
if !dryRun {
123+
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
124+
FieldSelector: fields.Set{"spec.unschedulable": "false"}.AsSelector().String(),
125+
})
126+
if err != nil {
127+
return err
128+
}
129+
130+
// If we're dry-running or there are no scheduable nodes available, we don't need to wait for the new DNS addon to become ready
131+
if !dryRun && len(nodes.Items) != 0 {
124132
dnsDeployment, err := client.AppsV1().Deployments(metav1.NamespaceSystem).Get(context.TODO(), installedDeploymentName, metav1.GetOptions{})
125133
if err != nil {
126134
return err
@@ -132,7 +140,7 @@ func removeOldDNSDeploymentIfAnotherDNSIsUsed(cfg *kubeadmapi.ClusterConfigurati
132140

133141
// We don't want to wait for the DNS deployment above to become ready when dryrunning (as it never will)
134142
// but here we should execute the DELETE command against the dryrun clientset, as it will only be logged
135-
err := apiclient.DeleteDeploymentForeground(client, metav1.NamespaceSystem, deploymentToDelete)
143+
err = apiclient.DeleteDeploymentForeground(client, metav1.NamespaceSystem, deploymentToDelete)
136144
if err != nil && !apierrors.IsNotFound(err) {
137145
return err
138146
}

0 commit comments

Comments
 (0)