mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Fall back to network if subnet is unknown
This commit is contained in:
parent
7be29bd9b6
commit
2bea4f7dd1
@ -80,7 +80,7 @@ function create-master-instance-internal() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local network=$(make-gcloud-network-argument \
|
local network=$(make-gcloud-network-argument \
|
||||||
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK}" \
|
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK:-}" \
|
||||||
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")
|
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")
|
||||||
|
|
||||||
local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
|
local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
|
||||||
|
@ -89,7 +89,7 @@ function create-master-instance-internal() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local network=$(make-gcloud-network-argument \
|
local network=$(make-gcloud-network-argument \
|
||||||
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK}" \
|
"${NETWORK_PROJECT}" "${REGION}" "${NETWORK}" "${SUBNETWORK:-}" \
|
||||||
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")
|
"${address:-}" "${ENABLE_IP_ALIASES:-}" "${IP_ALIAS_SIZE:-}")
|
||||||
|
|
||||||
local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
|
local metadata="kube-env=${KUBE_TEMP}/master-kube-env.yaml"
|
||||||
|
@ -196,6 +196,7 @@ function wait-for-master() {
|
|||||||
function prepare-upgrade() {
|
function prepare-upgrade() {
|
||||||
kube::util::ensure-temp-dir
|
kube::util::ensure-temp-dir
|
||||||
detect-project
|
detect-project
|
||||||
|
detect-subnetworks
|
||||||
detect-node-names # sets INSTANCE_GROUPS
|
detect-node-names # sets INSTANCE_GROUPS
|
||||||
write-cluster-name
|
write-cluster-name
|
||||||
tars_from_version
|
tars_from_version
|
||||||
|
@ -511,7 +511,7 @@ function make-gcloud-network-argument() {
|
|||||||
local alias_size="$7" # optional
|
local alias_size="$7" # optional
|
||||||
|
|
||||||
local networkURL="projects/${network_project}/global/networks/${network}"
|
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=""
|
local ret=""
|
||||||
|
|
||||||
@ -524,8 +524,12 @@ function make-gcloud-network-argument() {
|
|||||||
ret="${ret},aliases=pods-default:${alias_size}"
|
ret="${ret},aliases=pods-default:${alias_size}"
|
||||||
ret="${ret} --no-can-ip-forward"
|
ret="${ret} --no-can-ip-forward"
|
||||||
else
|
else
|
||||||
ret="${ret} --network ${networkURL}"
|
if [[ -n ${subnet:-} ]]; then
|
||||||
ret="${ret} --subnet ${subnetURL}"
|
ret="${ret} --subnet ${subnetURL}"
|
||||||
|
else
|
||||||
|
ret="${ret} --network ${networkURL}"
|
||||||
|
fi
|
||||||
|
|
||||||
ret="${ret} --can-ip-forward"
|
ret="${ret} --can-ip-forward"
|
||||||
if [[ -n ${address:-} ]]; then
|
if [[ -n ${address:-} ]]; then
|
||||||
ret="${ret} --address ${address}"
|
ret="${ret} --address ${address}"
|
||||||
@ -547,6 +551,7 @@ function get-template-name-from-version() {
|
|||||||
# $3: String of comma-separated metadata entries (must all be from a file).
|
# $3: String of comma-separated metadata entries (must all be from a file).
|
||||||
function create-node-template() {
|
function create-node-template() {
|
||||||
detect-project
|
detect-project
|
||||||
|
detect-subnetworks
|
||||||
local template_name="$1"
|
local template_name="$1"
|
||||||
|
|
||||||
# First, ensure the template doesn't exist.
|
# First, ensure the template doesn't exist.
|
||||||
@ -595,7 +600,7 @@ function create-node-template() {
|
|||||||
"${NETWORK_PROJECT}" \
|
"${NETWORK_PROJECT}" \
|
||||||
"${REGION}" \
|
"${REGION}" \
|
||||||
"${NETWORK}" \
|
"${NETWORK}" \
|
||||||
"${SUBNETWORK}" \
|
"${SUBNETWORK:-}" \
|
||||||
"" \
|
"" \
|
||||||
"${ENABLE_IP_ALIASES:-}" \
|
"${ENABLE_IP_ALIASES:-}" \
|
||||||
"${IP_ALIAS_SIZE:-}")
|
"${IP_ALIAS_SIZE:-}")
|
||||||
@ -715,6 +720,7 @@ function kube-up() {
|
|||||||
detect-master
|
detect-master
|
||||||
parse-master-env
|
parse-master-env
|
||||||
create-subnetworks
|
create-subnetworks
|
||||||
|
detect-subnetworks
|
||||||
create-nodes
|
create-nodes
|
||||||
elif [[ ${KUBE_REPLICATE_EXISTING_MASTER:-} == "true" ]]; then
|
elif [[ ${KUBE_REPLICATE_EXISTING_MASTER:-} == "true" ]]; then
|
||||||
if [[ "${MASTER_OS_DISTRIBUTION}" != "gci" && "${MASTER_OS_DISTRIBUTION}" != "debian" && "${MASTER_OS_DISTRIBUTION}" != "ubuntu" ]]; then
|
if [[ "${MASTER_OS_DISTRIBUTION}" != "gci" && "${MASTER_OS_DISTRIBUTION}" != "debian" && "${MASTER_OS_DISTRIBUTION}" != "ubuntu" ]]; then
|
||||||
@ -731,6 +737,7 @@ function kube-up() {
|
|||||||
check-existing
|
check-existing
|
||||||
create-network
|
create-network
|
||||||
create-subnetworks
|
create-subnetworks
|
||||||
|
detect-subnetworks
|
||||||
write-cluster-name
|
write-cluster-name
|
||||||
create-autoscaler-config
|
create-autoscaler-config
|
||||||
create-master
|
create-master
|
||||||
@ -815,23 +822,7 @@ function expand-default-subnetwork() {
|
|||||||
--quiet
|
--quiet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Vars set:
|
|
||||||
# SUBNETWORK
|
|
||||||
function create-subnetworks() {
|
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
|
case ${ENABLE_IP_ALIASES} in
|
||||||
true) echo "IP aliases are enabled. Creating subnetworks.";;
|
true) echo "IP aliases are enabled. Creating subnetworks.";;
|
||||||
false)
|
false)
|
||||||
@ -848,9 +839,6 @@ function create-subnetworks() {
|
|||||||
exit 1;;
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
SUBNETWORK=${IP_ALIAS_SUBNETWORK}
|
|
||||||
echo "Using IP Alias subnet ${SUBNETWORK}"
|
|
||||||
|
|
||||||
# Look for the alias subnet, it must exist and have a secondary
|
# Look for the alias subnet, it must exist and have a secondary
|
||||||
# range configured.
|
# range configured.
|
||||||
local subnet=$(gcloud beta compute networks subnets describe \
|
local subnet=$(gcloud beta compute networks subnets describe \
|
||||||
@ -888,6 +876,42 @@ function create-subnetworks() {
|
|||||||
fi
|
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() {
|
function delete-firewall-rules() {
|
||||||
for fw in $@; do
|
for fw in $@; do
|
||||||
if [[ -n $(gcloud compute firewall-rules --project "${NETWORK_PROJECT}" describe "${fw}" --format='value(name)' 2>/dev/null || true) ]]; then
|
if [[ -n $(gcloud compute firewall-rules --project "${NETWORK_PROJECT}" describe "${fw}" --format='value(name)' 2>/dev/null || true) ]]; then
|
||||||
@ -1322,7 +1346,7 @@ function create-heapster-node() {
|
|||||||
"${NETWORK_PROJECT}" \
|
"${NETWORK_PROJECT}" \
|
||||||
"${REGION}" \
|
"${REGION}" \
|
||||||
"${NETWORK}"
|
"${NETWORK}"
|
||||||
"${SUBNETWORK}" \
|
"${SUBNETWORK:-}" \
|
||||||
"" \
|
"" \
|
||||||
"${ENABLE_IP_ALIASES:-}" \
|
"${ENABLE_IP_ALIASES:-}" \
|
||||||
"${IP_ALIAS_SIZE:-}")
|
"${IP_ALIAS_SIZE:-}")
|
||||||
|
Loading…
Reference in New Issue
Block a user