fix: uptimerobot heartbeat

This commit is contained in:
Toboshii Nakama
2021-11-18 00:01:05 -06:00
parent 91ca65903f
commit ce1ddac645
4 changed files with 58 additions and 31 deletions

View File

@@ -14,6 +14,4 @@ rules:
brackets:
min-spaces-inside: 0
max-spaces-inside: 0
indentation:
spaces: 2
indent-sequences: consistent
indentation: enable

View File

@@ -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

View File

@@ -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

View File

@@ -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)"