Skip to content

Commit db550bb

Browse files
authored
fix(e2e): carry the kubeconfig into the partial-cluster delete
Review feedback on kube-logging#2301. The delete that clears a half-built cluster after a create times out did not name the kubeconfig the create used, so it fell back to the shared default. That is the delete most likely to lose the lock, because it runs exactly when several creates are timing out together. The stalled-create case creates with a kubeconfig now, so the delete's arguments are pinned rather than only its presence: without the fix it reports `delete cluster --name stuck` against the expected `delete cluster --kubeconfig /tmp/kind-stuck.kubeconfig --name stuck`. Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
1 parent a314e11 commit db550bb

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

e2e/internal/kind/commands.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ func (k *Kind) CreateCluster(options CreateClusterOptions) error {
110110

111111
case errors.Is(err, ErrTimeout):
112112
// kind removes a half-built cluster when one of its own actions fails,
113-
// but not when we kill it, so the leftovers have to go explicitly.
114-
cleanupErr := k.deleteCluster(k.CleanupTimeout, DeleteClusterOptions{Name: options.Name})
113+
// but not when we kill it, so the leftovers have to go explicitly. The
114+
// kubeconfig has to come along: this delete runs when creates are timing
115+
// out together, which is when a shared one loses the lock.
116+
cleanupErr := k.deleteCluster(k.CleanupTimeout, DeleteClusterOptions{
117+
Name: options.Name,
118+
Kubeconfig: options.Kubeconfig,
119+
})
115120
if cleanupErr != nil {
116121
return fmt.Errorf("%w; deleting the partial cluster also failed: %w", err, cleanupErr)
117122
}

e2e/internal/kind/commands_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,20 @@ func TestInvocations(t *testing.T) {
266266
want: []string{"create cluster --name fine"},
267267
},
268268
// kind tears down a half-built cluster when one of its own actions
269-
// fails, but not when we kill it, so the delete has to be ours.
269+
// fails, but not when we kill it, so the delete has to be ours. It has
270+
// to name the create's kubeconfig too: this is the delete that runs while
271+
// several creates are timing out together.
270272
"a stalled create deletes the partial cluster": {
271273
sleepEnv: "FAKE_KIND_CREATE_SLEEP",
272274
timeout: shortTimeout,
273-
invoke: func(k *Kind) error { return k.CreateCluster(CreateClusterOptions{Name: "stuck"}) },
274-
wantErr: true,
275-
want: []string{"create cluster --name stuck", "delete cluster --name stuck"},
275+
invoke: func(k *Kind) error {
276+
return k.CreateCluster(CreateClusterOptions{Name: "stuck", Kubeconfig: "/tmp/kind-stuck.kubeconfig"})
277+
},
278+
wantErr: true,
279+
want: []string{
280+
"create cluster --kubeconfig /tmp/kind-stuck.kubeconfig --name stuck",
281+
"delete cluster --kubeconfig /tmp/kind-stuck.kubeconfig --name stuck",
282+
},
276283
},
277284
"an empty image list runs nothing": {
278285
invoke: func(k *Kind) error { return k.LoadDockerImage(nil, LoadDockerImageOptions{Name: "c"}) },

0 commit comments

Comments
 (0)