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

GCE: Fall back to network if subnet is unknown #51987

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/gce/container-linux/master-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function create-master-instance-internal() {
fi

local network=$(make-gcloud-network-argument \
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK}" \
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK:-}" \
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")

local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
Expand Down
2 changes: 1 addition & 1 deletion cluster/gce/gci/master-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function create-master-instance-internal() {
fi

local network=$(make-gcloud-network-argument \
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK}" \
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK:-}" \
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")

local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
Expand Down
1 change: 1 addition & 0 deletions cluster/gce/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function wait-for-master() {
function prepare-upgrade() {
kube::util::ensure-temp-dir
detect-project
detect-subnetworks
detect-node-names # sets INSTANCE_GROUPS
write-cluster-name
tars_from_version
Expand Down
72 changes: 48 additions & 24 deletions cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ function make-gcloud-network-argument() {
local alias_size="$7" # optional

local networkURL="projects/${network_project}/global/networks/${network}"
local subnetURL="projects/${network_project}/regions/${region}/subnetworks/${subnet}"
local subnetURL="projects/${network_project}/regions/${region}/subnetworks/${subnet:-}"

local ret=""

Expand All @@ -524,8 +524,12 @@ function make-gcloud-network-argument() {
ret="${ret},aliases=pods-default:${alias_size}"
ret="${ret} --no-can-ip-forward"
else
ret="${ret} --network ${networkURL}"
ret="${ret} --subnet ${subnetURL}"
if [[ -n ${subnet:-} ]]; then
ret="${ret} --subnet ${subnetURL}"
else
ret="${ret} --network ${networkURL}"
fi

ret="${ret} --can-ip-forward"
if [[ -n ${address:-} ]]; then
ret="${ret} --address ${address}"
Expand All @@ -547,6 +551,7 @@ function get-template-name-from-version() {
# $3: String of comma-separated metadata entries (must all be from a file).
function create-node-template() {
detect-project
detect-subnetworks
local template_name="$1"

# First, ensure the template doesn't exist.
Expand Down Expand Up @@ -595,7 +600,7 @@ function create-node-template() {
"${NETWORK_PROJECT}" \
"${REGION}" \
"${NETWORK}" \
"${SUBNETWORK}" \
"${SUBNETWORK:-}" \
"" \
"${ENABLE_IP_ALIASES:-}" \
"${IP_ALIAS_SIZE:-}")
Expand Down Expand Up @@ -715,6 +720,7 @@ function kube-up() {
detect-master
parse-master-env
create-subnetworks
detect-subnetworks
create-nodes
elif [[ ${KUBE_REPLICATE_EXISTING_MASTER:-} == "true" ]]; then
if [[ "${MASTER_OS_DISTRIBUTION}" != "gci" && "${MASTER_OS_DISTRIBUTION}" != "debian" && "${MASTER_OS_DISTRIBUTION}" != "ubuntu" ]]; then
Expand All @@ -731,6 +737,7 @@ function kube-up() {
check-existing
create-network
create-subnetworks
detect-subnetworks
write-cluster-name
create-autoscaler-config
create-master
Expand Down Expand Up @@ -815,23 +822,7 @@ function expand-default-subnetwork() {
--quiet
}


# Vars set:
# SUBNETWORK
function create-subnetworks() {
SUBNETWORK=$(gcloud beta compute networks subnets list \
--network=${NETWORK} \
--regions=${REGION} \
--project=${NETWORK_PROJECT} \
--limit=1 \
--format='value(name)' 2>/dev/null)

if [[ -z ${SUBNETWORK:-} ]]; then
echo "${color_red}Could not find subnetwork with region ${REGION}, network ${NETWORK}, and project ${NETWORK_PROJECT}"
exit 1
fi
echo "Found subnet for region ${REGION} in network ${NETWORK}: ${SUBNETWORK}"

case ${ENABLE_IP_ALIASES} in
true) echo "IP aliases are enabled. Creating subnetworks.";;
false)
Expand All @@ -848,9 +839,6 @@ function create-subnetworks() {
exit 1;;
esac

SUBNETWORK=${IP_ALIAS_SUBNETWORK}
echo "Using IP Alias subnet ${SUBNETWORK}"

# Look for the alias subnet, it must exist and have a secondary
# range configured.
local subnet=$(gcloud beta compute networks subnets describe \
Expand Down Expand Up @@ -888,6 +876,42 @@ function create-subnetworks() {
fi
}

# detect-subnetworks sets the SUBNETWORK var if not already set
# Assumed vars:
# NETWORK
# REGION
# NETWORK_PROJECT
#
# Optional vars:
# SUBNETWORK
# IP_ALIAS_SUBNETWORK
function detect-subnetworks() {
if [[ -n ${SUBNETWORK:-} ]]; then
echo "Using subnet ${SUBNETWORK}"
return 0
fi

if [[ -n ${IP_ALIAS_SUBNETWORK:-} ]]; then
SUBNETWORK=${IP_ALIAS_SUBNETWORK}
echo "Using IP Alias subnet ${SUBNETWORK}"
return 0
fi

SUBNETWORK=$(gcloud beta compute networks subnets list \
--network=${NETWORK} \
--regions=${REGION} \
--project=${NETWORK_PROJECT} \
--limit=1 \
--format='value(name)' 2>/dev/null)

if [[ -n ${SUBNETWORK:-} ]]; then
echo "Found subnet for region ${REGION} in network ${NETWORK}: ${SUBNETWORK}"
return 0
fi

echo "${color_red}Could not find subnetwork with region ${REGION}, network ${NETWORK}, and project ${NETWORK_PROJECT}"
}

function delete-firewall-rules() {
for fw in $@; do
if [[ -n $(gcloud compute firewall-rules --project "${NETWORK_PROJECT}" describe "${fw}" --format='value(name)' 2>/dev/null || true) ]]; then
Expand Down Expand Up @@ -1322,7 +1346,7 @@ function create-heapster-node() {
"${NETWORK_PROJECT}" \
"${REGION}" \
"${NETWORK}"
"${SUBNETWORK}" \
"${SUBNETWORK:-}" \
"" \
"${ENABLE_IP_ALIASES:-}" \
"${IP_ALIAS_SIZE:-}")
Expand Down