titan-iac/services/logging/oneoffs/opensearch-dashboards-setup-job.yaml

88 lines
3.1 KiB
YAML
Raw Normal View History

2026-01-28 01:48:32 -03:00
# services/logging/oneoffs/opensearch-dashboards-setup-job.yaml
# One-off job for logging/opensearch-dashboards-setup-4.
# Purpose: opensearch dashboards setup 4 (see container args/env in this file).
# Run by setting spec.suspend to false, reconcile, then set it back to true.
# Safe to delete the finished Job/pod; it should not run continuously.
apiVersion: batch/v1
kind: Job
metadata:
2026-01-09 23:27:07 -03:00
name: opensearch-dashboards-setup-4
namespace: logging
spec:
2026-01-28 01:48:32 -03:00
suspend: true
backoffLimit: 3
ttlSecondsAfterFinished: 3600
template:
spec:
restartPolicy: OnFailure
nodeSelector:
node-role.kubernetes.io/worker: "true"
hardware: rpi5
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: hardware
operator: In
values:
- rpi5
containers:
- name: setup
image: alpine:3.20
command: ["/bin/sh", "-c"]
args:
- |
set -euo pipefail
apk add --no-cache curl >/dev/null
OSD_URL="http://opensearch-dashboards.logging.svc.cluster.local:5601"
for attempt in $(seq 1 60); do
code="$(curl -s -o /dev/null -w "%{http_code}" "${OSD_URL}/api/status" || true)"
if [ "${code}" = "200" ]; then
break
fi
sleep 5
done
if ! curl -s -o /dev/null -w "%{http_code}" "${OSD_URL}/api/status" | grep -q "200"; then
echo "OpenSearch Dashboards did not become ready in time" >&2
exit 1
fi
if [ ! -s /config/objects.ndjson ]; then
echo "Saved objects file not found at /config/objects.ndjson" >&2
exit 1
fi
2026-01-09 22:55:39 -03:00
import_code="$(curl -sS -o /tmp/import.json -w "%{http_code}" -X POST \
"${OSD_URL}/api/saved_objects/_import?overwrite=true" \
-H 'osd-xsrf: true' \
2026-01-09 22:55:39 -03:00
-F file=@/config/objects.ndjson)"
2026-01-09 22:55:39 -03:00
if [ "${import_code}" != "200" ]; then
echo "Saved object import failed with status ${import_code}:" >&2
cat /tmp/import.json >&2
exit 1
fi
settings_code="$(curl -sS -o /tmp/settings.json -w "%{http_code}" -X POST \
"${OSD_URL}/api/opensearch-dashboards/settings" \
-H 'Content-Type: application/json' \
-H 'osd-xsrf: true' \
2026-01-09 22:55:39 -03:00
-d '{"changes":{"defaultIndex":"kube-logs"}}')"
if [ "${settings_code}" != "200" ]; then
echo "Default index update failed with status ${settings_code}:" >&2
cat /tmp/settings.json >&2
exit 1
fi
volumeMounts:
- name: objects
mountPath: /config
readOnly: true
volumes:
- name: objects
configMap:
name: opensearch-dashboards-objects