diff --git a/codacy/templates/fluentd/lifecycle-police-job.yaml b/codacy/templates/fluentd/lifecycle-police-job.yaml index 68e5167fc..eb32590bc 100644 --- a/codacy/templates/fluentd/lifecycle-police-job.yaml +++ b/codacy/templates/fluentd/lifecycle-police-job.yaml @@ -12,9 +12,9 @@ metadata: # Minio create bucket hook doesn't define any hook weight, # any positive value will ensure that the bucket is created before this "helm.sh/hook-weight": "10" - "helm.sh/hook-delete-policy": hook-succeeded + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded spec: - backoffLimit: 100 + backoffLimit: 3 template: metadata: name: "{{ .Release.Name }}" @@ -30,14 +30,26 @@ spec: value: "{{ .Values.global.minio.accessKey }}" - name: AWS_SECRET_ACCESS_KEY value: "{{ .Values.global.minio.secretKey }}" - command: ["aws"] + command: ["/bin/sh", "-c"] args: - - s3api - - put-bucket-lifecycle-configuration - - --bucket - - {{ .Values.fluentdoperator.bucketName }} - - --endpoint-url - - http://{{ .Values.global.minio.location }}:{{ .Values.global.minio.port }} - - --lifecycle-configuration - - '{"Rules":[{"Expiration":{"Days": {{ .Values.fluentdoperator.expirationDays }} },"ID":"Delete old logs","Status":"Enabled"}]}' + - | + ENDPOINT="http://{{ .Values.global.minio.location }}:{{ .Values.global.minio.port }}" + BUCKET="{{ .Values.fluentdoperator.bucketName }}" + LIFECYCLE='{"Rules":[{"Expiration":{"Days": {{ .Values.fluentdoperator.expirationDays }} },"ID":"Delete old logs","Status":"Enabled"}]}' + MAX_WAIT=600 + ELAPSED=0 + echo "Waiting for MinIO at ${ENDPOINT}..." + until aws s3 ls --endpoint-url "${ENDPOINT}" > /dev/null 2>&1; do + if [ "${ELAPSED}" -ge "${MAX_WAIT}" ]; then + echo "Timed out waiting for MinIO after ${MAX_WAIT}s" + exit 1 + fi + sleep 10 + ELAPSED=$((ELAPSED + 10)) + done + echo "MinIO is ready. Setting lifecycle configuration on bucket ${BUCKET}..." + aws s3api put-bucket-lifecycle-configuration \ + --bucket "${BUCKET}" \ + --endpoint-url "${ENDPOINT}" \ + --lifecycle-configuration "${LIFECYCLE}" {{ end }}