Skip to content

Commit fc2b48d

Browse files
Merge branch 'main' into feat/add-envfrom
2 parents c65a444 + ed65764 commit fc2b48d

File tree

6 files changed

+93
-10
lines changed

6 files changed

+93
-10
lines changed

helm/oauth2-proxy/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: oauth2-proxy
2-
version: 7.4.3
2+
version: 7.5.2
33
apiVersion: v2
44
appVersion: 7.6.0
55
home: https://oauth2-proxy.github.io/oauth2-proxy/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
RETRY_INTERVAL=5 # Interval between retries in seconds
4+
elapsed=0 # Elapsed time
5+
6+
check_redis() {
7+
host=$1
8+
port=$2
9+
while [ $elapsed -lt $TOTAL_RETRY_TIME ]; do
10+
echo "Checking Redis at $host:$port... Elapsed time: ${elapsed}s"
11+
if nc -z -w1 $TIMEOUT $host $port > /dev/null 2>&1; then
12+
echo "Redis is up at $host:$port!"
13+
return 0
14+
else
15+
echo "Redis is down at $host:$port. Retrying in $RETRY_INTERVAL seconds."
16+
sleep $RETRY_INTERVAL
17+
elapsed=$((elapsed + RETRY_INTERVAL))
18+
fi
19+
done
20+
echo "Failed to connect to Redis at $host:$port after $TOTAL_RETRY_TIME seconds."
21+
return 1
22+
}
23+
24+
# For parsing and checking connections
25+
parse_and_check() {
26+
url=$1
27+
clean_url=${url#redis://}
28+
host=$(echo $clean_url | cut -d':' -f1)
29+
port=$(echo $clean_url | cut -d':' -f2)
30+
check_redis $host $port
31+
}
32+
33+
# Main
34+
if [ "$OAUTH2_PROXY_REDIS_USE_CLUSTER" = "true" ]; then
35+
echo "Checking Redis in cluster mode..."
36+
echo "$OAUTH2_PROXY_REDIS_CLUSTER_CONNECTION_URLS" | tr ',' '\n' | while read -r addr; do
37+
parse_and_check $addr || exit 1
38+
done
39+
elif [ "$OAUTH2_PROXY_REDIS_USE_SENTINEL" = "true" ]; then
40+
echo "Checking Redis in sentinel mode..."
41+
echo "$OAUTH2_PROXY_REDIS_SENTINEL_CONNECTION_URLS" | tr ',' '\n' | while read -r addr; do
42+
parse_and_check $addr || exit 1
43+
done
44+
elif [ -n "$OAUTH2_PROXY_REDIS_CONNECTION_URL" ]; then
45+
echo "Checking standalone Redis..."
46+
parse_and_check "$OAUTH2_PROXY_REDIS_CONNECTION_URL" || exit 1
47+
else
48+
echo "Redis configuration not specified."
49+
exit 1
50+
fi
51+
52+
echo "Redis check completed."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if and .Values.redis.enabled .Values.initContainers.waitForRedis.enabled }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
labels:
6+
app: {{ template "oauth2-proxy.name" . }}
7+
{{- include "oauth2-proxy.labels" . | indent 4 }}
8+
name: {{ template "oauth2-proxy.fullname" . }}-wait-for-redis
9+
namespace: {{ template "oauth2-proxy.namespace" $ }}
10+
data:
11+
check-redis.sh: |
12+
{{ .Files.Get "scripts/check-redis.sh" | indent 4 }}
13+
{{- end }}

helm/oauth2-proxy/templates/deployment.yaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,32 @@ spec:
6262
{{- if and .Values.redis.enabled .Values.initContainers.waitForRedis.enabled }}
6363
initContainers:
6464
- name: wait-for-redis
65-
image: "{{ .Values.initContainers.waitForRedis.image.repository }}:{{ include "kubectl.version" . }}"
65+
image: "{{ .Values.initContainers.waitForRedis.image.repository }}:{{ .Values.initContainers.waitForRedis.image.tag }}"
6666
imagePullPolicy: {{ .Values.initContainers.waitForRedis.image.pullPolicy }}
67-
args:
68-
- wait
69-
- pod/{{ include "oauth2-proxy.redis.fullname" . }}-master-0
70-
- --for=condition=ready
71-
- --timeout={{ .Values.initContainers.waitForRedis.timeout }}s
67+
command: ["/bin/sh", "-c", "/scripts/check-redis.sh"]
68+
env:
69+
- name: TOTAL_RETRY_TIME
70+
value: "{{ .Values.initContainers.waitForRedis.timeout }}"
71+
{{- if eq (default "" .Values.sessionStorage.redis.clientType) "standalone" }}
72+
- name: OAUTH2_PROXY_REDIS_CONNECTION_URL
73+
value: {{ include "oauth2-proxy.redis.StandaloneUrl" . }}
74+
{{- else if eq (default "" .Values.sessionStorage.redis.clientType) "cluster" }}
75+
- name: OAUTH2_PROXY_REDIS_CLUSTER_CONNECTION_URLS
76+
value: {{ .Values.sessionStorage.redis.cluster.connectionUrls }}
77+
{{- else if eq (default "" .Values.sessionStorage.redis.clientType) "sentinel" }}
78+
- name: OAUTH2_PROXY_REDIS_SENTINEL_CONNECTION_URLS
79+
value: {{ .Values.sessionStorage.redis.sentinel.connectionUrls }}
80+
{{- end }}
7281
{{- if .Values.initContainers.waitForRedis.securityContext.enabled }}
7382
{{- $securityContext := unset .Values.initContainers.waitForRedis.securityContext "enabled" }}
7483
securityContext:
7584
{{- toYaml $securityContext | nindent 10 }}
7685
{{- end }}
7786
resources:
7887
{{- toYaml .Values.initContainers.waitForRedis.resources | nindent 10 }}
88+
volumeMounts:
89+
- name: redis-script
90+
mountPath: /scripts
7991
{{- end }}
8092
{{- if .Values.terminationGracePeriodSeconds }}
8193
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
@@ -323,7 +335,12 @@ spec:
323335
secretName: {{ template "oauth2-proxy.fullname" . }}-accesslist
324336
{{- end }}
325337
{{- end }}
326-
338+
{{- if and .Values.redis.enabled .Values.initContainers.waitForRedis.enabled }}
339+
- name: redis-script
340+
configMap:
341+
name: {{ template "oauth2-proxy.fullname" . }}-wait-for-redis
342+
defaultMode: 0775
343+
{{- end }}
327344
{{- if or .Values.config.existingConfig .Values.config.configFile }}
328345
- configMap:
329346
defaultMode: 420

helm/oauth2-proxy/templates/servicemonitor.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ spec:
4444
{{- end }}
4545
{{- with .Values.metrics.serviceMonitor.tlsConfig }}
4646
tlsConfig:
47-
{{- toYaml .| nindent 4 }}
47+
{{- toYaml .| nindent 6 }}
4848
{{- end }}
4949
{{- with .Values.metrics.serviceMonitor.metricRelabelings }}
5050
metricRelabelings:

helm/oauth2-proxy/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ initContainers:
292292
waitForRedis:
293293
enabled: true
294294
image:
295-
repository: "docker.io/bitnami/kubectl"
295+
repository: "alpine"
296+
tag: "latest"
296297
pullPolicy: "IfNotPresent"
297298
# uses the kubernetes version of the cluster
298299
# the chart is deployed on, if not set

0 commit comments

Comments
 (0)