Skip to content

Commit 5fb034a

Browse files
committed
Use IP_ALIAS_SIZE to calculate and update IP_ALIAS_SIZE. Error added when ip-alias is not enabled when IP_ALIAS_SIZE is not empty.
1 parent 3989ec6 commit 5fb034a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

cluster/gce/config-common.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ function get-cluster-ip-range {
9898
echo "${suggested_range}"
9999
}
100100

101+
# Calculate ip alias range based on max number of pods.
102+
# Let pow be the smallest integer which is bigger than log2($1 * 2).
103+
# (32 - pow) will be returned.
104+
#
105+
# $1: The number of max pods limitation.
106+
function get-alias-range-size() {
107+
for pow in {0..31}; do
108+
if (( 1 << $pow > $1 * 2 )); then
109+
echo $((32 - pow))
110+
return 0
111+
fi
112+
done
113+
}
101114
# NOTE: Avoid giving nodes empty scopes, because kubelet needs a service account
102115
# in order to initialize properly.
103116
NODE_SCOPES="${NODE_SCOPES:-monitoring,logging-write,storage-ro}"

cluster/gce/config-default.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}"
289289
ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false}
290290
NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator}
291291
if [ ${ENABLE_IP_ALIASES} = true ]; then
292-
# Size of ranges allocated to each node. Currently supports only /32 and /24.
293-
IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24}
292+
# Number of Pods that can run on this node.
293+
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110}
294+
# Size of ranges allocated to each node.
295+
IP_ALIAS_SIZE="/$(get-alias-range-size ${MAX_PODS_PER_NODE})"
294296
IP_ALIAS_SUBNETWORK=${KUBE_GCE_IP_ALIAS_SUBNETWORK:-${INSTANCE_PREFIX}-subnet-default}
295297
# If we're using custom network, use the subnet we already create for it as the one for ip-alias.
296298
# Note that this means SUBNETWORK would override KUBE_GCE_IP_ALIAS_SUBNETWORK in case of custom network.
@@ -305,8 +307,10 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
305307
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_IP_ALIASES"
306308
PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE"
307309
PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME"
308-
# Number of Pods that can run on this node.
309-
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110}
310+
elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then
311+
# Should not have MAX_PODS_PER_NODE set for route-based clusters.
312+
echo -e "${color_red}Cannot set MAX_PODS_PER_NODE for route-based projects for ${PROJECT}." >&2
313+
exit 1
310314
fi
311315

312316
# Enable GCE Alpha features.

cluster/gce/config-test.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}"
296296
ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false}
297297
NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator}
298298
if [ ${ENABLE_IP_ALIASES} = true ]; then
299-
# Size of ranges allocated to each node. gcloud current supports only /32 and /24.
300-
IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24}
299+
# Number of Pods that can run on this node.
300+
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110}
301+
# Size of ranges allocated to each node.
302+
IP_ALIAS_SIZE="/$(get-alias-range-size ${MAX_PODS_PER_NODE})"
301303
IP_ALIAS_SUBNETWORK=${KUBE_GCE_IP_ALIAS_SUBNETWORK:-${INSTANCE_PREFIX}-subnet-default}
302304
# If we're using custom network, use the subnet we already create for it as the one for ip-alias.
303305
# Note that this means SUBNETWORK would override KUBE_GCE_IP_ALIAS_SUBNETWORK in case of custom network.
@@ -312,8 +314,10 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then
312314
PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_IP_ALIASES"
313315
PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE"
314316
PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME"
315-
# Number of Pods that can run on this node.
316-
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110}
317+
elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then
318+
# Should not have MAX_PODS_PER_NODE set for route-based clusters.
319+
echo -e "${color_red}Cannot set MAX_PODS_PER_NODE for route-based projects for ${PROJECT}." >&2
320+
exit 1
317321
fi
318322

319323
# Enable GCE Alpha features.

0 commit comments

Comments
 (0)