Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
e2e: idempotent namespace creation
Browse files Browse the repository at this point in the history
We create a test namespace once in the management cluster, and once in
the application cluster. Sometimes, in development, both of these happen
to be the same, so the second time we try to create the ns it'll error
out with "namespace foobar already exists", so if that happens we'll
just ignore it.
  • Loading branch information
juliogreff authored and Oleg Sidorov committed Feb 24, 2020
1 parent f4cada9 commit 3e58d0a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/e2e/e2e_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,24 @@ func poll(timeout time.Duration, waitCondition func() (bool, error)) error {

func setupNamespace(name string) (*corev1.Namespace, error) {
newNs := testNamespace(name)
_, err := appKubeClient.CoreV1().Namespaces().Create(newNs)

// We create a test namespace once in the management cluster, and once
// in the application cluster. Sometimes, in development, both of these
// happen to be the same, so the second time we try to create the ns
// it'll error out with "namespace foobar already exists", so if that
// happens we'll just ignore it.

ns, err := appKubeClient.CoreV1().Namespaces().Create(newNs)
if err != nil {
return nil, err
}

return kubeClient.CoreV1().Namespaces().Create(newNs)
_, err = kubeClient.CoreV1().Namespaces().Create(newNs)
if err != nil && !errors.IsAlreadyExists(err) {
return nil, err
}

return ns, nil
}

func teardownNamespace(name string) {
Expand Down

0 comments on commit 3e58d0a

Please sign in to comment.