Skip to content

Commit 3321b0d

Browse files
authored
Add script to update existing ingresses of custom domains (#2241)
* Add script to update existing ingresses of custom domains * Add script documentation
1 parent a6b3298 commit 3321b0d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
wikibase-local-ca.crt
2-
2+
*.bak

bin/update-ingress-service

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# This script automatically updates the service endpoint of any existing ingress
4+
# created by the Platform API with the label "wbstack-ingress-generation".
5+
#
6+
# Example of rerouting ingresses to the "anubis" service:
7+
# ./bin/update-ingress-service anubis
8+
9+
function usage() {
10+
echo "usage: $(basename $0) <service>"
11+
}
12+
13+
SERVICE=$1
14+
if [[ -z "${SERVICE}" ]]; then
15+
usage
16+
exit 1
17+
fi
18+
19+
INGRESSES=$(kubectl get ingress -l wbstack-ingress-generation -o json)
20+
21+
echo "$INGRESSES" > "wbstack-ingresses-$(date +%s).json.bak"
22+
23+
UPDATED_INGRESSES=$(echo "$INGRESSES" | jq '.items[].spec.rules[].http.paths[].backend.service.name="'$SERVICE'"')
24+
25+
kubectl diff -f <(echo "$UPDATED_INGRESSES")
26+
27+
read -p "Do you want to deploy these changes? (y/N): " CONFIRMATION
28+
if [[ ! $CONFIRMATION =~ ^[Yy]$ ]]; then
29+
echo "canceled"
30+
exit 1
31+
fi
32+
33+
kubectl apply -f <(echo "$UPDATED_INGRESSES")

0 commit comments

Comments
 (0)