diff --git a/.github/yamllint.config.yaml b/.github/yamllint.config.yaml index 8d131eda..e82fee5f 100644 --- a/.github/yamllint.config.yaml +++ b/.github/yamllint.config.yaml @@ -14,6 +14,4 @@ rules: brackets: min-spaces-inside: 0 max-spaces-inside: 0 - indentation: - spaces: 2 - indent-sequences: consistent + indentation: enable diff --git a/cluster/apps/monitoring/uptimerobot-heartbeat/cron-job.yaml b/cluster/apps/monitoring/uptimerobot-heartbeat/cron-job.yaml index 4ac54175..bf462beb 100644 --- a/cluster/apps/monitoring/uptimerobot-heartbeat/cron-job.yaml +++ b/cluster/apps/monitoring/uptimerobot-heartbeat/cron-job.yaml @@ -6,35 +6,37 @@ metadata: name: uptimerobot-heartbeat spec: schedule: "*/5 * * * *" - concurrencyPolicy: Forbid + concurrencyPolicy: "Forbid" + successfulJobsHistoryLimit: 3 + failedJobsHistoryLimit: 5 jobTemplate: spec: + backoffLimit: 3 + ttlSecondsAfterFinished: 300 template: - metadata: - annotations: - botkube.io/disable: "true" spec: restartPolicy: Never containers: - - name: uptimerobot-heartbeat - image: ghcr.io/k8s-at-home/kubectl:v1.22.2 - imagePullPolicy: IfNotPresent - envFrom: - - secretRef: - name: uptimerobot-heartbeat-url - command: - - "/bin/sh" - - "-ec" - - | - set -o nounset - set -o errexit - if [ -z "$UPTIMEROBOT_HEARTBEAT_URL" ]; then - printf "%s - Yikes - Missing UPTIMEROBOT_HEARTBEAT_URL environment variable" "$(date -u)" - exit 0 - fi - status_code=$(curl --connect-timeout 10 --max-time 30 -I -s -o /dev/null -w '%{http_code}' "$UPTIMEROBOT_HEARTBEAT_URL") - if [ "${status_code}" != "200" ]; then - printf "%s - Yikes - Heartbeat request failed, http code: %s" "$(date -u)" "$status_code" - exit 0 - fi - printf "%s - Success - Heartbeat request received and processed successfully" "$(date -u)" + - name: uptimerobot-heartbeat + image: ghcr.io/k8s-at-home/kubectl:v1.22.3 + envFrom: + - secretRef: + name: uptimerobot-heartbeat-url + command: + - "/bin/sh" + - "/app/uptimerobot-heartbeat.sh" + volumeMounts: + - name: uptimerobot-heartbeat + mountPath: /app/uptimerobot-heartbeat.sh + subPath: uptimerobot-heartbeat.sh + readOnly: true + volumes: + - name: uptimerobot-heartbeat + projected: + defaultMode: 0775 + sources: + - configMap: + name: uptimerobot-heartbeat + items: + - key: uptimerobot-heartbeat.sh + path: uptimerobot-heartbeat.sh diff --git a/cluster/apps/monitoring/uptimerobot-heartbeat/kustomization.yaml b/cluster/apps/monitoring/uptimerobot-heartbeat/kustomization.yaml index 48e164a4..da26f064 100644 --- a/cluster/apps/monitoring/uptimerobot-heartbeat/kustomization.yaml +++ b/cluster/apps/monitoring/uptimerobot-heartbeat/kustomization.yaml @@ -1,5 +1,15 @@ +--- apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: -- cron-job.yaml -- secret.enc.yaml + - cron-job.yaml + - secret.enc.yaml +namespace: monitoring +configMapGenerator: + - name: uptimerobot-heartbeat + files: + - uptimerobot-heartbeat.sh +generatorOptions: + disableNameSuffixHash: true + annotations: + kustomize.toolkit.fluxcd.io/substitute: disabled diff --git a/cluster/apps/monitoring/uptimerobot-heartbeat/uptimerobot-heartbeat.sh b/cluster/apps/monitoring/uptimerobot-heartbeat/uptimerobot-heartbeat.sh new file mode 100644 index 00000000..56e5d2b4 --- /dev/null +++ b/cluster/apps/monitoring/uptimerobot-heartbeat/uptimerobot-heartbeat.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -o nounset +set -o errexit + +if [ -z "$UPTIMEROBOT_HEARTBEAT_URL" ]; then + printf "%s - Yikes - Missing UPTIMEROBOT_HEARTBEAT_URL environment variable" "$(date -u)" + exit 0 +fi + +status_code=$(curl --connect-timeout 10 --max-time 30 -I -s -o /dev/null -w '%{http_code}' "$UPTIMEROBOT_HEARTBEAT_URL") +if [ "${status_code}" != "200" ]; then + printf "%s - Yikes - Heartbeat request failed, http code: %s" "$(date -u)" "$status_code" + exit 0 +fi + +printf "%s - Success - Heartbeat request received and processed successfully" "$(date -u)"