Skip to content

Commit 2ba0231

Browse files
committed
fix shellcheck failures of cluster/gce/upgrade-aliases.sh
1 parent 005eb53 commit 2ba0231

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

cluster/gce/upgrade-aliases.sh

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [[ "${KUBERNETES_PROVIDER:-gce}" != "gce" ]]; then
2626
exit 1
2727
fi
2828

29-
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
29+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
3030
source "${KUBE_ROOT}/hack/lib/util.sh"
3131
source "${KUBE_ROOT}/cluster/kube-util.sh"
3232

@@ -35,8 +35,9 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
3535
# Assumed vars:
3636
# PROJECT
3737
function get-k8s-node-routes-count() {
38-
local k8s_node_routes_count=$(gcloud compute routes list \
39-
--project=${PROJECT} --filter='description=k8s-node-route' \
38+
local k8s_node_routes_count
39+
k8s_node_routes_count=$(gcloud compute routes list \
40+
--project="${PROJECT}" --filter='description=k8s-node-route' \
4041
--format='value(name)' | wc -l)
4142
echo -n "${k8s_node_routes_count}"
4243
}
@@ -50,11 +51,12 @@ function get-k8s-node-routes-count() {
5051
# Vars set:
5152
# IP_ALIAS_SUBNETWORK
5253
function detect-k8s-subnetwork() {
53-
local subnetwork_url=$(gcloud compute instances describe \
54-
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \
54+
local subnetwork_url
55+
subnetwork_url=$(gcloud compute instances describe \
56+
"${KUBE_MASTER}" --project="${PROJECT}" --zone="${ZONE}" \
5557
--format='value(networkInterfaces[0].subnetwork)')
5658
if [[ -n ${subnetwork_url} ]]; then
57-
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/})
59+
IP_ALIAS_SUBNETWORK=${subnetwork_url##*/}
5860
fi
5961
}
6062

@@ -69,21 +71,24 @@ function detect-k8s-subnetwork() {
6971
function set-allow-subnet-cidr-routes-overlap() {
7072
local allow_subnet_cidr_routes_overlap
7173
allow_subnet_cidr_routes_overlap=$(gcloud compute networks subnets \
72-
describe ${IP_ALIAS_SUBNETWORK} --project=${PROJECT} --region=${REGION} \
74+
describe "${IP_ALIAS_SUBNETWORK}" --project="${PROJECT}" --region="${REGION}" \
7375
--format='value(allowSubnetCidrRoutesOverlap)')
7476
local allow_overlap=$1
75-
if [ ${allow_subnet_cidr_routes_overlap,,} = ${allow_overlap} ]; then
77+
if [ "${allow_subnet_cidr_routes_overlap,,}" = "${allow_overlap}" ]; then
7678
echo "Subnet ${IP_ALIAS_SUBNETWORK}'s allowSubnetCidrRoutesOverlap is already set as $1"
7779
return
7880
fi
7981

8082
echo "Setting subnet \"${IP_ALIAS_SUBNETWORK}\" allowSubnetCidrRoutesOverlap to $1"
81-
local fingerprint=$(gcloud compute networks subnets describe \
82-
${IP_ALIAS_SUBNETWORK} --project=${PROJECT} --region=${REGION} \
83+
local fingerprint
84+
fingerprint=$(gcloud compute networks subnets describe \
85+
"${IP_ALIAS_SUBNETWORK}" --project="${PROJECT}" --region="${REGION}" \
8386
--format='value(fingerprint)')
84-
local access_token=$(gcloud auth print-access-token)
87+
local access_token
88+
access_token=$(gcloud auth print-access-token)
8589
local request="{\"allowSubnetCidrRoutesOverlap\":$1, \"fingerprint\":\"${fingerprint}\"}"
86-
local subnetwork_url="${GCE_API_ENDPOINT}projects/${PROJECT}/regions/${REGION}/subnetworks/${IP_ALIAS_SUBNETWORK}"
90+
local subnetwork_url
91+
subnetwork_url="${GCE_API_ENDPOINT}projects/${PROJECT}/regions/${REGION}/subnetworks/${IP_ALIAS_SUBNETWORK}"
8792
until curl -s --header "Content-Type: application/json" --header "Authorization: Bearer ${access_token}" \
8893
-X PATCH -d "${request}" "${subnetwork_url}" --output /dev/null; do
8994
printf "."
@@ -100,7 +105,8 @@ function set-allow-subnet-cidr-routes-overlap() {
100105
# CLUSTER_IP_RANGE
101106
# SERVICE_CLUSTER_IP_RANGE
102107
function add-k8s-subnet-secondary-ranges() {
103-
local secondary_ranges=$(gcloud compute networks subnets describe "${IP_ALIAS_SUBNETWORK}" \
108+
local secondary_ranges
109+
secondary_ranges=$(gcloud compute networks subnets describe "${IP_ALIAS_SUBNETWORK}" \
104110
--project="${PROJECT}" --region="${REGION}" \
105111
--format='value(secondaryIpRanges)')
106112
if [[ "${secondary_ranges}" =~ "pods-default" && "${secondary_ranges}" =~ "services-default" ]]; then
@@ -109,8 +115,8 @@ function add-k8s-subnet-secondary-ranges() {
109115
fi
110116

111117
echo "Adding secondary ranges: pods-default (${CLUSTER_IP_RANGE}), services-default (${SERVICE_CLUSTER_IP_RANGE})"
112-
until gcloud compute networks subnets update ${IP_ALIAS_SUBNETWORK} \
113-
--project=${PROJECT} --region=${REGION} \
118+
until gcloud compute networks subnets update "${IP_ALIAS_SUBNETWORK}" \
119+
--project="${PROJECT}" --region="${REGION}" \
114120
--add-secondary-ranges="pods-default=${CLUSTER_IP_RANGE},services-default=${SERVICE_CLUSTER_IP_RANGE}"; do
115121
printf "."
116122
sleep 1
@@ -124,9 +130,12 @@ function add-k8s-subnet-secondary-ranges() {
124130
function delete-k8s-node-routes() {
125131
local -a routes
126132
local -r batch=200
127-
routes=( $(gcloud compute routes list \
128-
--project=${PROJECT} --filter='description=k8s-node-route' \
129-
--format='value(name)') )
133+
routes=()
134+
while IFS=$'\n' read -r route; do
135+
routes+=( "${route}" )
136+
done < <(gcloud compute routes list \
137+
--project="${PROJECT}" --filter='description=k8s-node-route' \
138+
--format='value(name)')
130139
while (( "${#routes[@]}" > 0 )); do
131140
echo Deleting k8s node routes "${routes[*]::${batch}}"
132141
gcloud compute routes delete --project "${PROJECT}" --quiet "${routes[@]::${batch}}"
@@ -145,7 +154,7 @@ fi
145154
echo "Found ${k8s_node_routes_count} K8s node routes. Proceeding to upgrade them to IP aliases based connectivity..."
146155

147156
detect-k8s-subnetwork
148-
if [ -z ${IP_ALIAS_SUBNETWORK} ]; then
157+
if [ -z "${IP_ALIAS_SUBNETWORK}" ]; then
149158
echo "No k8s cluster subnetwork found. Exiting..."
150159
exit 1
151160
fi
@@ -165,7 +174,7 @@ export ETCD_IMAGE=3.3.10-0
165174
export ETCD_VERSION=3.3.10
166175

167176
# Upgrade master with updated kube envs
168-
${KUBE_ROOT}/cluster/gce/upgrade.sh -M -l
177+
"${KUBE_ROOT}/cluster/gce/upgrade.sh" -M -l
169178

170179
delete-k8s-node-routes
171180
set-allow-subnet-cidr-routes-overlap false

hack/.shellcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
./cluster/gce/gci/flexvolume_node_setup.sh
1111
./cluster/gce/gci/health-monitor.sh
1212
./cluster/gce/gci/master-helper.sh
13-
./cluster/gce/upgrade-aliases.sh
1413
./cluster/gce/upgrade.sh
1514
./cluster/gce/util.sh
1615
./cluster/log-dump/log-dump.sh

0 commit comments

Comments
 (0)