Skip to content

Commit f58f13c

Browse files
synareteanoopcs9
authored andcommitted
tests: allow passing KUBECTL_CMD to deploy AD script
On OpenShift deployments users may want to use 'oc' as their kubectl command. Allow passing alternative command via 'KUBECTL_CMD' variable (same as in top-level Makefile). Made also few cosmetics fixes to cleanup 'shellcheck' warns and align to shell-scripts coding conventions. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 8a707a8 commit f58f13c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/test-deploy-ad-server.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ BASE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
66
DEPLOYMENT_YAML="${BASE_DIR}/tests/files/samba-ad-server-deployment.yml"
77
DEPLOYMENT_NAME="samba-ad-server"
88
COREDNS_SNIPPET="${BASE_DIR}/tests/files/coredns-snippet.template"
9+
KUBECTL_CMD=${KUBECTL_CMD:-kubectl}
910

1011
_error() {
1112
echo "$@"
1213
exit 1
1314
}
1415

1516
echo "Creating ad server deployment..."
16-
ERROR_MSG=$(kubectl create -f "${DEPLOYMENT_YAML}" 2>&1 1>/dev/null)
17+
ERROR_MSG=$(${KUBECTL_CMD} create -f "${DEPLOYMENT_YAML}" 2>&1 1>/dev/null)
1718
if [ $? -ne 0 ] ; then
1819
if [[ "${ERROR_MSG}" =~ "AlreadyExists" ]] ; then
1920
echo "Deployment exists already. Continuing."
@@ -22,12 +23,13 @@ if [ $? -ne 0 ] ; then
2223
fi
2324
fi
2425

25-
kubectl get deployment
26+
${KUBECTL_CMD} get deployment
2627

27-
replicaset="$(kubectl describe deployment ${DEPLOYMENT_NAME} | grep -s "NewReplicaSet:" | awk '{ print $2 }')"
28+
replicaset="$(${KUBECTL_CMD} describe deployment ${DEPLOYMENT_NAME} | \
29+
grep -s "NewReplicaSet:" | awk '{ print $2 }')"
2830
[ $? -eq 0 ] || _error "Error getting replicaset"
2931

30-
podname="$(kubectl get pod | grep $replicaset | awk '{ print $1 }')"
32+
podname="$(${KUBECTL_CMD} get pod | grep "${replicaset}" | awk '{ print $1 }')"
3133
[ $? -eq 0 ] || _error "Error getting podname"
3234

3335
echo "Samba ad pod is $podname"
@@ -39,20 +41,23 @@ until [ $tries -ge 120 ] || echo $podstatus | grep -q 'Running'; do
3941
sleep 1
4042
echo -n "."
4143
tries=$(( tries + 1 ))
42-
podstatus="$(kubectl get pod $podname -o go-template='{{.status.phase}}')"
44+
podstatus="$(${KUBECTL_CMD} get pod "${podname}" \
45+
-o go-template='{{.status.phase}}')"
4346
done
4447
echo
45-
kubectl get pod
48+
${KUBECTL_CMD} get pod
4649
echo
47-
echo $podstatus | grep -q 'Running' || _error "Pod did not reach Running state"
50+
echo "${podstatus}" | grep -q 'Running' || \
51+
_error "Pod did not reach Running state"
4852

4953
echo "waiting for samba to become reachable"
5054
tries=0
5155
rc=1
5256
while [ $tries -lt 120 ] && [ $rc -ne 0 ]; do
5357
sleep 1
5458
tries=$(( tries + 1 ))
55-
kubectl exec "${podname}" -- smbclient -N -L 127.0.0.1 2>/dev/null 1>/dev/null
59+
${KUBECTL_CMD} exec "${podname}" -- \
60+
smbclient -N -L 127.0.0.1 2>/dev/null 1>/dev/null
5661
rc=$?
5762
echo -n "."
5863
done
@@ -61,7 +66,7 @@ echo
6166

6267

6368

64-
AD_POD_IP=$(kubectl get pod -o jsonpath='{ .items[*].status.podIP }')
69+
AD_POD_IP=$(${KUBECTL_CMD} get pod -o jsonpath='{ .items[*].status.podIP }')
6570
[ $? -eq 0 ] || _error "Error getting ad server pod IP"
6671

6772
echo "AD pod IP: ${AD_POD_IP}"
@@ -73,7 +78,7 @@ data:
7378
Corefile: |
7479
EOF
7580

76-
kubectl get cm -n kube-system coredns -o jsonpath='{ .data.Corefile }' \
81+
${KUBECTL_CMD} get cm -n kube-system coredns -o jsonpath='{ .data.Corefile }' \
7782
| sed -e 's/^/ /g' \
7883
>> "${TMPFILE}"
7984

@@ -83,11 +88,11 @@ echo >> "${TMPFILE}"
8388
FIRSTLINE="$(head -1 "${COREDNS_SNIPPET}")"
8489
LASTLINE=" }"
8590

86-
sed -i.backup -e "/$FIRSTLINE/,/$LASTLINE/d" ${TMPFILE}
91+
sed -i.backup -e "/$FIRSTLINE/,/$LASTLINE/d" "${TMPFILE}"
8792

8893
sed -e "s/AD_SERVER_IP/${AD_POD_IP}/" "${COREDNS_SNIPPET}" >> "${TMPFILE}"
8994

9095
echo >> "${TMPFILE}"
9196

92-
kubectl patch cm -n kube-system coredns -p "$(cat ${TMPFILE})"
97+
${KUBECTL_CMD} patch cm -n kube-system coredns -p "$(cat "${TMPFILE}")"
9398
[ $? -eq 0 ] || _error "Error patching coredns config map"

0 commit comments

Comments
 (0)