From bacc01f7295d0df75cdbb52e7e63e7fe3fb883f4 Mon Sep 17 00:00:00 2001 From: Shyam Jeedigunta Date: Sat, 19 Aug 2017 03:00:50 +0200 Subject: [PATCH] Auto-calculate CLUSTER_IP_RANGE based on no. of nodes --- cluster/gce/config-common.sh | 14 ++++++++++++++ cluster/gce/config-default.sh | 2 +- cluster/gce/config-test.sh | 2 +- test/e2e/framework/test_context.go | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cluster/gce/config-common.sh b/cluster/gce/config-common.sh index dee1aad2c4d..4512faf35ab 100644 --- a/cluster/gce/config-common.sh +++ b/cluster/gce/config-common.sh @@ -84,6 +84,20 @@ function get-node-ip-range { echo "${suggested_range}" } +function get-cluster-ip-range { + local suggested_range="10.100.0.0/14" + if [[ "${NUM_NODES}" -gt 1000 ]]; then + suggested_range="10.100.0.0/13" + fi + if [[ "${NUM_NODES}" -gt 2000 ]]; then + suggested_range="10.100.0.0/12" + fi + if [[ "${NUM_NODES}" -gt 4000 ]]; then + suggested_range="10.100.0.0/11" + fi + echo "${suggested_range}" +} + if [[ "${FEDERATION:-}" == true ]]; then NODE_SCOPES="${NODE_SCOPES:-compute-rw,monitoring,logging-write,storage-ro,https://www.googleapis.com/auth/ndev.clouddns.readwrite}" else diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index 3b14d0b29b0..1626459b289 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -92,7 +92,7 @@ ETCD_QUORUM_READ="${ENABLE_ETCD_QUORUM_READ:-false}" MASTER_TAG="${INSTANCE_PREFIX}-master" NODE_TAG="${INSTANCE_PREFIX}-minion" -CLUSTER_IP_RANGE="${CLUSTER_IP_RANGE:-10.244.0.0/14}" +CLUSTER_IP_RANGE="${CLUSTER_IP_RANGE:-$(get-cluster-ip-range)}" MASTER_IP_RANGE="${MASTER_IP_RANGE:-10.246.0.0/24}" if [[ "${FEDERATION:-}" == true ]]; then diff --git a/cluster/gce/config-test.sh b/cluster/gce/config-test.sh index 9fb8b84bc91..207e56141ba 100755 --- a/cluster/gce/config-test.sh +++ b/cluster/gce/config-test.sh @@ -93,7 +93,7 @@ ETCD_QUORUM_READ="${ENABLE_ETCD_QUORUM_READ:-false}" MASTER_TAG="${INSTANCE_PREFIX}-master" NODE_TAG="${INSTANCE_PREFIX}-minion" -CLUSTER_IP_RANGE="${CLUSTER_IP_RANGE:-10.100.0.0/14}" +CLUSTER_IP_RANGE="${CLUSTER_IP_RANGE:-$(get-cluster-ip-range)}" MASTER_IP_RANGE="${MASTER_IP_RANGE:-10.246.0.0/24}" # NODE_IP_RANGE is used when ENABLE_IP_ALIASES=true. It is the primary range in # the subnet and is the range used for node instance IPs. diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 9476873a927..6c1ab0f9c83 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -301,4 +301,8 @@ func AfterReadingAllFlags(t *TestContextType) { if len(t.Host) == 0 && len(t.KubeConfig) == 0 { t.Host = defaultHost } + // Reset the cluster IP range flag to CLUSTER_IP_RANGE env var, if defined. + if clusterIPRange := os.Getenv("CLUSTER_IP_RANGE"); clusterIPRange != "" { + t.CloudConfig.ClusterIPRange = clusterIPRange + } }