{{- if and .Values.storegateway.enabled .Values.storegateway.grpc.server.tls.enabled (not .Values.storegateway.grpc.server.tls.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ printf "%s-store-grpc-server" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: storegateway
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if .Values.storegateway.grpc.server.tls.autoGenerated }}
  {{- $ca := genCA "thanos-store-grpc-server-ca" 365 }}
  {{- $hostname := printf "%s-store-grpc-server" (include "common.names.fullname" .) }}
  {{- $cert := genSignedCert $hostname nil (list $hostname) 365 $ca }}
  tls-cert: {{ $cert.Cert | b64enc | quote }}
  tls-key: {{ $cert.Key | b64enc | quote }}
  ca-cert: {{ $ca.Cert | b64enc | quote }}
  {{- else }}
  tls-cert: {{ .Values.storegateway.grpc.server.tls.cert | b64enc | quote }}
  tls-key: {{ .Values.storegateway.grpc.server.tls.key | b64enc | quote }}
  ca-cert : {{ .Values.storegateway.grpc.server.tls.ca | b64enc | quote }}
  {{- end }}
{{ end }}
