Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait namespace is actually deleted (#413) #422

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/kuttlctl/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ For more detailed documentation, visit: https://kuttl.dev`,
return errors.New("only use --attach-control-plane-output with --start-control-plane")
}

// if we are working with a control plane we can not wait to delete ns (there is no ns controller)
// this is added before flags potentially override. control plane should skip ns and cluster delete but
// perhaps there are cases where that is part of the test. In general, there is no cluster to delete and
// there is no namespace controller.
if options.StartControlPlane {
options.SkipDelete = true
options.SkipClusterDelete = true
}

if isSet(flags, "skip-delete") {
options.SkipDelete = skipDelete
}
Expand Down
20 changes: 17 additions & 3 deletions pkg/test/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
corev1 "k8s.io/api/core/v1"
eventsv1 "k8s.io/api/events/v1"
eventsbeta1 "k8s.io/api/events/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/discovery"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -69,13 +70,26 @@ func (t *Case) DeleteNamespace(cl client.Client, ns *namespace) error {
defer cancel()
}

return cl.Delete(ctx, &corev1.Namespace{
nsObj := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns.Name,
},
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
},
}

if err := cl.Delete(ctx, nsObj); err != nil {
return err
}

return wait.PollImmediateUntilWithContext(ctx, 100*time.Millisecond, func(ctx context.Context) (done bool, err error) {
actual := &corev1.Namespace{}
err = cl.Get(ctx, client.ObjectKey{Name: ns.Name}, actual)
if k8serrors.IsNotFound(err) {
return true, nil
}
return false, err
})
}

Expand Down Expand Up @@ -120,7 +134,7 @@ func (t *Case) NamespaceExists(namespace string) (bool, error) {
}
ns := &corev1.Namespace{}
err = cl.Get(context.TODO(), client.ObjectKey{Name: namespace}, ns)
if err != nil && !errors.IsNotFound(err) {
if err != nil && !k8serrors.IsNotFound(err) {
return false, err
}
return ns.Name == namespace, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/case_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func TestMultiClusterCase(t *testing.T) {
}

c := Case{
Logger: testutils.NewTestLogger(t, ""),
Logger: testutils.NewTestLogger(t, ""),
SkipDelete: true,
Steps: []*Step{
{
Name: "initialize-testenv",
Expand Down
2 changes: 2 additions & 0 deletions pkg/test/harness_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestHarnessRunIntegration(t *testing.T) {
"./test_data/",
},
StartControlPlane: true,
SkipDelete: true,
CRDDir: "./test_crds/",
},
T: t,
Expand All @@ -39,6 +40,7 @@ func TestHarnessRunIntegrationWithConfig(t *testing.T) {
},
// set as true to skip service account check
StartControlPlane: true,
SkipDelete: true,
Config: config,
CRDDir: "./test_crds/",
},
Expand Down