Skip to content

Commit

Permalink
fix: wait namespace is actually deleted (#413)
Browse files Browse the repository at this point in the history
Co-authored-by: Erik Godding Boye <egboye@gmail.com>
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly and erikgb authored Nov 14, 2022
1 parent 62c2940 commit 6b6e6b9
Showing 1 changed file with 17 additions and 3 deletions.
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 @@ -121,7 +135,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

0 comments on commit 6b6e6b9

Please sign in to comment.