-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional check to dangling cluster test
Also remove unused code which was needed for failed creation test
- Loading branch information
Showing
2 changed files
with
45 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,65 +581,6 @@ func BootstrapServicePerimeterProjects(t *testing.T, desiredProjects int) []*clo | |
return projects | ||
} | ||
|
||
func RemoveContainerServiceAgentRoleFromContainerEngineRobot(t *testing.T, project *cloudresourcemanager.Project) { | ||
config := BootstrapConfig(t) | ||
if config == nil { | ||
return | ||
} | ||
|
||
client := config.NewResourceManagerClient(config.UserAgent) | ||
containerEngineRobot := fmt.Sprintf("serviceAccount:service-%[email protected]", project.ProjectNumber) | ||
getPolicyRequest := &cloudresourcemanager.GetIamPolicyRequest{} | ||
policy, err := client.Projects.GetIamPolicy(project.ProjectId, getPolicyRequest).Do() | ||
if err != nil { | ||
t.Fatalf("error getting project iam policy: %v", err) | ||
} | ||
roleFound := false | ||
changed := false | ||
for _, binding := range policy.Bindings { | ||
if binding.Role == "roles/container.serviceAgent" { | ||
memberFound := false | ||
for i, member := range binding.Members { | ||
if member == containerEngineRobot { | ||
binding.Members[i] = binding.Members[len(binding.Members)-1] | ||
memberFound = true | ||
} | ||
} | ||
if memberFound { | ||
binding.Members = binding.Members[:len(binding.Members)-1] | ||
changed = true | ||
} | ||
} else if binding.Role == "roles/editor" { | ||
memberFound := false | ||
for _, member := range binding.Members { | ||
if member == containerEngineRobot { | ||
memberFound = true | ||
break | ||
} | ||
} | ||
if !memberFound { | ||
binding.Members = append(binding.Members, containerEngineRobot) | ||
changed = true | ||
} | ||
roleFound = true | ||
} | ||
} | ||
if !roleFound { | ||
policy.Bindings = append(policy.Bindings, &cloudresourcemanager.Binding{ | ||
Members: []string{containerEngineRobot}, | ||
Role: "roles/editor", | ||
}) | ||
changed = true | ||
} | ||
if changed { | ||
setPolicyRequest := &cloudresourcemanager.SetIamPolicyRequest{Policy: policy} | ||
policy, err = client.Projects.SetIamPolicy(project.ProjectId, setPolicyRequest).Do() | ||
if err != nil { | ||
t.Fatalf("error setting project iam policy: %v", err) | ||
} | ||
} | ||
} | ||
|
||
// BootstrapProject will create or get a project named | ||
// "<projectIDPrefix><projectIDSuffix>" that will persist across test runs, | ||
// where projectIDSuffix is based off of getTestProjectFromEnv(). The reason | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters