{{- if .Values.bucketweb.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "thanos.fullname" . }}-bucketweb
  labels: {{- include "thanos.labels" . | nindent 4 }}
    app.kubernetes.io/component: bucketweb
spec:
  replicas: {{ .Values.bucketweb.replicaCount }}
  strategy:
    type: {{ .Values.bucketweb.strategyType }}
    {{- if (eq "Recreate" .Values.bucketweb.strategyType) }}
    rollingUpdate: null
    {{- end }}
  selector:
    matchLabels: {{- include "thanos.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: bucketweb
  template:
    metadata:
      labels: {{- include "thanos.labels" . | nindent 8 }}
        app.kubernetes.io/component: bucketweb
      annotations:
        checksum/ojbstore-configuration: {{ include (print $.Template.BasePath "/objstore-secret.yaml") . | sha256sum }}
        {{- if .Values.bucketweb.podAnnotations }}
        {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.podAnnotations "context" $) | nindent 8 }}
        {{- end }}
    spec:
{{- include "thanos.imagePullSecrets" . | nindent 6 }}
      serviceAccount: {{ include "thanos.serviceaccount.name" (dict "component" "bucketweb" "context" $) }}
      {{- if .Values.bucketweb.affinity }}
      affinity: {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.bucketweb.nodeSelector }}
      nodeSelector: {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.bucketweb.tolerations }}
      tolerations: {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.bucketweb.priorityClassName }}
      priorityClassName: {{ .Values.bucketweb.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.bucketweb.securityContext.enabled }}
      securityContext:
        runAsUser: {{ .Values.bucketweb.securityContext.runAsUser }}
        fsGroup: {{ .Values.bucketweb.securityContext.fsGroup }}
      {{- end }}
      containers:
        - name: bucketweb
          image: {{ include "thanos.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          args:
            - tools
            - bucket
            - web
            - --http-address=0.0.0.0:8080
            - --log.level={{ .Values.bucketweb.logLevel }}
            - --objstore.config-file=/conf/objstore.yml
            {{- if .Values.bucketweb.refresh }}
            - --refresh={{ .Values.bucketweb.refresh }}
            {{- end }}
            {{- if .Values.bucketweb.timeout }}
            - --timeout={{ .Values.bucketweb.timeout }}
            {{- end }}
            {{- range .Values.bucketweb.extraFlags }}
            - {{ . }}
            {{- end }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          {{- if .Values.bucketweb.livenessProbe }}
          livenessProbe: {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.livenessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.bucketweb.readinessProbe }}
          readinessProbe: {{- include "thanos.tplValue" (dict "value" .Values.bucketweb.readinessProbe "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.bucketweb.resources }}
          resources: {{- toYaml .Values.bucketweb.resources | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: objstore-config
              mountPath: /conf
      volumes:
        - name: objstore-config
          secret:
            secretName: {{ include "thanos.objstoreSecretName" . }}
            {{- if .Values.existingObjstoreSecretItems }}
            items: {{- toYaml .Values.existingObjstoreSecretItems | nindent 14 }}
            {{- end }}
{{- end }}
