-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement helm chart test (#152)
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com> Co-authored-by: Nathan Klick <nathan@swirldslabs.com>
- Loading branch information
1 parent
2a18bb6
commit 9321e4c
Showing
6 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
EX_OK=0 | ||
EX_ERR=1 | ||
|
||
function get_pod_list() { | ||
local pattern=$1 | ||
local resp=$(kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}' | grep "${pattern}") | ||
echo "${resp}" | ||
} | ||
|
||
function test_node_total() { | ||
# set test expectations | ||
local expected_node_total=3 | ||
|
||
echo "-------------------------------------------------------------" | ||
echo "Checking total number of network node containers" | ||
echo "-------------------------------------------------------------" | ||
kubectl wait --for=condition=ready pod -l type=network-node --timeout=300s || return "${EX_ERR}" | ||
|
||
local resp="$(get_pod_list network-node)" | ||
local nodes=(${resp}) # convert into an array | ||
echo "Nodes: " "${nodes[@]}" | ||
local node_total=${#nodes[@]} | ||
|
||
echo "Total network node: ${node_total} (expected: ${expected_node_total})" | ||
echo "" | ||
|
||
# assert equal | ||
[ "${node_total}" = "${expected_node_total}" ] || return "${EX_ERR}" | ||
return "${EX_OK}" | ||
} | ||
|
||
function test_systemctl() { | ||
# test that systemctl status is ready in node containers | ||
local systemctl_all_nodes="${EX_ERR}" # by default set to error status | ||
|
||
echo "-------------------------------------------------------------" | ||
echo "Checking systemctl is running in all network node containers" | ||
echo "-------------------------------------------------------------" | ||
|
||
local resp="$(get_pod_list network-node)" | ||
local nodes=(${resp}) # convert into an array | ||
echo "Nodes: " "${nodes[@]}" | ||
for node in "${nodes[@]}" | ||
do | ||
local cmd="kubectl exec ${node} -c root-container -- systemctl status --no-pager" | ||
|
||
kubectl exec "${node}" -c root-container -- systemctl status --no-pager | ||
local status="$?" | ||
|
||
echo "'${cmd}' => ${status} (expected: 0)" | ||
|
||
if [ "${status}" != "${EX_OK}" ]; then | ||
systemctl_all_nodes="${EX_ERR}" | ||
break # break at first error | ||
fi | ||
|
||
systemctl_all_nodes="${EX_OK}" | ||
done | ||
|
||
# assert 0 | ||
[ "${systemctl_all_nodes}" = "${EX_OK}" ] || return "${EX_ERR}" | ||
|
||
return "${EX_OK}" | ||
} | ||
|
||
function run_tests() { | ||
local test_node_total_status | ||
local test_systemctl_status | ||
|
||
test_node_total | ||
local status="$?" | ||
[ "${status}" = "${EX_OK}" ] && test_node_total_status="PASS" || test_node_total_status="FAIL" | ||
|
||
test_systemctl | ||
local status="$?" | ||
[ "${status}" = "${EX_OK}" ] && test_systemctl_status="PASS" || test_systemctl_status="FAIL" | ||
|
||
echo "-------------------------------------------------------------" | ||
echo "Test results" | ||
echo "-------------------------------------------------------------" | ||
echo "test_node_total: ${test_node_total_status}" | ||
echo "test_systemctl: ${test_systemctl_status}" | ||
|
||
[ "${test_node_total_status}" = "PASS" ] && \ | ||
[ "${test_systemctl_status}" = "PASS" ] || return "${EX_ERR}" | ||
|
||
return "${EX_OK}" | ||
} | ||
|
||
run_tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: tester | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: tester-role | ||
rules: | ||
- apiGroups: [ "" ] | ||
resources: | ||
- pods | ||
- pods/log | ||
verbs: | ||
- get | ||
- list | ||
- apiGroups: [ "" ] | ||
resources: | ||
- pods/exec | ||
verbs: | ||
- create | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: tester-role-binding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: tester | ||
roleRef: | ||
kind: Role | ||
name: tester-role | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: tester-cfg | ||
data: | ||
test.sh: | | ||
{{- .Files.Get "configs/test.sh" | nindent 4 }} |
26 changes: 26 additions & 0 deletions
26
charts/hedera-network/templates/tests/test-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: "network-test" | ||
annotations: | ||
"helm.sh/hook": test | ||
spec: | ||
serviceAccountName: tester | ||
volumes: | ||
- name: test-cfg | ||
configMap: | ||
name: tester-cfg | ||
defaultMode: 0777 # we need the test files to be executable | ||
containers: | ||
- name: tester | ||
image: bitnami/kubectl:latest | ||
volumeMounts: | ||
- mountPath: /scripts/test.sh | ||
name: test-cfg | ||
subPath: test.sh | ||
command: | ||
- "/bin/bash" | ||
- "-c" | ||
- /scripts/test.sh | ||
#- "while true;do echo sleeping; sleep 10;done" | ||
restartPolicy: Never |