Skip to content

Commit

Permalink
Add labels to namespaces created during end to end tests
Browse files Browse the repository at this point in the history
Besides that it is a good practice to label resources created this allows in this case easy deletion of the namespaces if:
- there was an issue while running the tests
- the variable TEST_KEEP_NAMESPACES was set
- the tests were abruptly stopped by the developer

Currently you have to run something like:
$ kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep arendelle | xargs kubectl delete namespace
This would become:
$ kubectl delete ns -l "tekton.dev/test-e2e=true"
  • Loading branch information
fgiloux authored and tekton-robot committed Apr 7, 2020
1 parent 9a61678 commit b5ec5f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion test/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ func initializeLogsAndMetrics(t *testing.T) {

func createNamespace(t *testing.T, namespace string, kubeClient *knativetest.KubeClient) {
t.Logf("Create namespace %s to deploy to", namespace)
labels := map[string]string{
"tekton.dev/test-e2e": "true",
}
if _, err := kubeClient.Kube.CoreV1().Namespaces().Create(&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Name: namespace,
Labels: labels,
},
}); err != nil {
t.Fatalf("Failed to create namespace %s for tests: %s", namespace, err)
Expand Down
6 changes: 5 additions & 1 deletion test/v1alpha1/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ func initializeLogsAndMetrics(t *testing.T) {

func createNamespace(t *testing.T, namespace string, kubeClient *knativetest.KubeClient) {
t.Logf("Create namespace %s to deploy to", namespace)
labels := map[string]string{
"tekton.dev/test-e2e": "true",
}
if _, err := kubeClient.Kube.CoreV1().Namespaces().Create(&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Name: namespace,
Labels: labels,
},
}); err != nil {
t.Fatalf("Failed to create namespace %s for tests: %s", namespace, err)
Expand Down

0 comments on commit b5ec5f8

Please sign in to comment.