Skip to content

Commit

Permalink
Fix cli e2e test run issue
Browse files Browse the repository at this point in the history
  • Loading branch information
efiacor committed Mar 26, 2024
1 parent 4d5355f commit e1b19ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions test/e2e/cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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, " "))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit e1b19ec

Please sign in to comment.