-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Fix shellcheck failures of cluster/gce/upgrade-aliases.sh #77386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ if [[ "${KUBERNETES_PROVIDER:-gce}" != "gce" ]]; then | |
exit 1 | ||
fi | ||
|
||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. | ||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. | ||
source "${KUBE_ROOT}/hack/lib/util.sh" | ||
source "${KUBE_ROOT}/cluster/kube-util.sh" | ||
|
||
|
@@ -35,8 +35,9 @@ source "${KUBE_ROOT}/cluster/kube-util.sh" | |
# Assumed vars: | ||
# PROJECT | ||
function get-k8s-node-routes-count() { | ||
local k8s_node_routes_count=$(gcloud compute routes list \ | ||
--project=${PROJECT} --filter='description=k8s-node-route' \ | ||
local k8s_node_routes_count | ||
k8s_node_routes_count=$(gcloud compute routes list \ | ||
--project="${PROJECT}" --filter='description=k8s-node-route' \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change reason:
|
||
--format='value(name)' | wc -l) | ||
echo -n "${k8s_node_routes_count}" | ||
} | ||
|
@@ -50,11 +51,12 @@ function get-k8s-node-routes-count() { | |
# Vars set: | ||
# IP_ALIAS_SUBNETWORK | ||
function detect-k8s-subnetwork() { | ||
local subnetwork_url=$(gcloud compute instances describe \ | ||
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \ | ||
local subnetwork_url | ||
subnetwork_url=$(gcloud compute instances describe \ | ||
"${KUBE_MASTER}" --project="${PROJECT}" --zone="${ZONE}" \ | ||
--format='value(networkInterfaces[0].subnetwork)') | ||
if [[ -n ${subnetwork_url} ]]; then | ||
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/}) | ||
IP_ALIAS_SUBNETWORK=${subnetwork_url##*/} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change reason:
|
||
fi | ||
} | ||
|
||
|
@@ -69,21 +71,24 @@ function detect-k8s-subnetwork() { | |
function set-allow-subnet-cidr-routes-overlap() { | ||
local allow_subnet_cidr_routes_overlap | ||
allow_subnet_cidr_routes_overlap=$(gcloud compute networks subnets \ | ||
describe ${IP_ALIAS_SUBNETWORK} --project=${PROJECT} --region=${REGION} \ | ||
describe "${IP_ALIAS_SUBNETWORK}" --project="${PROJECT}" --region="${REGION}" \ | ||
--format='value(allowSubnetCidrRoutesOverlap)') | ||
local allow_overlap=$1 | ||
if [ ${allow_subnet_cidr_routes_overlap,,} = ${allow_overlap} ]; then | ||
if [ "${allow_subnet_cidr_routes_overlap,,}" = "${allow_overlap}" ]; then | ||
echo "Subnet ${IP_ALIAS_SUBNETWORK}'s allowSubnetCidrRoutesOverlap is already set as $1" | ||
return | ||
fi | ||
|
||
echo "Setting subnet \"${IP_ALIAS_SUBNETWORK}\" allowSubnetCidrRoutesOverlap to $1" | ||
local fingerprint=$(gcloud compute networks subnets describe \ | ||
${IP_ALIAS_SUBNETWORK} --project=${PROJECT} --region=${REGION} \ | ||
local fingerprint | ||
fingerprint=$(gcloud compute networks subnets describe \ | ||
"${IP_ALIAS_SUBNETWORK}" --project="${PROJECT}" --region="${REGION}" \ | ||
--format='value(fingerprint)') | ||
local access_token=$(gcloud auth print-access-token) | ||
local access_token | ||
access_token=$(gcloud auth print-access-token) | ||
local request="{\"allowSubnetCidrRoutesOverlap\":$1, \"fingerprint\":\"${fingerprint}\"}" | ||
local subnetwork_url="${GCE_API_ENDPOINT}projects/${PROJECT}/regions/${REGION}/subnetworks/${IP_ALIAS_SUBNETWORK}" | ||
local subnetwork_url | ||
subnetwork_url="${GCE_API_ENDPOINT}projects/${PROJECT}/regions/${REGION}/subnetworks/${IP_ALIAS_SUBNETWORK}" | ||
until curl -s --header "Content-Type: application/json" --header "Authorization: Bearer ${access_token}" \ | ||
-X PATCH -d "${request}" "${subnetwork_url}" --output /dev/null; do | ||
printf "." | ||
|
@@ -100,7 +105,8 @@ function set-allow-subnet-cidr-routes-overlap() { | |
# CLUSTER_IP_RANGE | ||
# SERVICE_CLUSTER_IP_RANGE | ||
function add-k8s-subnet-secondary-ranges() { | ||
local secondary_ranges=$(gcloud compute networks subnets describe "${IP_ALIAS_SUBNETWORK}" \ | ||
local secondary_ranges | ||
secondary_ranges=$(gcloud compute networks subnets describe "${IP_ALIAS_SUBNETWORK}" \ | ||
--project="${PROJECT}" --region="${REGION}" \ | ||
--format='value(secondaryIpRanges)') | ||
if [[ "${secondary_ranges}" =~ "pods-default" && "${secondary_ranges}" =~ "services-default" ]]; then | ||
|
@@ -109,8 +115,8 @@ function add-k8s-subnet-secondary-ranges() { | |
fi | ||
|
||
echo "Adding secondary ranges: pods-default (${CLUSTER_IP_RANGE}), services-default (${SERVICE_CLUSTER_IP_RANGE})" | ||
until gcloud compute networks subnets update ${IP_ALIAS_SUBNETWORK} \ | ||
--project=${PROJECT} --region=${REGION} \ | ||
until gcloud compute networks subnets update "${IP_ALIAS_SUBNETWORK}" \ | ||
--project="${PROJECT}" --region="${REGION}" \ | ||
--add-secondary-ranges="pods-default=${CLUSTER_IP_RANGE},services-default=${SERVICE_CLUSTER_IP_RANGE}"; do | ||
printf "." | ||
sleep 1 | ||
|
@@ -124,9 +130,12 @@ function add-k8s-subnet-secondary-ranges() { | |
function delete-k8s-node-routes() { | ||
local -a routes | ||
local -r batch=200 | ||
routes=( $(gcloud compute routes list \ | ||
--project=${PROJECT} --filter='description=k8s-node-route' \ | ||
--format='value(name)') ) | ||
routes=() | ||
while IFS=$'\n' read -r route; do | ||
routes+=( "${route}" ) | ||
done < <(gcloud compute routes list \ | ||
--project="${PROJECT}" --filter='description=k8s-node-route' \ | ||
--format='value(name)') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change reason:
|
||
while (( "${#routes[@]}" > 0 )); do | ||
echo Deleting k8s node routes "${routes[*]::${batch}}" | ||
gcloud compute routes delete --project "${PROJECT}" --quiet "${routes[@]::${batch}}" | ||
|
@@ -145,7 +154,7 @@ fi | |
echo "Found ${k8s_node_routes_count} K8s node routes. Proceeding to upgrade them to IP aliases based connectivity..." | ||
|
||
detect-k8s-subnetwork | ||
if [ -z ${IP_ALIAS_SUBNETWORK} ]; then | ||
if [ -z "${IP_ALIAS_SUBNETWORK}" ]; then | ||
echo "No k8s cluster subnetwork found. Exiting..." | ||
exit 1 | ||
fi | ||
|
@@ -165,7 +174,7 @@ export ETCD_IMAGE=3.3.10-0 | |
export ETCD_VERSION=3.3.10 | ||
|
||
# Upgrade master with updated kube envs | ||
${KUBE_ROOT}/cluster/gce/upgrade.sh -M -l | ||
"${KUBE_ROOT}/cluster/gce/upgrade.sh" -M -l | ||
|
||
delete-k8s-node-routes | ||
set-allow-subnet-cidr-routes-overlap false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change reason: