Skip to content

Commit

Permalink
Added support for a configurable number of nodes to GCE
Browse files Browse the repository at this point in the history
Includes the suggested IP range function from the original
kubetest.
  • Loading branch information
michaelmdresser committed Jul 16, 2020
1 parent 84f795e commit eb98594
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kubetest2-gce/deployer/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,28 @@ func (d *deployer) buildEnv() []string {
// kube-up and kube-down get this as a default ("kubernetes") but log-dump
// does not. opted to set it manually here for maximum consistency
env = append(env, "KUBE_GCE_INSTANCE_PREFIX=kubetest2")

// Pass through number of nodes and associated IP range. In the future,
// IP range will be configurable.
env = append(env, fmt.Sprintf("NUM_NODES=%d", d.NumNodes))
env = append(env, fmt.Sprintf("CLUSTER_IP_RANGE=%s", getClusterIPRange(d.NumNodes)))

return env
}

// Taken from the kubetest bash (gce) deployer
// Calculates the cluster IP range based on the no. of nodes in the cluster.
// Note: This mimics the function get-cluster-ip-range used by kube-up script.
func getClusterIPRange(numNodes int) string {
suggestedRange := "10.64.0.0/14"
if numNodes > 1000 {
suggestedRange = "10.64.0.0/13"
}
if numNodes > 2000 {
suggestedRange = "10.64.0.0/12"
}
if numNodes > 4000 {
suggestedRange = "10.64.0.0/11"
}
return suggestedRange
}
2 changes: 2 additions & 0 deletions kubetest2-gce/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type deployer struct {
OverwriteLogsDir bool `desc:"If set, will overwrite an existing logs directory if one is encountered during dumping of logs. Useful when runnning tests locally."`
BoskosLocation string `desc:"If set, manually specifies the location of the boskos server. If unset and boskos is needed, defaults to http://boskos.test-pods.svc.cluster.local."`
LegacyMode bool `desc:"Set if the provided repo root is the kubernetes/kubernetes repo and not kubernetes/cloud-provider-gcp."`
NumNodes int `desc:"The number of nodes in the cluster."`
}

// New implements deployer.New for gce
Expand All @@ -74,6 +75,7 @@ func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
boskosHeartbeatClose: make(chan struct{}),
BoskosAcquireTimeoutSeconds: 5 * 60,
BoskosLocation: "http://boskos.test-pods.svc.cluster.local.",
NumNodes: 3,
}

flagSet, err := gpflag.Parse(d)
Expand Down
4 changes: 4 additions & 0 deletions kubetest2-gce/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func enableComputeAPI(project string) error {
}

func (d *deployer) verifyUpFlags() error {
if d.NumNodes < 1 {
return fmt.Errorf("number of nodes must be at least 1")
}

if err := d.setRepoPathIfNotSet(); err != nil {
return err
}
Expand Down

0 comments on commit eb98594

Please sign in to comment.