Skip to content

Commit e47b321

Browse files
synaretephlogistonjohn
authored andcommitted
tests: patch dns-operator when running over OpenShift
When running over OpenShift need to patch the CRD of dns-operator in order order to configure extra DNS entry for testing. Using 'jq' utility to simplify JSON parsing. See "DNS Operator in OpenShift Container Platform" in OpenShift's documentations for examples. Signed-off-by: Shachar Sharon <[email protected]>
1 parent bca416c commit e47b321

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"spec": {
3+
"nodePlacement": {},
4+
"servers": [
5+
{
6+
"forwardPlugin": {
7+
"upstreams": [
8+
"AD_SERVER_IP:53"
9+
]
10+
},
11+
"name": "samba-ad",
12+
"zones": [
13+
"domain1.sink.test"
14+
]
15+
}
16+
]
17+
}
18+
}

tests/test-deploy-ad-server.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ 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+
OPENSHIFT_DNS_SNIPPET="${BASE_DIR}/tests/files/openshift-dns-snippet.template"
910
KUBECTL_CMD=${KUBECTL_CMD:-kubectl}
11+
JQ_CMD=${JQ_CMD:-jq}
1012

1113
_error() {
1214
echo "$@"
1315
exit 1
1416
}
1517

18+
_require_command() {
19+
command -v "${1}" > /dev/null || _error "Can not find ${1}"
20+
}
21+
_require_command "${KUBECTL_CMD}"
22+
_require_command "${JQ_CMD}"
23+
24+
1625
echo "Creating ad server deployment..."
1726
ERROR_MSG=$(${KUBECTL_CMD} create -f "${DEPLOYMENT_YAML}" 2>&1 1>/dev/null)
1827
if [ $? -ne 0 ] ; then
@@ -65,12 +74,31 @@ echo
6574
[ $rc -eq 0 ] || _error "Error: samba ad did not become reachable"
6675

6776

68-
69-
AD_POD_IP=$(${KUBECTL_CMD} get pod -o jsonpath='{ .items[*].status.podIP }')
77+
AD_POD_IP=$(${KUBECTL_CMD} get pod -o json \
78+
| ${JQ_CMD} -c -M '.items[] | .metadata.name + " " + .status.podIP' \
79+
| grep samba-ad-server \
80+
| tr -d "\"" \
81+
| awk '{print $2}')
7082
[ $? -eq 0 ] || _error "Error getting ad server pod IP"
71-
7283
echo "AD pod IP: ${AD_POD_IP}"
7384

85+
# when running over OpenShift need to patch dns-operator
86+
${KUBECTL_CMD} get deployment dns-operator \
87+
-n openshift-dns-operator > /dev/null 2>&1
88+
OPENSHIFT_DNS="$?"
89+
if [ ${OPENSHIFT_DNS} -eq 0 ]; then
90+
PATCHFILE=$(mktemp).json
91+
sed -e "s/AD_SERVER_IP/${AD_POD_IP}/g" \
92+
${OPENSHIFT_DNS_SNIPPET} > "${PATCHFILE}"
93+
94+
${KUBECTL_CMD} patch dns.operator default \
95+
--type=merge --patch-file "${PATCHFILE}"
96+
97+
[ $? -eq 0 ] || _error "Failed patching dns-operator with $PATCHFILE"
98+
unlink "${PATCHFILE}"
99+
exit 0
100+
fi
101+
74102
TMPFILE=$(mktemp)
75103

76104
cat > "${TMPFILE}" <<EOF

0 commit comments

Comments
 (0)