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

Allow specifying network stack type #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion kubetest2-gke/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const (
gceStockoutErrorPattern = ".*does not have enough resources available to fulfill.*"
)

const (
networkStackTypeIPv4 = "IPv4"
networkStackTypeIPv4IPv6 = "IPv4_IPv6"
)

type privateClusterAccessLevel string

const (
Expand Down Expand Up @@ -199,7 +204,8 @@ func NewDeployer(opts types.Options) *Deployer {
BoskosProjectsRequested: []int{1},
},
NetworkOptions: &options.NetworkOptions{
Network: "default",
Network: "default",
StackType: networkStackTypeIPv4,
},
ClusterOptions: &options.ClusterOptions{
Environment: "prod",
Expand Down
15 changes: 11 additions & 4 deletions kubetest2-gke/deployer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ func (d *Deployer) CreateNetwork() error {
// 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
// Additionally, for network stack type different from IPv4, the subnet mode must be custom too.
subnetMode := "auto"
if len(d.Projects) > 1 {
if len(d.Projects) > 1 || d.StackType != networkStackTypeIPv4 {
subnetMode = "custom"
}
if runWithNoOutput(exec.Command("gcloud", "compute", "networks", "describe", d.Network,
Expand All @@ -162,9 +163,15 @@ func (d *Deployer) CreateNetwork() error {
// Assume error implies non-existent.
// 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)
if err := runWithOutput(exec.Command("gcloud", "compute", "networks", "create", d.Network,
"--project="+d.Projects[0],
"--subnet-mode="+subnetMode)); err != nil {
args := []string{"compute", "networks", "create", d.Network, "--project=" + d.Projects[0], "--subnet-mode=" + subnetMode}

if d.StackType == networkStackTypeIPv4IPv6 {
// Currently dual stack networks only use an internal IP address range. If needed, this switch can be offered
// through a kubetest flag.
args = append(args, "--enable-ula-internal-ipv6")
}

if err := runWithOutput(exec.Command("gcloud", args...)); err != nil {
return err
}
}
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 @@ -22,4 +22,5 @@ type NetworkOptions struct {
PrivateClusterAccessLevel string `flag:"~private-cluster-access-level" desc:"Private cluster access level, if not empty, must be one of 'no', 'limited' or 'unrestricted'. See the details in https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters."`
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."`
StackType string `flag:"~network-stack-type" desc:"Stack type of the network, one of 'IPv4' or 'IPv4_IPv6'. Defaults to 'IPv4' if not provided."`
}