Skip to content

Commit 9c6e8a9

Browse files
committed
feat(redis): Stop go-templating redis init scripts
Signed-off-by: Oliver Gondža <ogondza@gmail.com>
1 parent 61e675b commit 9c6e8a9

16 files changed

Lines changed: 178 additions & 185 deletions

build/redis/haproxy_init.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
: "${ARGOCD_REDIS_SERVICE_NAME:?Variable ARGOCD_REDIS_SERVICE_NAME is required}"
2+
3+
HAPROXY_CONF=/data/haproxy.cfg
4+
cp /readonly/haproxy.cfg "$HAPROXY_CONF"
5+
6+
for loop in $(seq 1 10); do
7+
getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-0" && break
8+
echo "Waiting for service ${ARGOCD_REDIS_SERVICE_NAME}-announce-0 to be ready ($loop) ..." && sleep 1
9+
done
10+
ANNOUNCE_IP0=$(getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-0" | awk '{ print $1 }')
11+
if [ -z "$ANNOUNCE_IP0" ]; then
12+
echo "Could not resolve the announce ip for ${ARGOCD_REDIS_SERVICE_NAME}-announce-0"
13+
exit 1
14+
fi
15+
sed -i "s/REPLACE_ANNOUNCE0/$ANNOUNCE_IP0/" "$HAPROXY_CONF"
16+
17+
for loop in $(seq 1 10); do
18+
getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-1" && break
19+
echo "Waiting for service ${ARGOCD_REDIS_SERVICE_NAME}-announce-1 to be ready ($loop) ..." && sleep 1
20+
done
21+
ANNOUNCE_IP1=$(getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-1" | awk '{ print $1 }')
22+
if [ -z "$ANNOUNCE_IP1" ]; then
23+
echo "Could not resolve the announce ip for ${ARGOCD_REDIS_SERVICE_NAME}-announce-1"
24+
exit 1
25+
fi
26+
sed -i "s/REPLACE_ANNOUNCE1/$ANNOUNCE_IP1/" "$HAPROXY_CONF"
27+
28+
for loop in $(seq 1 10); do
29+
getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-2" && break
30+
echo "Waiting for service ${ARGOCD_REDIS_SERVICE_NAME}-announce-2 to be ready ($loop) ..." && sleep 1
31+
done
32+
ANNOUNCE_IP2=$(getent hosts "${ARGOCD_REDIS_SERVICE_NAME}-announce-2" | awk '{ print $1 }')
33+
if [ -z "$ANNOUNCE_IP2" ]; then
34+
echo "Could not resolve the announce ip for ${ARGOCD_REDIS_SERVICE_NAME}-announce-2"
35+
exit 1
36+
fi
37+
sed -i "s/REPLACE_ANNOUNCE2/$ANNOUNCE_IP2/" "$HAPROXY_CONF"
38+
39+
auth=$(cat /redis-initial-pass/admin.password)
40+
sed -i "s/replace-with-redis-auth/$auth/" "$HAPROXY_CONF"
41+

build/redis/haproxy_init.sh.tpl

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
echo "$(date) Start..."
2+
3+
: "${ARGOCD_REDIS_USE_TLS:?Variable ARGOCD_REDIS_USE_TLS is required}"
4+
: "${ARGOCD_REDIS_SERVICE_NAME:?Variable ARGOCD_REDIS_SERVICE_NAME is required}"
5+
26
HOSTNAME="$(cat /proc/sys/kernel/hostname)"
37
INDEX="${HOSTNAME##*-}"
4-
SENTINEL_PORT={{- if eq .UseTLS "false" -}}26379{{- else -}}0{{- end }}
58
MASTER=''
69
MASTER_GROUP="argocd"
710
QUORUM="2"
811
REDIS_CONF=/data/conf/redis.conf
9-
{{- if eq .UseTLS "false"}}
10-
REDIS_PORT=6379
11-
REDIS_TLS_PORT=
12-
{{- else}}
13-
REDIS_PORT=0
14-
REDIS_TLS_PORT=6379
15-
{{- end}}
12+
if [ "$ARGOCD_REDIS_USE_TLS" = "false" ]; then
13+
REDIS_PORT=6379
14+
REDIS_TLS_PORT=
15+
SENTINEL_PORT=26379
16+
SENTINEL_TLS_PORT=
17+
else
18+
REDIS_PORT=0
19+
REDIS_TLS_PORT=6379
20+
SENTINEL_PORT=0
21+
SENTINEL_TLS_PORT=26379
22+
fi
1623
SENTINEL_CONF=/data/conf/sentinel.conf
17-
SENTINEL_TLS_PORT={{- if eq .UseTLS "true" -}}26379{{- end }}
18-
SERVICE={{.ServiceName}}
19-
SENTINEL_TLS_REPLICATION_ENABLED={{.UseTLS}}
20-
REDIS_TLS_REPLICATION_ENABLED={{.UseTLS}}
24+
SERVICE=$ARGOCD_REDIS_SERVICE_NAME
25+
SENTINEL_TLS_REPLICATION_ENABLED=$ARGOCD_REDIS_USE_TLS
26+
REDIS_TLS_REPLICATION_ENABLED=$ARGOCD_REDIS_USE_TLS
2127
set -eu
2228

2329
sentinel_get_master() {
@@ -48,7 +54,7 @@ sentinel_get_master_retry() {
4854

4955
identify_master() {
5056
echo "Identifying redis master (get-master-addr-by-name).."
51-
echo " using sentinel ({{.ServiceName}}), sentinel group name (argocd)"
57+
echo " using sentinel (${ARGOCD_REDIS_SERVICE_NAME}), sentinel group name (argocd)"
5258
echo " $(date).."
5359
MASTER="$(sentinel_get_master_retry 3)"
5460
if [ -n "${MASTER}" ]; then

build/redis/redis_liveness.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
# Minimalistic sh strict-mode as there is no bash in redis container
3+
set -eu
4+
5+
response=$(redis-cli -a "${AUTH}" --no-auth-warning "$@" ping)
6+
if [ "$response" != "PONG" ] && [ "${response:0:7}" != "LOADING" ] ; then
7+
echo "$response"
8+
exit 1
9+
fi
10+
echo "response=$response"

build/redis/redis_liveness.sh.tpl

Lines changed: 0 additions & 16 deletions
This file was deleted.

build/redis/redis_readiness.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
# Minimalistic sh strict-mode as there is no bash in redis container
3+
set -eu
4+
5+
response=$(redis-cli -a "${AUTH}" --no-auth-warning "$@" ping)
6+
if [ "$response" != "PONG" ]; then
7+
echo "$response"
8+
exit 1
9+
fi
10+
echo "response=$response"

build/redis/redis_readiness.sh.tpl

Lines changed: 0 additions & 16 deletions
This file was deleted.

build/redis/sentinel_liveness.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
# Minimalistic sh strict-mode as there is no bash in redis container
3+
set -eu
4+
5+
response=$(redis-cli "$@" ping)
6+
if [ "$response" != "PONG" ]; then
7+
echo "$response"
8+
exit 1
9+
fi
10+
echo "response=$response"

build/redis/sentinel_liveness.sh.tpl

Lines changed: 0 additions & 15 deletions
This file was deleted.

controllers/argocd/configmap.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,20 +711,20 @@ func (r *ReconcileArgoCD) reconcileRedisConfiguration(cr *argoproj.ArgoCD, useTL
711711
if err := r.reconcileRedisHAConfigMap(cr, useTLSForRedis); err != nil {
712712
return err
713713
}
714-
if err := r.reconcileRedisHAHealthConfigMap(cr, useTLSForRedis); err != nil {
714+
if err := r.reconcileRedisHAHealthConfigMap(cr); err != nil {
715715
return err
716716
}
717717
return nil
718718
}
719719

720720
// reconcileRedisHAConfigMap will ensure that the Redis HA Health ConfigMap is present for the given ArgoCD.
721-
func (r *ReconcileArgoCD) reconcileRedisHAHealthConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
721+
func (r *ReconcileArgoCD) reconcileRedisHAHealthConfigMap(cr *argoproj.ArgoCD) error {
722722
ctx := context.TODO()
723723
cm := newConfigMapWithName(common.ArgoCDRedisHAHealthConfigMapName, cr)
724724
cm.Data = map[string]string{
725-
"redis_liveness.sh": getRedisLivenessScript(useTLSForRedis),
726-
"redis_readiness.sh": getRedisReadinessScript(useTLSForRedis),
727-
"sentinel_liveness.sh": getSentinelLivenessScript(useTLSForRedis),
725+
"redis_liveness.sh": getRedisLivenessScript(),
726+
"redis_readiness.sh": getRedisReadinessScript(),
727+
"sentinel_liveness.sh": getSentinelLivenessScript(),
728728
}
729729
existingCM := &corev1.ConfigMap{}
730730
exists, err := argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, existingCM)
@@ -779,7 +779,7 @@ func (r *ReconcileArgoCD) reconcileRedisHAConfigMap(cr *argoproj.ArgoCD, useTLSF
779779
desired.Data = map[string]string{
780780
"haproxy.cfg": getRedisHAProxyConfig(cr, useTLSForRedis),
781781
"haproxy_init.sh": getRedisHAProxyScript(cr),
782-
"init.sh": getRedisInitScript(cr, useTLSForRedis),
782+
"init.sh": getRedisInitScript(),
783783
"redis.conf": getRedisConf(useTLSForRedis),
784784
"sentinel.conf": getRedisSentinelConf(useTLSForRedis),
785785
}
@@ -854,7 +854,7 @@ func (r *ReconcileArgoCD) recreateRedisHAHealthConfigMap(cr *argoproj.ArgoCD, us
854854
return err
855855
}
856856
}
857-
return r.reconcileRedisHAHealthConfigMap(cr, useTLSForRedis)
857+
return r.reconcileRedisHAHealthConfigMap(cr)
858858
}
859859

860860
// reconcileSSHKnownHosts will ensure that the ArgoCD SSH Known Hosts ConfigMap is present.

0 commit comments

Comments
 (0)