Make nodecontroller configure nodes' pod IP ranges

This commit is contained in:
Tomek Kulczynski
2015-02-24 13:32:44 +01:00
committed by CJ Cullen
parent db6586bdab
commit 290c7b94ef
13 changed files with 286 additions and 126 deletions

View File

@@ -37,48 +37,7 @@ MASTER_NAME="${INSTANCE_PREFIX}-master"
MASTER_TAG="${INSTANCE_PREFIX}-master"
MINION_TAG="${INSTANCE_PREFIX}-minion"
MASTER_IP_RANGE="${MASTER_IP_RANGE:-10.246.0.0/24}"
# Compute IP addresses for nodes.
function increment_ipv4 {
local ip_base=$1
local incr_amount=$2
local -a ip_components
local ip_regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
[[ $ip_base =~ $ip_regex ]]
ip_components=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}" "${BASH_REMATCH[4]}")
ip_dec=0
local comp
for comp in "${ip_components[@]}"; do
ip_dec=$((ip_dec<<8))
ip_dec=$((ip_dec + $comp))
done
ip_dec=$((ip_dec + $incr_amount))
ip_components=()
local i
for ((i=0; i < 4; i++)); do
comp=$((ip_dec & 0xFF))
ip_components+=($comp)
ip_dec=$((ip_dec>>8))
done
echo "${ip_components[3]}.${ip_components[2]}.${ip_components[1]}.${ip_components[0]}"
}
node_count="${NUM_MINIONS}"
next_node="${KUBE_GCE_CLUSTER_CLASS_B:-10.244}.0.0"
node_subnet_size=24
node_subnet_count=$((2 ** (32-$node_subnet_size)))
subnets=()
for ((node_num=0; node_num<node_count; node_num++)); do
subnets+=("$next_node"/"${node_subnet_size}")
next_node=$(increment_ipv4 $next_node $node_subnet_count)
done
CLUSTER_IP_RANGE="${KUBE_GCE_CLUSTER_CLASS_B:-10.244}.0.0/16"
MINION_IP_RANGES=($(eval echo "${subnets[@]}"))
MINION_SCOPES=("storage-ro" "compute-rw" "https://www.googleapis.com/auth/monitoring" "https://www.googleapis.com/auth/logging.write")
# Increase the sleep interval value if concerned about API rate limits. 3, in seconds, is the default.
POLL_SLEEP_INTERVAL=3

View File

@@ -37,7 +37,6 @@ MASTER_NAME="${INSTANCE_PREFIX}-master"
MASTER_TAG="${INSTANCE_PREFIX}-master"
MINION_TAG="${INSTANCE_PREFIX}-minion"
CLUSTER_IP_RANGE="${KUBE_GCE_CLUSTER_CLASS_B:-10.245}.0.0/16"
MINION_IP_RANGES=($(eval echo "${KUBE_GCE_CLUSTER_CLASS_B:-10.245}.{1..${NUM_MINIONS}}.0/24"))
MASTER_IP_RANGE="${MASTER_IP_RANGE:-10.246.0.0/24}"
MINION_SCOPES=("storage-ro" "compute-rw" "https://www.googleapis.com/auth/logging.write" "https://www.googleapis.com/auth/monitoring")
# Increase the sleep interval value if concerned about API rate limits. 3, in seconds, is the default.

View File

@@ -336,31 +336,6 @@ function create-firewall-rule {
done
}
# Robustly try to create a route.
# $1: The name of the route.
# $2: IP range.
function create-route {
detect-project
local attempt=0
while true; do
if ! gcloud compute routes create "$1" \
--project "${PROJECT}" \
--destination-range "$2" \
--network "${NETWORK}" \
--next-hop-instance "$1" \
--next-hop-instance-zone "${ZONE}"; then
if (( attempt > 5 )); then
echo -e "${color_red}Failed to create route $1 ${color_norm}"
exit 2
fi
echo -e "${color_yellow}Attempt $(($attempt+1)) failed to create route $1. Retrying.${color_norm}"
attempt=$(($attempt+1))
else
break
fi
done
}
# Robustly try to create an instance template.
# $1: The name of the instance template.
# $2: The scopes flag.
@@ -569,23 +544,6 @@ function kube-up {
# to gcloud's deficiency.
wait-for-minions-to-run
detect-minion-names
# Create the routes and set IP ranges to instance metadata, 5 instances at a time.
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
create-route "${MINION_NAMES[$i]}" "${MINION_IP_RANGES[$i]}" &
add-instance-metadata "${MINION_NAMES[$i]}" "node-ip-range=${MINION_IP_RANGES[$i]}" &
if [ $i -ne 0 ] && [ $((i%5)) -eq 0 ]; then
echo Waiting for a batch of routes at $i...
wait-for-jobs
fi
done
create-route "${MASTER_NAME}" "${MASTER_IP_RANGE}"
# Wait for last batch of jobs.
wait-for-jobs
detect-master
echo "Waiting for cluster initialization."