Skip to content

Commit

Permalink
Merge pull request #50 from chizhg/beta-for-shared-vpc
Browse files Browse the repository at this point in the history
Use gcloud beta command group for shared vpc operations
  • Loading branch information
k8s-ci-robot authored Sep 10, 2020
2 parents c364b92 + e72158d commit d9a6c4e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kubetest2-gke/deployer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ func enableSharedVPCAndGrantRoles(projects []string, region, network string) err
// Enable Shared VPC for multiproject requests on the host project.
// Assuming we have Shared VPC Admin role at the organization level.
networkHostProject := projects[0]
if err := runWithOutput(exec.Command("gcloud", "compute", "shared-vpc", "enable", networkHostProject)); err != nil {
// Shared VPC is still in beta, so we have to use the beta command group here.
// TODO(chizhg): remove beta after shared VPC is in prod.
if err := runWithOutput(exec.Command("gcloud", "beta", "compute", "shared-vpc", "enable", networkHostProject)); err != nil {
// Sometimes we may want to use the projects pre-configured with shared-vpc for testing,
// and the service account that runs this command might not have the right permission, so do not
// error out if an error happens here.
Expand All @@ -221,7 +223,7 @@ func enableSharedVPCAndGrantRoles(projects []string, region, network string) err

// Associate the rest of the projects.
for i := 1; i < len(projects); i++ {
if err := runWithOutput(exec.Command("gcloud", "compute", "shared-vpc",
if err := runWithOutput(exec.Command("gcloud", "beta", "compute", "shared-vpc",
"associated-projects", "add", projects[i],
"--host-project", networkHostProject)); err != nil {
klog.Warningf("Error associating project %q to Shared VPC: %v, it might be due to permission issues.", projects[i], err)
Expand Down Expand Up @@ -316,15 +318,15 @@ func disableSharedVPCProjects(projects []string) error {

// Disassociate the rest of the projects
for i := 1; i < len(projects); i++ {
if err := runWithOutput(exec.Command("gcloud", "compute", "shared-vpc",
if err := runWithOutput(exec.Command("gcloud", "beta", "compute", "shared-vpc",
"associated-projects", "remove", projects[i],
"--host-project", networkHostProject)); err != nil {
klog.Warningf("Error removing the associated project %q from Shared VPC: %v", projects[i], err)
}
}

// Disable Shared VPC for multiproject requests on the host project
if err := runWithOutput(exec.Command("gcloud", "compute", "shared-vpc", "disable", networkHostProject)); err != nil {
if err := runWithOutput(exec.Command("gcloud", "beta", "compute", "shared-vpc", "disable", networkHostProject)); err != nil {
klog.Warningf("Error disabling Shared VPC for the host project: %v", err)
}

Expand Down

0 comments on commit d9a6c4e

Please sign in to comment.