Skip to content

Commit 16d2f2a

Browse files
Merge pull request #11731 from andriyDev/fix-multinode-restart
Move node config deletion out of drainNode and into Delete
2 parents 62f1f80 + 5727823 commit 16d2f2a

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

Diff for: pkg/minikube/node/node.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func Add(cc *config.ClusterConfig, n config.Node, delOnFail bool) error {
8282

8383
// drainNode drains then deletes (removes) node from cluster.
8484
func drainNode(cc config.ClusterConfig, name string) (*config.Node, error) {
85-
n, index, err := Retrieve(cc, name)
85+
n, _, err := Retrieve(cc, name)
8686
if err != nil {
8787
return n, errors.Wrap(err, "retrieve")
8888
}
@@ -130,8 +130,7 @@ func drainNode(cc config.ClusterConfig, name string) (*config.Node, error) {
130130
}
131131
klog.Infof("successfully deleted node %q", name)
132132

133-
cc.Nodes = append(cc.Nodes[:index], cc.Nodes[index+1:]...)
134-
return n, config.SaveProfile(viper.GetString(config.ProfileName), &cc)
133+
return n, nil
135134
}
136135

137136
// Delete calls drainNode to remove node from cluster and deletes the host.
@@ -152,7 +151,13 @@ func Delete(cc config.ClusterConfig, name string) (*config.Node, error) {
152151
return n, err
153152
}
154153

155-
return n, nil
154+
_, index, err := Retrieve(cc, name)
155+
if err != nil {
156+
return n, errors.Wrap(err, "retrieve")
157+
}
158+
159+
cc.Nodes = append(cc.Nodes[:index], cc.Nodes[index+1:]...)
160+
return n, config.SaveProfile(viper.GetString(config.ProfileName), &cc)
156161
}
157162

158163
// Retrieve finds the node by name in the given cluster

Diff for: site/content/en/docs/contrib/tests.en.md

+3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ tests the minikube node stop command
256256
#### validateStartNodeAfterStop
257257
tests the minikube node start command on an existing stopped node
258258

259+
#### validateRestartKeepsNodes
260+
restarts minikube cluster and checks if the reported node list is unchanged
261+
259262
#### validateStopMultiNodeCluster
260263
runs minikube stop on a multinode cluster
261264

Diff for: test/integration/multinode_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestMultiNode(t *testing.T) {
5555
{"CopyFile", validateCopyFileWithMultiNode},
5656
{"StopNode", validateStopRunningNode},
5757
{"StartAfterStop", validateStartNodeAfterStop},
58+
{"RestartKeepsNodes", validateRestartKeepsNodes},
5859
{"DeleteNode", validateDeleteNodeFromMultiNode},
5960
{"StopMultiNode", validateStopMultiNodeCluster},
6061
{"RestartMultiNode", validateRestartMultiNodeCluster},
@@ -258,6 +259,36 @@ func validateStartNodeAfterStop(ctx context.Context, t *testing.T, profile strin
258259
}
259260
}
260261

262+
// validateRestartKeepsNodes restarts minikube cluster and checks if the reported node list is unchanged
263+
func validateRestartKeepsNodes(ctx context.Context, t *testing.T, profile string) {
264+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "node", "list", "-p", profile))
265+
if err != nil {
266+
t.Errorf("failed to run node list. args %q : %v", rr.Command(), err)
267+
}
268+
269+
nodeList := rr.Stdout.String()
270+
271+
_, err = Run(t, exec.CommandContext(ctx, Target(), "stop", "-p", profile))
272+
if err != nil {
273+
t.Errorf("failed to run minikube stop. args %q : %v", rr.Command(), err)
274+
}
275+
276+
_, err = Run(t, exec.CommandContext(ctx, Target(), "start", "-p", profile, "--wait=true", "-v=8", "--alsologtostderr"))
277+
if err != nil {
278+
t.Errorf("failed to run minikube start. args %q : %v", rr.Command(), err)
279+
}
280+
281+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "node", "list", "-p", profile))
282+
if err != nil {
283+
t.Errorf("failed to run node list. args %q : %v", rr.Command(), err)
284+
}
285+
286+
restartedNodeList := rr.Stdout.String()
287+
if nodeList != restartedNodeList {
288+
t.Fatalf("reported node list is not the same after restart. Before restart: %s\nAfter restart: %s", nodeList, restartedNodeList)
289+
}
290+
}
291+
261292
// validateStopMultiNodeCluster runs minikube stop on a multinode cluster
262293
func validateStopMultiNodeCluster(ctx context.Context, t *testing.T, profile string) {
263294
// Run minikube stop on the cluster

0 commit comments

Comments
 (0)