{{- $name := include "oauth2-proxy.name" .  -}}
{{- $fullName := include "oauth2-proxy.fullname" .  -}}
{{- $labels := include "oauth2-proxy.labels" . -}}
{{- with .Values.sessionStorage }}
{{- if and (eq .type "redis") (not .redis.existingSecret) (or .redis.password .redis.sentinel.password) }}
apiVersion: v1
kind: Secret
metadata:
  labels:
    app: {{ $name }}
    {{- $labels | indent 4 }}
  name: {{ $fullName }}-redis-access
  namespace: {{ template "oauth2-proxy.namespace" $ }}
type: Opaque
data:
  {{- if and .redis.password (not .redis.existingSecret) }}
  {{ .redis.passwordKey }}: {{ .redis.password | b64enc | quote }}
  {{- end }}
  {{- if and .redis.sentinel.password (not .redis.sentinel.existingSecret) (ne .redis.sentinel.passwordKey .redis.passwordKey) }}
  {{ .redis.sentinel.passwordKey }}: {{ .redis.sentinel.password | b64enc | quote }}
  {{- end }}
{{- end }}
{{- end }}
