mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #77386 from SataQiu/fix-shellcheck-20190503
Fix shellcheck failures of cluster/gce/upgrade-aliases.sh
This commit is contained in:
commit
1c18c3263a
@ -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' \
|
||||
--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##*/}
|
||||
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)')
|
||||
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
|
||||
|
@ -10,7 +10,6 @@
|
||||
./cluster/gce/gci/flexvolume_node_setup.sh
|
||||
./cluster/gce/gci/health-monitor.sh
|
||||
./cluster/gce/gci/master-helper.sh
|
||||
./cluster/gce/upgrade-aliases.sh
|
||||
./cluster/gce/upgrade.sh
|
||||
./cluster/gce/util.sh
|
||||
./cluster/log-dump/log-dump.sh
|
||||
|
Loading…
Reference in New Issue
Block a user