Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api generation #35

Merged
merged 12 commits into from
Mar 28, 2024
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the test case not failing before because of finalizers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intermittently yes.
See the history here - https://github.com/nephio-project/porch/actions/workflows/porchctl-cli-e2e.yaml
I believe there is some timing/race condition on how the PackageRev api-resource gets updated. If the Finalizers remain, it blocks the NameSpace deletion.

Copy link
Contributor

@nagygergo nagygergo Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's fine, I'll open a separate issue on this one. Seems strange that porch-server is sometimes able to delete the packagerevs and sometimes not.

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
Loading