Skip to content

Commit a35e410

Browse files
address code review comments
Signed-off-by: Rohit Yadav <[email protected]>
1 parent 8ffea92 commit a35e410

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

hack/cleanup-ag.sh renamed to hack/cleanup-affinity-groups.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ set -o errexit
2727
set -o nounset
2828
set -o pipefail
2929

30-
export DRY_RUN=false
31-
export VERBOSE=false
32-
export NAMESPACE=default
33-
export KUBECONFIG=$HOME/.kube/config
30+
# script params
31+
DRY_RUN=false
32+
VERBOSE=false
33+
# k8s params
34+
NAMESPACE=default
35+
KUBECONFIG=$HOME/.kube/config
36+
# cmk params
37+
CS_URL=
38+
CS_APIKEY=
39+
CS_SECRETKEY=
3440

3541
debug() {
3642
if [[ "$VERBOSE" == "true" ]]; then
@@ -39,7 +45,7 @@ debug() {
3945
}
4046

4147
_kubectl() {
42-
kubectl -n $NAMESPACE -o json $@
48+
KUBECONFIG=$KUBECONFIG kubectl -n $NAMESPACE -o json $@
4349
}
4450

4551
_cmk() {
@@ -51,27 +57,27 @@ get_affinity_groups() {
5157
}
5258

5359
get_cluster() {
54-
affinityGroup=$1
60+
local affinityGroup=$1
5561
_kubectl get cloudstackaffinitygroup $affinityGroup | jq -r '.metadata.labels."cluster.x-k8s.io/cluster-name"'
5662
}
5763

5864
get_cluster_credentials() {
59-
cluster=$1
65+
local cluster=$1
6066
_kubectl get cloudstackcluster $cluster | jq -r '.spec.failureDomains[].acsEndpoint.name' | uniq
6167
}
6268

6369
setup_acs_credentials() {
64-
credential=$1
65-
export CS_URL=$(_kubectl get secret $credential | jq -r '.data."api-url"' | base64 -D)
66-
export CS_APIKEY=$(_kubectl get secret $credential | jq -r '.data."api-key"' | base64 -D)
67-
export CS_SECRETKEY=$(_kubectl get secret $credential | jq -r '.data."secret-key"' | base64 -D)
70+
local credential=$1
71+
CS_URL=$(_kubectl get secret $credential | jq -r '.data."api-url"' | base64 -D)
72+
CS_APIKEY=$(_kubectl get secret $credential | jq -r '.data."api-key"' | base64 -D)
73+
CS_SECRETKEY=$(_kubectl get secret $credential | jq -r '.data."secret-key"' | base64 -D)
6874
debug "Using CloudStack Control Plane URL: $CS_URL and CloudStack Account: $(_cmk list users | jq -r '.user[] | .account + " and User: " + .username')"
6975
}
7076

7177
main() {
7278
for ag in $(get_affinity_groups); do
7379
echo "[info] Checking CloudStack Affinity Group: $ag"
74-
cluster=$(get_cluster $ag)
80+
local cluster=$(get_cluster $ag)
7581
for credential in $(get_cluster_credentials $cluster); do
7682
setup_acs_credentials $credential
7783
CS_AG_ID=$(_kubectl get cloudstackaffinitygroup $ag | jq -r '.spec.id')
@@ -112,13 +118,13 @@ help() {
112118
while getopts ":dkvh" option; do
113119
case $option in
114120
d)
115-
export DRY_RUN=true;;
121+
DRY_RUN=true;;
116122
k)
117-
export KUBECONFIG=$OPTARG;;
123+
KUBECONFIG=$OPTARG;;
118124
v)
119-
export VERBOSE=true;;
125+
VERBOSE=true;;
120126
n)
121-
export NAMESPACE=$OPTARG;;
127+
NAMESPACE=$OPTARG;;
122128
h)
123129
help
124130
exit;;

0 commit comments

Comments
 (0)