diff --git a/test/e2e/cli/cluster.go b/test/e2e/cli/cluster.go index cb385edd..560fba78 100644 --- a/test/e2e/cli/cluster.go +++ b/test/e2e/cli/cluster.go @@ -165,6 +165,8 @@ func KubectlCreateNamespace(t *testing.T, name string) { } func KubectlDeleteNamespace(t *testing.T, name string) { + //Removing Finalizers from PackageRevs in the test NameSpace to avoid locking when deleting + RemovePackagerevFinalizers(t, name) cmd := exec.Command("kubectl", "delete", "namespace", name) t.Logf("running command %v", strings.Join(cmd.Args, " ")) out, err := cmd.CombinedOutput() @@ -174,6 +176,40 @@ func KubectlDeleteNamespace(t *testing.T, name string) { t.Logf("output: %v", string(out)) } +func RemovePackagerevFinalizers(t *testing.T, namespace string) { + cmd := exec.Command("kubectl", "get", "packagerevs", "--namespace", namespace, "--output=jsonpath={.items[*].metadata.name}") + var stderr bytes.Buffer + var stdout bytes.Buffer + cmd.Stderr = &stderr + cmd.Stdout = &stdout + + if err := cmd.Run(); err != nil { + t.Fatalf("Error when getting packagerevs from namespace: %v: %s", err, stderr.String()) + } + + packagerevs := realySplit(stdout.String(), " ") + if len(packagerevs) == 0 { + t.Log("kubectl get packagerevs didn't return any objects - continue") + return + } + t.Logf("Removing Finalizers from PackagRevs: %v", packagerevs) + + for _, pkgrev := range packagerevs { + cmd := exec.Command("kubectl", "patch", "packagerev", pkgrev, "--type", "json", "--patch=[{\"op\": \"remove\", \"path\": \"/metadata/finalizers\"}]", "--namespace", namespace) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("Failed to remove Finalizer from %q: %v\n%s", pkgrev, err, string(out)) + } + } +} + +func realySplit(s, sep string) []string { + if len(s) == 0 { + return []string{} + } + return strings.Split(s, sep) +} + func RegisterRepository(t *testing.T, repoURL, namespace, name string) { cmd := exec.Command("porchctl", "repo", "register", "--namespace", namespace, "--name", name, repoURL) t.Logf("running command %v", strings.Join(cmd.Args, " ")) diff --git a/test/e2e/cli/config.go b/test/e2e/cli/config.go index e9947b5d..d1d66e2e 100644 --- a/test/e2e/cli/config.go +++ b/test/e2e/cli/config.go @@ -46,7 +46,7 @@ type TestCaseConfig struct { ConfigFile string `yaml:"-"` // Repository is the name of the k8s Repository resource to register the default Git repo. Repository string `yaml:"repository,omitempty"` - // Commands is a list of kpt commands to be executed by the test. + // Commands is a list of porchctl commands to be executed by the test. Commands []Command `yaml:"commands,omitempty"` // Skip the test? If the value is not empty, it will be used as a message with which to skip the test. Skip string `yaml:"skip,omitempty"`