From 787398bff8675add2f5117d8ba2fe9620afd72af Mon Sep 17 00:00:00 2001 From: Baruch Bilanski Date: Mon, 11 Mar 2024 15:12:16 +0200 Subject: [PATCH] changed testjob to cronjob --- .../Testers/Aqua/aqua-testJob.yaml | 151 +++++++++--------- 1 file changed, 77 insertions(+), 74 deletions(-) diff --git a/eks-anywhere-common/Testers/Aqua/aqua-testJob.yaml b/eks-anywhere-common/Testers/Aqua/aqua-testJob.yaml index 4166fdd3..1b0bb176 100644 --- a/eks-anywhere-common/Testers/Aqua/aqua-testJob.yaml +++ b/eks-anywhere-common/Testers/Aqua/aqua-testJob.yaml @@ -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