Skip to content

Commit

Permalink
Delete the membership after unregistration failure (#175) (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-yu authored Oct 5, 2022
1 parent 12c3de4 commit 1d82d3f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions e2e/testcases/csr_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ func cleanMembershipInfo(nt *nomostest.NT, fleetMembership, gcpProject, gkeURI s
}
nt.T.Logf("The membership exits, unregistering the cluster from project %q to clean up the membership", fleetProject)
if err = unregisterCluster(fleetMembership, fleetProject, gkeURI); err != nil {
nt.T.Errorf("failed to unregister the cluster: %v", err)
nt.T.Skip("Skip the test because unable to unregister the cluster")
nt.T.Logf("failed to unregister the cluster: %v", err)
if err = deleteMembership(fleetMembership, fleetProject); err != nil {
nt.T.Logf("failed to delete the membership %q: %v", fleetMembership, err)
}
membershipExists, _, err = getMembershipIdentityProvider(nt)
if err != nil {
nt.T.Error(err)
Expand Down Expand Up @@ -348,6 +350,15 @@ func unregisterCluster(fleetMembership, gcpProject, gkeURI string) error {
return nil
}

// deleteMembership deletes the membership from the cluster.
func deleteMembership(fleetMembership, gcpProject string) error {
out, err := exec.Command("gcloud", "container", "hub", "memberships", "delete", fleetMembership, "--quiet", "--project", gcpProject).CombinedOutput()
if err != nil {
return fmt.Errorf("%s: %v", string(out), err)
}
return nil
}

// registerCluster registers a cluster in a fleet.
func registerCluster(fleetMembership, gcpProject, gkeURI string) error {
out, err := exec.Command("gcloud", "container", "hub", "memberships", "register", fleetMembership, "--project", gcpProject, "--gke-uri", gkeURI, "--enable-workload-identity").CombinedOutput()
Expand Down

0 comments on commit 1d82d3f

Please sign in to comment.