Skip to content

Commit 5826b09

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#42713 from luxas/kubeadm_fix_reset
Automatic merge from submit-queue (batch tested with PRs 43018, 42713) kubeadm: Don't drain and remove the current node on kubeadm reset **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: In v1.5, `kubeadm reset` would drain your node and remove it from your cluster if you specified, but now in v1.6 we can't do that due to the RBAC rules we have set up. After conversations with @liggitt, I also agree this functionality was somehow a little mis-placed (though still very convenient to use), so we're removing it for v1.6. It's the system administrator's duty to drain and remove nodes from the cluster, not the nodes' responsibility. The current behavior is therefore a bug that needs to be fixed in v1.6 **Release note**: ```release-note kubeadm: `kubeadm reset` won't drain and remove the current node anymore ``` @liggitt @deads2k @jbeda @dmmcquay @pires @errordeveloper
2 parents 1221779 + c7fc530 commit 5826b09

File tree

1 file changed

+5
-57
lines changed

1 file changed

+5
-57
lines changed

cmd/kubeadm/app/cmd/reset.go

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"os"
2323
"os/exec"
2424
"path/filepath"
25-
"strings"
2625

2726
"github.com/spf13/cobra"
2827

@@ -36,13 +35,13 @@ import (
3635

3736
// NewCmdReset returns the "kubeadm reset" command
3837
func NewCmdReset(out io.Writer) *cobra.Command {
39-
var skipPreFlight, removeNode bool
38+
var skipPreFlight bool
4039
var certsDir string
4140
cmd := &cobra.Command{
4241
Use: "reset",
4342
Short: "Run this to revert any changes made to this host by 'kubeadm init' or 'kubeadm join'.",
4443
Run: func(cmd *cobra.Command, args []string) {
45-
r, err := NewReset(skipPreFlight, removeNode, certsDir)
44+
r, err := NewReset(skipPreFlight, certsDir)
4645
kubeadmutil.CheckErr(err)
4746
kubeadmutil.CheckErr(r.Run(out))
4847
},
@@ -53,11 +52,6 @@ func NewCmdReset(out io.Writer) *cobra.Command {
5352
"Skip preflight checks normally run before modifying the system",
5453
)
5554

56-
cmd.PersistentFlags().BoolVar(
57-
&removeNode, "remove-node", true,
58-
"Remove this node from the pool of nodes in this cluster",
59-
)
60-
6155
cmd.PersistentFlags().StringVar(
6256
&certsDir, "cert-dir", kubeadmapiext.DefaultCertificatesDir,
6357
"The path to the directory where the certificates are stored. If specified, clean this directory.",
@@ -67,11 +61,10 @@ func NewCmdReset(out io.Writer) *cobra.Command {
6761
}
6862

6963
type Reset struct {
70-
removeNode bool
71-
certsDir string
64+
certsDir string
7265
}
7366

74-
func NewReset(skipPreFlight, removeNode bool, certsDir string) (*Reset, error) {
67+
func NewReset(skipPreFlight bool, certsDir string) (*Reset, error) {
7568
if !skipPreFlight {
7669
fmt.Println("[preflight] Running pre-flight checks")
7770

@@ -83,20 +76,13 @@ func NewReset(skipPreFlight, removeNode bool, certsDir string) (*Reset, error) {
8376
}
8477

8578
return &Reset{
86-
removeNode: removeNode,
87-
certsDir: certsDir,
79+
certsDir: certsDir,
8880
}, nil
8981
}
9082

9183
// Run reverts any changes made to this host by "kubeadm init" or "kubeadm join".
9284
func (r *Reset) Run(out io.Writer) error {
9385

94-
// Try to drain and remove the node from the cluster
95-
err := drainAndRemoveNode(r.removeNode)
96-
if err != nil {
97-
fmt.Printf("[reset] Failed to cleanup node: [%v]\n", err)
98-
}
99-
10086
// Try to stop the kubelet service
10187
initSystem, err := initsystem.GetInitSystem()
10288
if err != nil {
@@ -151,44 +137,6 @@ func (r *Reset) Run(out io.Writer) error {
151137
return nil
152138
}
153139

154-
func drainAndRemoveNode(removeNode bool) error {
155-
hostname, err := os.Hostname()
156-
if err != nil {
157-
return fmt.Errorf("failed to detect node hostname")
158-
}
159-
hostname = strings.ToLower(hostname)
160-
161-
// TODO: Use the "native" k8s client for this once we're confident the versioned is working
162-
kubeConfigPath := filepath.Join(kubeadmapi.GlobalEnvParams.KubernetesDir, kubeadmconstants.KubeletKubeConfigFileName)
163-
164-
getNodesCmd := fmt.Sprintf("kubectl --kubeconfig %s get nodes | grep %s", kubeConfigPath, hostname)
165-
output, err := exec.Command("sh", "-c", getNodesCmd).Output()
166-
if err != nil {
167-
// kubeadm shouldn't drain and/or remove the node when it doesn't exist anymore
168-
return fmt.Errorf("failed to list nodes: %v", err)
169-
}
170-
if len(output) == 0 {
171-
return fmt.Errorf("list nodes request returned zero entries")
172-
}
173-
174-
fmt.Printf("[reset] Draining node: %q\n", hostname)
175-
176-
_, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "drain", hostname, "--delete-local-data", "--force", "--ignore-daemonsets").Output()
177-
if err != nil {
178-
return fmt.Errorf("failed to drain node %q: %v", hostname, err)
179-
}
180-
181-
if removeNode {
182-
fmt.Printf("[reset] Removing node: %q\n", hostname)
183-
_, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "delete", "node", hostname).Output()
184-
if err != nil {
185-
return fmt.Errorf("failed to remove node %q: %v", hostname, err)
186-
}
187-
}
188-
189-
return nil
190-
}
191-
192140
// cleanDir removes everything in a directory, but not the directory itself
193141
func cleanDir(filePath string) error {
194142
// If the directory doesn't even exist there's nothing to do, and we do

0 commit comments

Comments
 (0)