Merge pull request #77386 from SataQiu/fix-shellcheck-20190503

Fix shellcheck failures of cluster/gce/upgrade-aliases.sh
This commit is contained in:
Kubernetes Prow Robot 2019-05-10 21:30:24 -07:00 committed by GitHub
commit 1c18c3263a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -26,7 +26,7 @@ if [[ "${KUBERNETES_PROVIDER:-gce}" != "gce" ]]; then
exit 1 exit 1
fi fi
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
source "${KUBE_ROOT}/hack/lib/util.sh" source "${KUBE_ROOT}/hack/lib/util.sh"
source "${KUBE_ROOT}/cluster/kube-util.sh" source "${KUBE_ROOT}/cluster/kube-util.sh"
@ -35,8 +35,9 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
# Assumed vars: # Assumed vars:
# PROJECT # PROJECT
function get-k8s-node-routes-count() { function get-k8s-node-routes-count() {
local k8s_node_routes_count=$(gcloud compute routes list \ local k8s_node_routes_count
--project=${PROJECT} --filter='description=k8s-node-route' \ k8s_node_routes_count=$(gcloud compute routes list \
--project="${PROJECT}" --filter='description=k8s-node-route' \
--format='value(name)' | wc -l) --format='value(name)' | wc -l)
echo -n "${k8s_node_routes_count}" echo -n "${k8s_node_routes_count}"
} }
@ -50,11 +51,12 @@ function get-k8s-node-routes-count() {
# Vars set: # Vars set:
# IP_ALIAS_SUBNETWORK # IP_ALIAS_SUBNETWORK
function detect-k8s-subnetwork() { function detect-k8s-subnetwork() {
local subnetwork_url=$(gcloud compute instances describe \ local subnetwork_url
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \ subnetwork_url=$(gcloud compute instances describe \
"${KUBE_MASTER}" --project="${PROJECT}" --zone="${ZONE}" \
--format='value(networkInterfaces[0].subnetwork)') --format='value(networkInterfaces[0].subnetwork)')
if [[ -n ${subnetwork_url} ]]; then if [[ -n ${subnetwork_url} ]]; then
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/}) IP_ALIAS_SUBNETWORK=${subnetwork_url##*/}
fi fi
} }
@ -69,21 +71,24 @@ function detect-k8s-subnetwork() {
function set-allow-subnet-cidr-routes-overlap() { function set-allow-subnet-cidr-routes-overlap() {
local allow_subnet_cidr_routes_overlap local allow_subnet_cidr_routes_overlap
allow_subnet_cidr_routes_overlap=$(gcloud compute networks subnets \ 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)') --format='value(allowSubnetCidrRoutesOverlap)')
local allow_overlap=$1 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" echo "Subnet ${IP_ALIAS_SUBNETWORK}'s allowSubnetCidrRoutesOverlap is already set as $1"
return return
fi fi
echo "Setting subnet \"${IP_ALIAS_SUBNETWORK}\" allowSubnetCidrRoutesOverlap to $1" echo "Setting subnet \"${IP_ALIAS_SUBNETWORK}\" allowSubnetCidrRoutesOverlap to $1"
local fingerprint=$(gcloud compute networks subnets describe \ local fingerprint
${IP_ALIAS_SUBNETWORK} --project=${PROJECT} --region=${REGION} \ fingerprint=$(gcloud compute networks subnets describe \
"${IP_ALIAS_SUBNETWORK}" --project="${PROJECT}" --region="${REGION}" \
--format='value(fingerprint)') --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 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}" \ until curl -s --header "Content-Type: application/json" --header "Authorization: Bearer ${access_token}" \
-X PATCH -d "${request}" "${subnetwork_url}" --output /dev/null; do -X PATCH -d "${request}" "${subnetwork_url}" --output /dev/null; do
printf "." printf "."
@ -100,7 +105,8 @@ function set-allow-subnet-cidr-routes-overlap() {
# CLUSTER_IP_RANGE # CLUSTER_IP_RANGE
# SERVICE_CLUSTER_IP_RANGE # SERVICE_CLUSTER_IP_RANGE
function add-k8s-subnet-secondary-ranges() { 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}" \ --project="${PROJECT}" --region="${REGION}" \
--format='value(secondaryIpRanges)') --format='value(secondaryIpRanges)')
if [[ "${secondary_ranges}" =~ "pods-default" && "${secondary_ranges}" =~ "services-default" ]]; then if [[ "${secondary_ranges}" =~ "pods-default" && "${secondary_ranges}" =~ "services-default" ]]; then
@ -109,8 +115,8 @@ function add-k8s-subnet-secondary-ranges() {
fi fi
echo "Adding secondary ranges: pods-default (${CLUSTER_IP_RANGE}), services-default (${SERVICE_CLUSTER_IP_RANGE})" echo "Adding secondary ranges: pods-default (${CLUSTER_IP_RANGE}), services-default (${SERVICE_CLUSTER_IP_RANGE})"
until gcloud compute networks subnets update ${IP_ALIAS_SUBNETWORK} \ until gcloud compute networks subnets update "${IP_ALIAS_SUBNETWORK}" \
--project=${PROJECT} --region=${REGION} \ --project="${PROJECT}" --region="${REGION}" \
--add-secondary-ranges="pods-default=${CLUSTER_IP_RANGE},services-default=${SERVICE_CLUSTER_IP_RANGE}"; do --add-secondary-ranges="pods-default=${CLUSTER_IP_RANGE},services-default=${SERVICE_CLUSTER_IP_RANGE}"; do
printf "." printf "."
sleep 1 sleep 1
@ -124,9 +130,12 @@ function add-k8s-subnet-secondary-ranges() {
function delete-k8s-node-routes() { function delete-k8s-node-routes() {
local -a routes local -a routes
local -r batch=200 local -r batch=200
routes=( $(gcloud compute routes list \ routes=()
--project=${PROJECT} --filter='description=k8s-node-route' \ while IFS=$'\n' read -r route; do
--format='value(name)') ) routes+=( "${route}" )
done < <(gcloud compute routes list \
--project="${PROJECT}" --filter='description=k8s-node-route' \
--format='value(name)')
while (( "${#routes[@]}" > 0 )); do while (( "${#routes[@]}" > 0 )); do
echo Deleting k8s node routes "${routes[*]::${batch}}" echo Deleting k8s node routes "${routes[*]::${batch}}"
gcloud compute routes delete --project "${PROJECT}" --quiet "${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..." echo "Found ${k8s_node_routes_count} K8s node routes. Proceeding to upgrade them to IP aliases based connectivity..."
detect-k8s-subnetwork detect-k8s-subnetwork
if [ -z ${IP_ALIAS_SUBNETWORK} ]; then if [ -z "${IP_ALIAS_SUBNETWORK}" ]; then
echo "No k8s cluster subnetwork found. Exiting..." echo "No k8s cluster subnetwork found. Exiting..."
exit 1 exit 1
fi fi
@ -165,7 +174,7 @@ export ETCD_IMAGE=3.3.10-0
export ETCD_VERSION=3.3.10 export ETCD_VERSION=3.3.10
# Upgrade master with updated kube envs # 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 delete-k8s-node-routes
set-allow-subnet-cidr-routes-overlap false set-allow-subnet-cidr-routes-overlap false

View File

@ -10,7 +10,6 @@
./cluster/gce/gci/flexvolume_node_setup.sh ./cluster/gce/gci/flexvolume_node_setup.sh
./cluster/gce/gci/health-monitor.sh ./cluster/gce/gci/health-monitor.sh
./cluster/gce/gci/master-helper.sh ./cluster/gce/gci/master-helper.sh
./cluster/gce/upgrade-aliases.sh
./cluster/gce/upgrade.sh ./cluster/gce/upgrade.sh
./cluster/gce/util.sh ./cluster/gce/util.sh
./cluster/log-dump/log-dump.sh ./cluster/log-dump/log-dump.sh