-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathk8s-validate.sh
More file actions
49 lines (44 loc) · 1.06 KB
/
Copy pathk8s-validate.sh
File metadata and controls
49 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/lib/common.sh
source "$SCRIPT_DIR/lib/common.sh"
ACTION="${1:-validate}"
ROOT="$(repo_root)"
DOCKER_ROOT="$(docker_mount_path "$ROOT")"
OVERLAY="k8s/overlays/local"
run_kubectl() {
if have_command kubectl; then
(
cd "$ROOT"
kubectl "$@"
)
return
fi
docker run --rm -v "$DOCKER_ROOT:/workspace" -w /workspace bitnami/kubectl:1.34.1 kubectl "$@"
}
case "$ACTION" in
render)
run_kubectl kustomize "$OVERLAY" >/dev/null
log "Kubernetes manifests rendered successfully"
;;
validate)
rendered_file="$(mktemp)"
run_kubectl kustomize "$OVERLAY" >"$rendered_file"
grep -q "kind: Deployment" "$rendered_file"
grep -q "kind: Service" "$rendered_file"
grep -q "kind: Ingress" "$rendered_file"
rm -f "$rendered_file"
log "Kubernetes manifests rendered successfully"
;;
apply)
require_command kubectl
(
cd "$ROOT"
kubectl apply -k "$OVERLAY"
)
;;
*)
fail "Unsupported action: $ACTION"
;;
esac