@@ -26,7 +26,7 @@ if [[ "${KUBERNETES_PROVIDER:-gce}" != "gce" ]]; then
26
26
exit 1
27
27
fi
28
28
29
- KUBE_ROOT=$( dirname " ${BASH_SOURCE} " ) /../..
29
+ KUBE_ROOT=$( dirname " ${BASH_SOURCE[0] } " ) /../..
30
30
source " ${KUBE_ROOT} /hack/lib/util.sh"
31
31
source " ${KUBE_ROOT} /cluster/kube-util.sh"
32
32
@@ -35,8 +35,9 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
35
35
# Assumed vars:
36
36
# PROJECT
37
37
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' \
40
41
--format=' value(name)' | wc -l)
41
42
echo -n " ${k8s_node_routes_count} "
42
43
}
@@ -50,11 +51,12 @@ function get-k8s-node-routes-count() {
50
51
# Vars set:
51
52
# IP_ALIAS_SUBNETWORK
52
53
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} " \
55
57
--format=' value(networkInterfaces[0].subnetwork)' )
56
58
if [[ -n ${subnetwork_url} ]]; then
57
- IP_ALIAS_SUBNETWORK=$( echo $ {subnetwork_url##*/ })
59
+ IP_ALIAS_SUBNETWORK=${subnetwork_url##*/ }
58
60
fi
59
61
}
60
62
@@ -69,21 +71,24 @@ function detect-k8s-subnetwork() {
69
71
function set-allow-subnet-cidr-routes-overlap() {
70
72
local allow_subnet_cidr_routes_overlap
71
73
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} " \
73
75
--format=' value(allowSubnetCidrRoutesOverlap)' )
74
76
local allow_overlap=$1
75
- if [ ${allow_subnet_cidr_routes_overlap,,} = ${allow_overlap} ]; then
77
+ if [ " ${allow_subnet_cidr_routes_overlap,,} " = " ${allow_overlap} " ]; then
76
78
echo " Subnet ${IP_ALIAS_SUBNETWORK} 's allowSubnetCidrRoutesOverlap is already set as $1 "
77
79
return
78
80
fi
79
81
80
82
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} " \
83
86
--format=' value(fingerprint)' )
84
- local access_token=$( gcloud auth print-access-token)
87
+ local access_token
88
+ access_token=$( gcloud auth print-access-token)
85
89
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} "
87
92
until curl -s --header " Content-Type: application/json" --header " Authorization: Bearer ${access_token} " \
88
93
-X PATCH -d " ${request} " " ${subnetwork_url} " --output /dev/null; do
89
94
printf " ."
@@ -100,7 +105,8 @@ function set-allow-subnet-cidr-routes-overlap() {
100
105
# CLUSTER_IP_RANGE
101
106
# SERVICE_CLUSTER_IP_RANGE
102
107
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} " \
104
110
--project=" ${PROJECT} " --region=" ${REGION} " \
105
111
--format=' value(secondaryIpRanges)' )
106
112
if [[ " ${secondary_ranges} " =~ " pods-default" && " ${secondary_ranges} " =~ " services-default" ]]; then
@@ -109,8 +115,8 @@ function add-k8s-subnet-secondary-ranges() {
109
115
fi
110
116
111
117
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} " \
114
120
--add-secondary-ranges=" pods-default=${CLUSTER_IP_RANGE} ,services-default=${SERVICE_CLUSTER_IP_RANGE} " ; do
115
121
printf " ."
116
122
sleep 1
@@ -124,9 +130,12 @@ function add-k8s-subnet-secondary-ranges() {
124
130
function delete-k8s-node-routes() {
125
131
local -a routes
126
132
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)' )
130
139
while (( "${# routes[@]} " > 0 )) ; do
131
140
echo Deleting k8s node routes " ${routes[*]:: ${batch} } "
132
141
gcloud compute routes delete --project " ${PROJECT} " --quiet " ${routes[@]:: ${batch} } "
145
154
echo " Found ${k8s_node_routes_count} K8s node routes. Proceeding to upgrade them to IP aliases based connectivity..."
146
155
147
156
detect-k8s-subnetwork
148
- if [ -z ${IP_ALIAS_SUBNETWORK} ]; then
157
+ if [ -z " ${IP_ALIAS_SUBNETWORK} " ]; then
149
158
echo " No k8s cluster subnetwork found. Exiting..."
150
159
exit 1
151
160
fi
@@ -165,7 +174,7 @@ export ETCD_IMAGE=3.3.10-0
165
174
export ETCD_VERSION=3.3.10
166
175
167
176
# Upgrade master with updated kube envs
168
- ${KUBE_ROOT} /cluster/gce/upgrade.sh -M -l
177
+ " ${KUBE_ROOT} /cluster/gce/upgrade.sh" -M -l
169
178
170
179
delete-k8s-node-routes
171
180
set-allow-subnet-cidr-routes-overlap false
0 commit comments