forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubernetes-yaml.sh
More file actions
executable file
·90 lines (78 loc) · 2.16 KB
/
kubernetes-yaml.sh
File metadata and controls
executable file
·90 lines (78 loc) · 2.16 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
# kubernetes-yaml.sh
#
# SUMMARY
#
# Manages the Kubernetes distribution YAML configs.
# See usage function in the code or run without arguments.
cd "$(dirname "${BASH_SOURCE[0]}")/.."
CONFIGURATIONS_DIR="scripts/kubernetes-yaml"
generate() {
local RELEASE_NAME="$1"
local CHART="$2"
local VALUES_FILE="$3"
# Print header.
cat <<EOF
# This file is generated from the Helm Chart by "scripts/kubernetes-yaml.sh".
# You might want to use the Helm Chart, see "$CHART" or the
# documentation on our website at https://vector.dev/docs.
# If you copied this file into you local setup - feel free to change it however
# you please.
# If you want to create a PR to the Vector's Kubernetes config - please do not
# edit this file directly. Instead, apply your changes to the Helm Chart.
EOF
# Generate template.
# TODO: use app-version when https://github.com/helm/helm/issues/8670 is solved
helm template \
"$RELEASE_NAME" \
"$CHART" \
--namespace vector \
--create-namespace \
--values "$VALUES_FILE" \
--version master
}
update() {
for CONFIG_FILE in "$CONFIGURATIONS_DIR"/*/config.sh; do
VALUES_FILE="$(dirname "$CONFIG_FILE")/values.yaml"
(
# shellcheck disable=SC1090
source "$CONFIG_FILE"
generate "$RELEASE_NAME" "$CHART" "$VALUES_FILE" > "$TARGET_FILE"
)
done
}
check() {
for CONFIG_FILE in "$CONFIGURATIONS_DIR"/*/config.sh; do
VALUES_FILE="$(dirname "$CONFIG_FILE")/values.yaml"
(
# shellcheck disable=SC1090
source "$CONFIG_FILE"
GENERATED="$(generate "$RELEASE_NAME" "$CHART" "$VALUES_FILE")"
FILE="$(cat "$TARGET_FILE")"
if [[ "$GENERATED" != "$FILE" ]]; then
echo "Error: Kubernetes YAML config ($TARGET_FILE) does not match the generated version" >&2
exit 1
fi
)
done
}
usage() {
cat >&2 <<-EOF
Usage: $0 MODE
Modes:
check - compare the current file contents and the generated config and
exit with non-zero exit code if they don't match
update - update the file with the generated config
EOF
exit 1
}
MODE="${1:-}"
case "$MODE" in
update|check)
"$MODE"
;;
*)
usage
;;
esac