Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions codacy/templates/fluentd/lifecycle-police-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Nitpick: It is safer to quote the annotation value to ensure consistent parsing, especially when it contains special characters like commas.

Suggested change
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"

spec:
backoffLimit: 100
backoffLimit: 3
template:
metadata:
name: "{{ .Release.Name }}"
Expand All @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

Suggestion: The current check only verifies that the MinIO endpoint is reachable. Since the script's primary action is to configure a specific bucket, the wait loop should verify the bucket's existence to avoid a race condition where the service is up but the target bucket has not yet been initialized.

Suggested change
until aws s3 ls --endpoint-url "${ENDPOINT}" > /dev/null 2>&1; do
until aws s3 ls "s3://${BUCKET}" --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 }}