Skip to content

Commit

Permalink
changed testjob to cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
BaruchBilanski committed Mar 11, 2024
1 parent c639ab6 commit 787398b
Showing 1 changed file with 77 additions and 74 deletions.
151 changes: 77 additions & 74 deletions eks-anywhere-common/Testers/Aqua/aqua-testJob.yaml
Original file line number Diff line number Diff line change
@@ -1,87 +1,90 @@
apiVersion: batch/v1
kind: Job
kind: CronJob
metadata:
name: aqua-enforcer-tester
namespace: aqua
spec:
template:
schedule: "0 */12 * * *"
jobTemplate:
spec:
serviceAccountName: 'aqua-enforcer-sa'
containers:
- name: test-aqua-enforcer
image: 'alpine/k8s:1.26.2'
imagePullPolicy: Always
command:
- /bin/bash
args:
- '-c'
- >-
echo "Checking Aqua Enforcer";
sleep 5;
timeout_seconds=420;
retry_interval=30;
max_retry_attempts=10;
start_time=$(date +%s);
aqua_enforcer_pods=($(kubectl get pods -n aqua -l app=aqua-enforcer-ds --field-selector=status.phase==Running -o jsonpath="{.items[*].metadata.name}"));
for aqua_enforcer_pod in "${aqua_enforcer_pods[@]}"; do
while true; do
current_time=$(date +%s); elapsed_time=$((current_time - start_time));
if [ $elapsed_time -ge $timeout_seconds ]; then
echo "Error: Timeout reached while waiting for Aqua Enforcer pods to be ready.";
exit 1;
fi;
aqua_enforcer_pod_status=$(kubectl get pod $aqua_enforcer_pod -n aqua -o jsonpath="{.status.phase}");
if [[ $aqua_enforcer_pod_status != "Running" ]]; then
echo "LOG: Pod $aqua_enforcer_pod, $aqua_enforcer_pod_status";
sleep 15;
else
echo "LOG: Pod $aqua_enforcer_pod, Running";
break;
fi;
done;
done;
for aqua_enforcer_pod in "${aqua_enforcer_pods[@]}"; do
kubectl exec -n aqua $aqua_enforcer_pod -- /opt/aquasec/./slk status > /dev/null 2>&1;
status_command_exit_code=$?;
if [ $status_command_exit_code -eq 0 ]; then
echo "Aqua Enforcer pod $aqua_enforcer_pod is running and connected";
else
echo "Error: status command failed for pod $aqua_enforcer_pod.";
echo "Retrying for 5 minutes.";
start_time_retry=$(date +%s); retry_elapsed_time=0;
while [ $retry_elapsed_time -lt $((retry_interval * max_retry_attempts)) ]; do
kubectl exec -n aqua $aqua_enforcer_pod -- /opt/aquasec/./slk status > /dev/null 2>&1;
status_command_exit_code=$?;
if [ $status_command_exit_code -eq 0 ]; then
echo "status command executed successfully for pod $aqua_enforcer_pod.";
break;
template:
spec:
serviceAccountName: 'aqua-enforcer-sa'
containers:
- name: test-aqua-enforcer
image: 'alpine/k8s:1.26.2'
imagePullPolicy: Always
command:
- /bin/bash
args:
- '-c'
- >-
echo "Checking Aqua Enforcer";
sleep 5;
timeout_seconds=420;
retry_interval=30;
max_retry_attempts=10;
start_time=$(date +%s);
aqua_enforcer_pods=($(kubectl get pods -n aqua -l app=aqua-enforcer-ds --field-selector=status.phase==Running -o jsonpath="{.items[*].metadata.name}"));
for aqua_enforcer_pod in "${aqua_enforcer_pods[@]}"; do
while true; do
current_time=$(date +%s); elapsed_time=$((current_time - start_time));

if [ $elapsed_time -ge $timeout_seconds ]; then
echo "Error: Timeout reached while waiting for Aqua Enforcer pods to be ready.";
exit 1;
fi;

aqua_enforcer_pod_status=$(kubectl get pod $aqua_enforcer_pod -n aqua -o jsonpath="{.status.phase}");

if [[ $aqua_enforcer_pod_status != "Running" ]]; then
echo "LOG: Pod $aqua_enforcer_pod, $aqua_enforcer_pod_status";
sleep 15;
else
echo "Retry: status command failed. Retrying in 30 seconds.";
sleep $retry_interval;
retry_elapsed_time=$((retry_elapsed_time + retry_interval));
echo "LOG: Pod $aqua_enforcer_pod, Running";
break;
fi;
done;
if [ $status_command_exit_code -ne 0 ]; then
echo "Error: Retry limit reached. status command still not successful for pod $aqua_enforcer_pod.";
exit 1;
done;

for aqua_enforcer_pod in "${aqua_enforcer_pods[@]}"; do
kubectl exec -n aqua $aqua_enforcer_pod -- /opt/aquasec/./slk status > /dev/null 2>&1;
status_command_exit_code=$?;

if [ $status_command_exit_code -eq 0 ]; then
echo "Aqua Enforcer pod $aqua_enforcer_pod is running and connected";
else
echo "Error: status command failed for pod $aqua_enforcer_pod.";
echo "Retrying for 5 minutes.";

start_time_retry=$(date +%s); retry_elapsed_time=0;

while [ $retry_elapsed_time -lt $((retry_interval * max_retry_attempts)) ]; do
kubectl exec -n aqua $aqua_enforcer_pod -- /opt/aquasec/./slk status > /dev/null 2>&1;
status_command_exit_code=$?;

if [ $status_command_exit_code -eq 0 ]; then
echo "status command executed successfully for pod $aqua_enforcer_pod.";
break;
else
echo "Retry: status command failed. Retrying in 30 seconds.";
sleep $retry_interval;
retry_elapsed_time=$((retry_elapsed_time + retry_interval));
fi;
done;

if [ $status_command_exit_code -ne 0 ]; then
echo "Error: Retry limit reached. status command still not successful for pod $aqua_enforcer_pod.";
exit 1;
fi;
fi;
fi;
done;
echo "Job completed successfully for all Aqua Enforcer pods.";
exit 0;
restartPolicy: Never
backoffLimit: 1
done;

echo "Job completed successfully for all Aqua Enforcer pods.";
exit 0;
restartPolicy: Never
backoffLimit: 1

---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down

0 comments on commit 787398b

Please sign in to comment.