Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kubetest2-gke/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func NewDeployer(opts types.Options) *Deployer {
},
NetworkOptions: &options.NetworkOptions{
Network: "default",
UseCustomSubnetMode: false,
RemoveNetwork: true,
EnableULAInternalIPv6: false,
},
Expand Down
20 changes: 12 additions & 8 deletions kubetest2-gke/deployer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (d *Deployer) VerifyNetworkFlags() error {
if err := validateSubnetRanges(d.SubnetworkRanges); err != nil {
return err
}

if !d.UseCustomSubnetMode {
return errors.New("the 'auto' subnet mode cannot be used for multi-project profile")
}
}

return d.internalizeNetworkFlags(numProjects)
Expand Down Expand Up @@ -148,18 +152,18 @@ func (d *Deployer) internalizeNetworkFlags(numProjects int) error {

func (d *Deployer) CreateNetwork() error {
// Create network if it doesn't exist.
// For single project profile, the subnet-mode could be auto for simplicity.
// For multiple projects profile, the subnet-mode must be custom and should only be created in the host project.
// (Here we consider the first project to be the host project and the rest be service projects)
// Reference: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-shared-vpc#creating_a_network_and_two_subnets
subnetMode := "auto"
if len(d.Projects) > 1 {
subnetMode = "custom"
}
if runWithNoOutput(exec.Command("gcloud", "compute", "networks", "describe", d.Network,
"--project="+d.Projects[0],
"--format=value(name)")) != nil {
// Assume error implies non-existent.
// For single project profile, the subnet-mode could be auto for simplicity.
// For multiple projects profile, the subnet-mode must be custom and should only be created in the host project.
// (Here we consider the first project to be the host project and the rest be service projects)
// Reference: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-shared-vpc#creating_a_network_and_two_subnets
subnetMode := "auto"
if d.UseCustomSubnetMode || len(d.Projects) > 1 {
subnetMode = string("custom")
}
// TODO(chizhg): find a more reliable way to check if the network exists or not.
klog.V(1).Infof("Couldn't describe network %q, assuming it doesn't exist and creating it", d.Network)
createNetworkCommand := []string{
Expand Down
1 change: 1 addition & 0 deletions kubetest2-gke/deployer/options/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type NetworkOptions struct {
PrivateClusterMasterIPRanges []string `flag:"~private-cluster-master-ip-range" desc:"Private cluster master IP ranges. It should be IPv4 CIDR(s), and its length must be the same as the number of clusters if private cluster is requested."`
SubnetworkRanges []string `flag:"~subnetwork-ranges" desc:"Subnetwork ranges as required for shared VPC setup as described in https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-shared-vpc#creating_a_network_and_two_subnets. For multi-project profile, it is required and should be in the format of 10.0.4.0/22 10.0.32.0/20 10.4.0.0/14,172.16.4.0/22 172.16.16.0/20 172.16.4.0/22, where the subnetworks configuration for different project are separated by comma, and the ranges of each subnetwork configuration is separated by space."`
EnableULAInternalIPv6 bool `flag:"~enable-ula-internal-ipv6" desc:"Enable Unique Local IPv6 Addresses (ULA). Adds the --enable-ula-internal-ipv6 flag to the gcloud compute networks create command"`
UseCustomSubnetMode bool `flag:"~use-custom-subnet-mode" desc:"Use '--subnet-mode=custom' when creating the network. Effective only for single-project deployments, as multi-project deployments always use 'custom' mode. Defaults to false."`

RemoveNetwork bool `flag:"~remove-network" desc:"At the end of the test remove non-default network that was used by cluster. The 'default' network is never deleted. Defaults to true if not provided."`
}