Skip to content

Commit 0f70377

Browse files
Merge pull request #92 from bluebrown/feature/wait-for-redis
add init container to block until redis is ready
2 parents c9ffb3b + d573201 commit 0f70377

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

helm/oauth2-proxy/Chart.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: oauth2-proxy
2-
version: 6.14.0
2+
version: 6.15.0
33
apiVersion: v2
44
appVersion: 7.4.0
55
home: https://oauth2-proxy.github.io/oauth2-proxy/
@@ -32,3 +32,12 @@ maintainers:
3232
- name: pierluigilenoci
3333
3434
kubeVersion: ">=1.9.0-0"
35+
annotations:
36+
artifacthub.io/changes: |
37+
- kind: added
38+
description: optional init container to wait for redis subchart's master pod to be ready
39+
links:
40+
- name: Github Issue
41+
url: https://github.com/oauth2-proxy/manifests/issues/91
42+
- name: Github PR
43+
url: https://github.com/oauth2-proxy/manifests/pull/92

helm/oauth2-proxy/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Parameter | Description | Default
143143
`ingress.annotations` | Ingress annotations | `nil`
144144
`ingress.hosts` | Ingress accepted hostnames | `nil`
145145
`ingress.tls` | Ingress TLS configuration | `nil`
146+
`initContainers.waitForRedis.enabled` | if `redis.enabled` is true, use an init container to wait for the redis master pod to be ready. If `serviceAccount.enabled` is true, create additionally a role/binding to get, list and watch the redis master pod | `true`
147+
`initContainers.waitForRedis.kubectlVersion` | kubectl version to use for the init container | `printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor`
146148
`livenessProbe.enabled` | enable Kubernetes livenessProbe. Disable to use oauth2-proxy with Istio mTLS. See [Istio FAQ](https://istio.io/help/faq/security/#k8s-health-checks) | `true`
147149
`livenessProbe.initialDelaySeconds` | number of seconds | 0
148150
`livenessProbe.timeoutSeconds` | number of seconds | 1

helm/oauth2-proxy/templates/deployment.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ spec:
5757
hostnames:
5858
- {{ .Values.hostAlias.hostname }}
5959
{{- end }}
60+
initContainers:
61+
{{- if and .Values.redis.enabled .Values.initContainers.waitForRedis.enabled }}
62+
- name: wait-for-redis
63+
image: "docker.io/bitnami/kubectl:{{ default (printf "%s.%s" .Capabilities.KubeVersion.Major .Capabilities.KubeVersion.Minor) .Values.initContainers.waitForRedis.kubectlVersion }}"
64+
args:
65+
- wait
66+
- pod/{{ include "oauth2-proxy.redis.fullname" . }}-master-0
67+
- --for=condition=ready
68+
- --timeout=180s
69+
securityContext:
70+
allowPrivilegeEscalation: false
71+
readOnlyRootFilesystem: true
72+
runAsNonRoot: true
73+
runAsUser: 65534
74+
{{- end }}
6075
containers:
6176
- name: {{ .Chart.Name }}
6277
image: "{{ .Values.image.repository }}:v{{ include "oauth2-proxy.version" . }}"
Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{{- if or .Values.serviceAccount.enabled -}}
2+
{{- $fullName := include "oauth2-proxy.fullname" . -}}
3+
{{- $saName := include "oauth2-proxy.serviceAccountName" . -}}
4+
{{- $name := include "oauth2-proxy.name" . -}}
5+
{{- $namespace := include "oauth2-proxy.namespace" $ -}}
6+
{{- $labels := include "oauth2-proxy.labels" . -}}
7+
---
28
apiVersion: v1
39
kind: ServiceAccount
410
metadata:
@@ -7,9 +13,46 @@ metadata:
713
{{- toYaml . | nindent 4 }}
814
{{- end }}
915
labels:
10-
app: {{ template "oauth2-proxy.name" . }}
11-
{{- include "oauth2-proxy.labels" . | indent 4 }}
12-
name: {{ template "oauth2-proxy.serviceAccountName" . }}
13-
namespace: {{ template "oauth2-proxy.namespace" $ }}
16+
app: {{ $name }}
17+
{{- $labels | indent 4 }}
18+
name: {{ $saName }}
19+
namespace: {{ $namespace }}
1420
automountServiceAccountToken : {{ .Values.serviceAccount.automountServiceAccountToken }}
21+
{{- if and .Values.redis.enabled .Values.initContainers.waitForRedis.enabled }}
22+
---
23+
kind: Role
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
metadata:
26+
name: {{ $fullName }}-watch-redis
27+
labels:
28+
app: {{ $name }}
29+
{{- $labels | nindent 4 }}
30+
rules:
31+
- apiGroups:
32+
- ""
33+
resources:
34+
- pods
35+
resourceNames:
36+
- "{{ include "oauth2-proxy.redis.fullname" . }}-master-0"
37+
verbs:
38+
- get
39+
- list
40+
- watch
41+
---
42+
kind: RoleBinding
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
metadata:
45+
name: {{ $saName }}-watch-redis
46+
labels:
47+
app: {{ $name }}
48+
{{- $labels | nindent 4 }}
49+
subjects:
50+
- kind: ServiceAccount
51+
name: {{ $saName }}
52+
apiGroup: ""
53+
roleRef:
54+
kind: Role
55+
name: {{ $fullName }}-watch-redis
56+
apiGroup: ""
57+
{{- end -}}
1558
{{- end -}}

helm/oauth2-proxy/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ podSecurityContext: {}
266266
# whether to use http or https
267267
httpScheme: http
268268

269+
initContainers:
270+
# if the redis sub-chart is enabled, wait for it to be ready
271+
# before starting the proxy
272+
# creates a role binding to get, list, watch, the redis master pod
273+
# if service account is enabled
274+
waitForRedis:
275+
enabled: true
276+
# uses the kubernetes version of the cluster
277+
# the chart is deployed on, if not set
278+
kubectlVersion: ""
279+
269280
# Additionally authenticate against a htpasswd file. Entries must be created with "htpasswd -B" for bcrypt encryption.
270281
# Alternatively supply an existing secret which contains the required information.
271282
htpasswdFile:

0 commit comments

Comments
 (0)