61 lines
1.9 KiB
Bash
61 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# Methods library for private_gateway — sourced by install-private_gateway.sh
|
|
|
|
_kubectl() {
|
|
if command -v kubectl >/dev/null 2>&1; then
|
|
command kubectl "$@"
|
|
elif command -v k0s >/dev/null 2>&1; then
|
|
k0s kubectl "$@"
|
|
else
|
|
echo "ERROR: no kubectl or k0s binary found" >&2; exit 127
|
|
fi
|
|
}
|
|
|
|
_require_env() {
|
|
local var="$1"
|
|
if [ -z "${!var:-}" ]; then
|
|
echo "ERROR: required variable $var is not set" >&2; exit 1
|
|
fi
|
|
}
|
|
|
|
# --validate=false skips kubectl CLIENT-side schema validation only; the API
|
|
# server still validates on admission. Required because applying the Cilium
|
|
# CiliumLoadBalancerIPPool (cilium.io/v2) trips a client-side openapi fetch that
|
|
# 404s on k0s ("failed to download openapi"), which would abort the plan.
|
|
_plan_apply() {
|
|
local file="$1"
|
|
local path="$SCRIPT_DIR/manifests/${file}.yaml"
|
|
[ -f "$path" ] || { echo " [skip] $file.yaml not in manifests/"; return 0; }
|
|
_kubectl apply --validate=false -f "$path"
|
|
}
|
|
|
|
_plan_apply_skip() {
|
|
local file="$1"
|
|
local path="$SCRIPT_DIR/manifests/${file}.yaml"
|
|
[ -f "$path" ] || { echo " [skip] $file.yaml not in manifests/"; return 0; }
|
|
if _kubectl get -f "$path" >/dev/null 2>&1; then
|
|
echo " [skip] $file already exists in cluster"
|
|
return 0
|
|
fi
|
|
_kubectl apply --validate=false -f "$path"
|
|
}
|
|
|
|
_plan_delete() {
|
|
local file="$1"
|
|
local path="$SCRIPT_DIR/manifests/${file}.yaml"
|
|
[ -f "$path" ] || { echo " [skip] $file.yaml not in manifests/"; return 0; }
|
|
_kubectl delete -f "$path" --ignore-not-found
|
|
}
|
|
|
|
_method_health() {
|
|
local gw_status
|
|
gw_status=$(_kubectl get gateway "$PGW_NAME" \
|
|
--namespace "$PGW_NAMESPACE" \
|
|
-o jsonpath='{.status.conditions[?(@.type=="Programmed")].status}' 2>/dev/null || true)
|
|
if [ "$gw_status" = "True" ]; then
|
|
echo "HEALTHY: gateway/$PGW_NAME is Programmed"
|
|
else
|
|
echo "UNHEALTHY: gateway/$PGW_NAME not Programmed (status=${gw_status:-unknown})" >&2
|
|
exit 1
|
|
fi
|
|
}
|