forked from jotak/demo-mesh-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgentpl.sh
executable file
·97 lines (88 loc) · 3.3 KB
/
gentpl.sh
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
91
92
93
94
95
96
97
#!/usr/bin/env bash
if [[ "$#" -lt 1 || "$1" = "--help" ]]; then
echo "Syntax: gentpl.sh <service name> <other options>"
echo ""
exit
fi
FULL_NAME="$1"
# Split on first '-': https://www.linuxjournal.com/article/8919
# E.g. for FULL_NAME=ball-openj9 => BASE_NAME=ball, VM=openj9
BASE_NAME="${1%-*}"
VM="${1##*-}"
PULL_POLICY="Never"
DOMAIN=""
USER="jotak"
TAG="dev"
NAMESPACE="default"
VERSION="base"
VERSION_OVERRIDE=""
METRICS_ENABLED="0"
TRACING_ENABLED="0"
KAFKA_ADDRESS=""
INTERACTIVE_MODE="0"
LAST_ARG=""
for arg in "$@"
do
if [[ "$arg" = "--metrics" ]]; then
METRICS_ENABLED="1"
elif [[ "$arg" = "--tracing" ]]; then
TRACING_ENABLED="1"
elif [[ "$arg" = "--kafka" ]]; then
KAFKA_ADDRESS="messaging-kafka-bootstrap.kafka:9092"
elif [[ "$arg" = "--interactive" ]]; then
INTERACTIVE_MODE="1"
elif [[ "$LAST_ARG" = "-v" ]]; then
VERSION="$arg"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-vo" ]]; then
VERSION_OVERRIDE="$arg"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-pp" ]]; then
PULL_POLICY="$arg"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-d" ]]; then
DOMAIN="$arg/"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-t" ]]; then
TAG="$arg"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-u" ]]; then
USER="$arg"
LAST_ARG=""
elif [[ "$LAST_ARG" = "-n" ]]; then
NAMESPACE="$arg"
LAST_ARG=""
else
LAST_ARG="$arg"
fi
done
# Special case for AIs where base VERSION is actually "locals" or "visitors"
if [[ "$VERSION" = "base" && "$FULL_NAME" = "ai-hotspot" ]]; then
VERSION="locals"
elif [[ "$VERSION" = "base" && "$FULL_NAME" = "ai-openj9" ]]; then
VERSION="visitors"
fi
if [[ "$VERSION_OVERRIDE" = "" ]]; then
VERSION_OVERRIDE="$VERSION"
fi
IMAGE="${DOMAIN}${USER}/mesharena-$FULL_NAME:$TAG"
if [[ -f "./k8s/$BASE_NAME-$VERSION.yml" ]] ; then
cat "./k8s/$BASE_NAME-$VERSION.yml" \
| ./yq w - metadata.labels.version $VERSION_OVERRIDE \
| ./yq w - metadata.labels.vm $VM \
| ./yq w - metadata.name "$BASE_NAME-$VERSION_OVERRIDE" \
| ./yq w - spec.selector.matchLabels.version $VERSION_OVERRIDE \
| ./yq w - spec.selector.matchLabels.vm $VM \
| ./yq w - spec.template.metadata.labels.version $VERSION_OVERRIDE \
| ./yq w - spec.template.metadata.labels.vm $VM \
| ./yq w - spec.template.spec.containers[0].imagePullPolicy $PULL_POLICY \
| ./yq w - spec.template.spec.containers[0].image $IMAGE \
| ./yq w - spec.template.spec.containers[0].name $FULL_NAME \
| ( [ "$METRICS_ENABLED" = "1" ] && ./yq w - --tag '!!str' "spec.template.metadata.annotations.(prometheus.io/scrape)" "true" || cat ) \
| ./yq w - --tag '!!str' "spec.template.spec.containers[0].env.(name==METRICS_ENABLED).value" $METRICS_ENABLED \
| ./yq w - --tag '!!str' "spec.template.spec.containers[0].env.(name==TRACING_ENABLED).value" $TRACING_ENABLED \
| ./yq w - --tag '!!str' "spec.template.spec.containers[0].env.(name==INTERACTIVE_MODE).value" $INTERACTIVE_MODE \
| ( [ "$KAFKA_ADDRESS" != "" ] && ./yq w - --tag '!!str' "spec.template.spec.containers[0].env.(name==KAFKA_ADDRESS).value" $KAFKA_ADDRESS || cat ) \
| ./yq w - "spec.template.spec.containers[0].env.(name==JAEGER_SERVICE_NAME).value" $BASE_NAME.$NAMESPACE
echo "---"
fi