Skip to content

Commit

Permalink
test: NetworkPolicy E2E tests cleanup for soak (Azure#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis authored Jan 8, 2019
1 parent 261c4d9 commit 0ed8f71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,11 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
if eng.HasNetworkPolicy("calico") || eng.HasNetworkPolicy("azure") || eng.HasNetworkPolicy("cilium") {
nsClientOne, nsClientTwo, nsServer := "client-one", "client-two", "server"
By("Creating namespaces")
_, err := namespace.Create(nsClientOne)
namespaceClientOne, err := namespace.CreateIfNotExist(nsClientOne)
Expect(err).NotTo(HaveOccurred())
_, err = namespace.Create(nsClientTwo)
namespaceClientTwo, err := namespace.CreateIfNotExist(nsClientTwo)
Expect(err).NotTo(HaveOccurred())
_, err = namespace.Create(nsServer)
namespaceServer, err := namespace.CreateIfNotExist(nsServer)
Expect(err).NotTo(HaveOccurred())
By("Creating client and server nginx deployments")
r := rand.New(rand.NewSource(time.Now().UnixNano()))
Expand Down Expand Up @@ -1002,6 +1002,12 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
Expect(err).NotTo(HaveOccurred())
err = serverDeploy.Delete(deleteResourceRetries)
Expect(err).NotTo(HaveOccurred())
err = namespaceClientOne.Delete()
Expect(err).NotTo(HaveOccurred())
err = namespaceClientTwo.Delete()
Expect(err).NotTo(HaveOccurred())
err = namespaceServer.Delete()
Expect(err).NotTo(HaveOccurred())
} else {
Skip("Calico or Azure network policy was not provisioned for this Cluster Definition")
}
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/kubernetes/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func Create(name string) (*Namespace, error) {
return Get(name)
}

// CreateIfNotExist a namespace with the given name if it doesn't exist already
func CreateIfNotExist(name string) (*Namespace, error) {
n, err := Get(name)
if err != nil {
return Create(name)
}
return n, nil
}

// Get returns a namespace for with a given name
func Get(name string) (*Namespace, error) {
cmd := exec.Command("kubectl", "get", "namespace", name, "-o", "json")
Expand Down

0 comments on commit 0ed8f71

Please sign in to comment.