Skip to content

Commit

Permalink
ci: various gke script fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Kwiek <maciej@isovalent.com>
  • Loading branch information
nebril committed Jun 4, 2020
1 parent 11336de commit f5a7682
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/gke/delete-terminating-namespaces.sh
Expand Up @@ -32,6 +32,6 @@ for pair in $OBJECTS; do
#echo "Checking if $ns/$obj ($pair) is present in $NAMESPACES"
if ! $(echo "$NAMESPACES" | grep -q "$ns" - ) ; then
echo "Object $obj in $ns is a namespace orphan; deleting"
kubectl delete -n $ns $obj
kubectl delete -n $ns $obj --force --grace-period=0
fi
done
12 changes: 3 additions & 9 deletions test/gke/release-cluster.sh
Expand Up @@ -7,7 +7,7 @@ project="cilium-ci"
# this is only needs to be set as some of gcloud commands requires it,
# but as this script uses resource URIs clusters in all locations are
# going to be discovered and used
region="us-west2"
region="us-west1"

export KUBECONFIG="${script_dir}/gke-kubeconfig"
cluster_uri="$(cat "${script_dir}/cluster-uri")"
Expand All @@ -32,14 +32,8 @@ echo "deleting terminating namespaces"
./delete-terminating-namespaces.sh

set -e

echo "scaling ${cluster_uri} to 0"
node_pools=($(gcloud container node-pools list --project "${project}" --region "${region}" --cluster "${cluster_uri}" --uri))
if [ "${#node_pools[@]}" -ne 1 ] ; then
echo "expected 1 node pool, found ${#node_pools[@]}"
exit 1
fi

gcloud container clusters resize --project "${project}" --region "${region}" --node-pool "${node_pools[1]}" --num-nodes 0 --quiet "${cluster_uri}"
echo "scaling ${cluster_uri} to 0"
${script_dir}/resize-cluster.sh 0 ${cluster_uri}

rm -f "${script_dir}/cluster-uri" "${script_dir}/cluster-name" "${script_dir}/cluster-version"
42 changes: 42 additions & 0 deletions test/gke/resize-cluster.sh
@@ -0,0 +1,42 @@
#!/bin/bash

# Copyright 2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

set -o errexit
set -o pipefail
set -o nounset

# this script sets management cluster nodepool cnrm object nodecount and resizes the cluster via gcloud cli

if [ ! "$#" -eq 2 ] ; then
echo "$0 supports exactly 2 arguments - desired node count and cluster uri"
exit 1
fi

project="cilium-ci"
# this is only needs to be set as some of gcloud commands requires it,
# but as this script uses resource URIs clusters in all locations are
# going to be discovered and used
region="us-west1"

node_count=${1}
cluster_uri=${2}
cluster_name=${cluster_uri##*/}

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

export KUBECONFIG="${script_dir}/resize-kubeconfig"
gcloud container clusters get-credentials --project "${project}" --region "europe-west4" management-cluster-0

kubectl get containernodepools.container.cnrm.cloud.google.com ${cluster_name} -n test-clusters -o yaml | sed "s/nodeCount:.*$/nodeCount: ${node_count}/g" | kubectl replace -f -

gcloud container clusters get-credentials --project "${project}" --region "${region}" "${cluster_uri}"

node_pools=($(gcloud container node-pools list --project "${project}" --region "${region}" --cluster "${cluster_uri}" --format="value(name)"))
if [ "${#node_pools[@]}" -ne 1 ] ; then
echo "expected 1 node pool, found ${#node_pools[@]}"
exit 1
fi

gcloud container clusters resize --project "${project}" --region "${region}" --node-pool "${node_pools[0]}" --num-nodes ${node_count} --quiet "${cluster_uri}"
14 changes: 4 additions & 10 deletions test/gke/select-cluster.sh
Expand Up @@ -7,7 +7,7 @@ project="cilium-ci"
# this is only needs to be set as some of gcloud commands requires it,
# but as this script uses resource URIs clusters in all locations are
# going to be discovered and used
region="us-west2"
region="us-west1"

set -e

Expand All @@ -30,7 +30,7 @@ while [ $locked -ne 0 ]; do
kubectl annotate deployment lock lock=1
locked=$?
echo $locked
if [ -n "${BUILD_URL+x}" ] ; then
if [ -n "${BUILD_URL+x}" ] && [ $locked -eq 0 ] ; then
kubectl annotate deployment lock --overwrite "jenkins-build-url=${BUILD_URL}"
fi
set -e
Expand All @@ -48,14 +48,8 @@ kubectl create ns cilium || true
echo "deleting terminating namespaces"
${script_dir}/delete-terminating-namespaces.sh

echo "scaling $cluster to 2"
node_pools=($(gcloud container node-pools list --project "${project}" --region "${region}" --cluster "${cluster_uri}" --uri))
if [ "${#node_pools[@]}" -ne 1 ] ; then
echo "expected 1 node pool, found ${#node_pools[@]}"
exit 1
fi

gcloud container clusters resize --project "${project}" --region "${region}" --node-pool "${node_pools[1]}" --num-nodes 2 --quiet "${cluster_uri}"
echo "scaling ${cluster_uri} to 2"
${script_dir}/resize-cluster.sh 2 ${cluster_uri}

echo "labeling nodes"
index=1
Expand Down

0 comments on commit f5a7682

Please sign in to comment.