Skip to content

Commit 00f38b8

Browse files
authored
fix(helmfile): add some idempotence to hooks (#1761)
* fix(helmfile): add some idempotence * Update prometheus-operator-crds.sh.j2
1 parent a2aa8e4 commit 00f38b8

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
#!/usr/bin/env bash
22

3-
wait_for_cilium_crds() {
4-
local crds=(
3+
set -euo pipefail
4+
5+
function wait_for_crds() {
6+
local -r crds=(
57
"ciliuml2announcementpolicies.cilium.io"
68
"ciliumbgppeeringpolicies.cilium.io"
79
"ciliumloadbalancerippools.cilium.io"
810
)
911

1012
for crd in "${crds[@]}"; do
1113
until kubectl get crd "$crd" &>/dev/null; do
14+
echo "Waiting for CRD '${crd}'..."
1215
sleep 5
1316
done
1417
done
1518
}
1619

17-
apply_cilium_config() {
18-
kubectl apply \
20+
function apply_config() {
21+
echo "Checking if Cilium config needs to be applied..."
22+
if kubectl diff \
1923
--namespace=kube-system \
20-
--server-side \
21-
--field-manager=kustomize-controller \
2224
--kustomize \
23-
"${KUBERNETES_DIR}/apps/kube-system/cilium/config"
25+
"${KUBERNETES_DIR}/apps/kube-system/cilium/config" &>/dev/null;
26+
then
27+
echo "Cilium config is up to date. Skipping..."
28+
else
29+
echo "Applying Cilium config..."
30+
kubectl apply \
31+
--namespace=kube-system \
32+
--server-side \
33+
--field-manager=kustomize-controller \
34+
--kustomize \
35+
"${KUBERNETES_DIR}/apps/kube-system/cilium/config"
36+
fi
2437
}
2538

26-
main() {
27-
wait_for_cilium_crds
28-
apply_cilium_config
39+
function main() {
40+
wait_for_crds
41+
apply_config
2942
}
3043

31-
main
44+
main "$@"
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
# renovate: datasource=github-releases depName=prometheus-operator/prometheus-operator
46
PROMETHEUS_OPERATOR_VERSION="v0.80.0"
57

6-
apply_prometheus_operator_crds() {
7-
local crds=(
8+
function apply_crds() {
9+
local -r crds=(
810
"alertmanagerconfigs"
911
"alertmanagers"
1012
"podmonitors"
@@ -18,15 +20,20 @@ apply_prometheus_operator_crds() {
1820
)
1921

2022
for crd in "${crds[@]}"; do
21-
kubectl apply \
22-
--server-side \
23-
--filename \
24-
"https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/${PROMETHEUS_OPERATOR_VERSION}/example/prometheus-operator-crd/monitoring.coreos.com_${crd}.yaml"
23+
if kubectl get crd "${crd}.monitoring.coreos.com" &>/dev/null; then
24+
echo "The CRD '${crd}' already exists. Skipping..."
25+
else
26+
echo "Applying CRD '${crd}'..."
27+
kubectl apply \
28+
--server-side \
29+
--filename \
30+
"https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/${PROMETHEUS_OPERATOR_VERSION}/example/prometheus-operator-crd/monitoring.coreos.com_${crd}.yaml"
31+
fi
2532
done
2633
}
2734

28-
main() {
29-
apply_prometheus_operator_crds
35+
function main() {
36+
apply_crds
3037
}
3138

32-
main
39+
main "$@"

0 commit comments

Comments
 (0)