Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Verify that a namespace is truly deleted after an API call #32

Merged
merged 5 commits into from
Oct 23, 2019
Merged
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion tests/utils/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -12,6 +13,8 @@ import (
"time"
)

const namespaceDeletionTimeout = 5 * time.Minute

/* client-go util methods */

func GetK8sClientSet() (*kubernetes.Clientset, error) {
Expand Down Expand Up @@ -43,7 +46,22 @@ func DropNamespace(clientSet *kubernetes.Clientset, name string) error {
PropagationPolicy: &propagationPolicy,
}

return clientSet.CoreV1().Namespaces().Delete(name, &options)
err := clientSet.CoreV1().Namespaces().Delete(name, &options)
if err != nil {
return err
}

return retry(namespaceDeletionTimeout, 3*time.Second, func() error {
rpalaznik marked this conversation as resolved.
Show resolved Hide resolved
_, err := clientSet.CoreV1().Namespaces().Get(name, metav1.GetOptions{})
if err == nil {
return errors.New("the namespace is still there")
} else if statusErr, ok := err.(*apiErrors.StatusError); !ok || statusErr.Status().Reason != metav1.StatusReasonNotFound {
return err
} else {
log.Info("Deleted!")
rpalaznik marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
})
}

func waitForPodStatusPhase(clientSet *kubernetes.Clientset, podName string, namespace string, status string, timeout time.Duration) error {
Expand Down