forked from kuberhealthy/kuberhealthy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes kuberhealthy#1120 Signed-off-by: Ugur Zongur <104643878+ugurzongur@users.noreply.github.com>
- Loading branch information
1 parent
b489fb6
commit 421bccf
Showing
15 changed files
with
459 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
|
||
# ========== Utility functions ========== | ||
function get_khjob_status_ok { | ||
kubectl get khjob -n $NS kh-test-job -ojsonpath='{.status.ok}' | ||
} | ||
|
||
function get_khstate_ok { | ||
kubectl get khstate -n $NS kh-test-job -ojsonpath='{.spec.OK}' | ||
} | ||
|
||
function job_phase { | ||
kubectl get khjob -n $NS kh-test-job -ojsonpath='{.spec.phase}' | ||
} | ||
|
||
function fail_test { | ||
# Print debug_information | ||
echo --- | ||
kubectl get khjob -n $NS kh-test-job -oyaml | ||
echo --- | ||
kubectl get khstate -n $NS kh-test-job -oyaml | ||
exit 1 | ||
} | ||
|
||
echo ========== Job E2E test - Job successful case ========== | ||
sed s/REPORT_FAILURE_VALUE/false/ .ci/khjob.yaml |kubectl apply -n $NS -f- | ||
|
||
if [ "$(get_khjob_status_ok)" != "" ]; then | ||
echo "There should not be any OK field initially"; fail_test | ||
fi | ||
|
||
if [ "$(job_phase)" != "Running" ]; then | ||
echo "Job should be in running phase"; fail_test | ||
fi | ||
|
||
# Wait until the field is available | ||
TIMEOUT=30 | ||
while [ "$(job_phase)" == "Running" ] && [ $TIMEOUT -gt 0 ]; do sleep 1; echo Job phase: $(job_phase), timeout: ${TIMEOUT}; let TIMEOUT-=1; done | ||
|
||
# Check the result | ||
if [ "$(get_khjob_status_ok)" != "true" ]; then | ||
echo "khjob status should have returned OK"; fail_test | ||
fi | ||
|
||
if [ "$(get_khstate_ok)" != "true" ]; then | ||
echo "khstate should have returned OK"; fail_test | ||
fi | ||
|
||
if [ "$(job_phase)" != "Completed" ]; then | ||
echo "Job phase should be Completed."; fail_test | ||
fi | ||
|
||
# Delete the job | ||
kubectl delete khjob -n $NS kh-test-job | ||
|
||
|
||
|
||
echo ========== Job E2E test - Job fail case ========== | ||
|
||
sed s/REPORT_FAILURE_VALUE/true/ .ci/khjob.yaml |kubectl apply -n $NS -f- | ||
|
||
if [ "$(get_khjob_status_ok)" != "" ]; then | ||
echo "There should not be any OK field initially"; fail_test | ||
fi | ||
|
||
if [ "$(job_phase)" != "Running" ]; then | ||
echo "Job should be in running phase"; fail_test | ||
fi | ||
|
||
# Wait until the field is available | ||
TIMEOUT=30 | ||
while [ "$(job_phase)" == "Running" ] && [ $TIMEOUT -gt 0 ]; do sleep 1; echo Job phase: $(job_phase), timeout: ${TIMEOUT}; let TIMEOUT-=1; done | ||
|
||
# Check the result | ||
if [ "$(get_khjob_status_ok)" != "false" ]; then | ||
echo "khjob status should have NOT returned OK"; fail_test | ||
fi | ||
|
||
if [ "$(get_khstate_ok)" != "false" ]; then | ||
echo "khstate should have NOT returned OK"; fail_test | ||
fi | ||
|
||
if [ "$(job_phase)" != "Completed" ]; then | ||
echo "Job phase should be Completed."; fail_test | ||
fi | ||
|
||
# Delete the job | ||
kubectl delete khjob -n $NS kh-test-job |
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,20 @@ | ||
apiVersion: comcast.github.io/v1 | ||
kind: KuberhealthyJob | ||
metadata: | ||
name: kh-test-job | ||
spec: | ||
timeout: 2m | ||
podSpec: | ||
containers: | ||
- env: | ||
- name: REPORT_FAILURE | ||
value: "REPORT_FAILURE_VALUE" | ||
- name: REPORT_DELAY | ||
value: 5s | ||
image: kuberhealthy/test-check:latest | ||
imagePullPolicy: Always | ||
name: main | ||
resources: | ||
requests: | ||
cpu: 10m | ||
memory: 50Mi |
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
Oops, something went wrong.