feat(cluster): implement cloudflare-ddns cronjob in networking namespace
Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
7 files changed
+122
-12
No files matched your search
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
current_ipv4="$(curl -s https://ipv4.icanhazip.com/)"
|
||||
zone_id=$(curl -s -X GET \
|
||||
"https://api.cloudflare.com/client/v4/zones?name=${CLOUDFLARE_RECORD_NAME#*.}&status=active" \
|
||||
-H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
|
||||
-H "X-Auth-Key: ${CLOUDFLARE_APIKEY}" \
|
||||
-H "Content-Type: application/json" \
|
||||
| jq --raw-output ".result[0] | .id"
|
||||
)
|
||||
record_ipv4=$(curl -s -X GET \
|
||||
"https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records?name=${CLOUDFLARE_RECORD_NAME}&type=A" \
|
||||
-H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
|
||||
-H "X-Auth-Key: ${CLOUDFLARE_APIKEY}" \
|
||||
-H "Content-Type: application/json" \
|
||||
)
|
||||
old_ip4=$(echo "$record_ipv4" | jq --raw-output '.result[0] | .content')
|
||||
if [[ "${current_ipv4}" == "${old_ip4}" ]]; then
|
||||
printf "%s - IP Address '%s' has not changed" "$(date -u)" "${current_ipv4}"
|
||||
exit 0
|
||||
fi
|
||||
record_ipv4_identifier="$(echo "$record_ipv4" | jq --raw-output '.result[0] | .id')"
|
||||
update_ipv4=$(curl -s -X PUT \
|
||||
"https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${record_ipv4_identifier}" \
|
||||
-H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
|
||||
-H "X-Auth-Key: ${CLOUDFLARE_APIKEY}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"proxied\":true,\"name\":\"${CLOUDFLARE_RECORD_NAME}\",\"content\":\"${current_ipv4}\"}" \
|
||||
)
|
||||
if [[ "$(echo "$update_ipv4" | jq --raw-output '.success')" == "true" ]]; then
|
||||
printf "%s - Success - IP Address '%s' has been updated" "$(date -u)" "${current_ipv4}"
|
||||
exit 0
|
||||
else
|
||||
printf "%s - Yikes - Updating IP Address '%s' has failed" "$(date -u)" "${current_ipv4}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: cloudflare-ddns
|
||||
namespace: networking
|
||||
spec:
|
||||
schedule: "0 * * * *"
|
||||
concurrencyPolicy: "Forbid"
|
||||
successfulJobsHistoryLimit: 3
|
||||
failedJobsHistoryLimit: 5
|
||||
jobTemplate:
|
||||
spec:
|
||||
backoffLimit: 3
|
||||
ttlSecondsAfterFinished: 300
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: cloudflare-ddns
|
||||
image: ghcr.io/k8s-at-home/kubectl:v1.23.3
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: cloudflare-ddns
|
||||
command:
|
||||
- "/bin/bash"
|
||||
- "/app/cloudflare-ddns.sh"
|
||||
volumeMounts:
|
||||
- name: cloudflare-ddns
|
||||
mountPath: /app/cloudflare-ddns.sh
|
||||
subPath: cloudflare-ddns.sh
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: cloudflare-ddns
|
||||
projected:
|
||||
defaultMode: 0775
|
||||
sources:
|
||||
- configMap:
|
||||
name: cloudflare-ddns
|
||||
items:
|
||||
- key: cloudflare-ddns.sh
|
||||
path: cloudflare-ddns.sh
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- cron-job.yaml
|
||||
- secret.sops.yaml
|
||||
namespace: networking
|
||||
configMapGenerator:
|
||||
- name: cloudflare-ddns
|
||||
files:
|
||||
- cloudflare-ddns.sh
|
||||
generatorOptions:
|
||||
disableNameSuffixHash: true
|
||||
annotations:
|
||||
kustomize.toolkit.fluxcd.io/substitute: disabled
|
||||
@@ -1,4 +1,5 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- cloudflare-ddns
|
||||
- traefik
|
||||
Reference in new issue
Block a user