apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "pcp-satellite-catalog-service.fullname" . }}
  labels:
    {{- include "pcp-satellite-catalog-service.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "pcp-satellite-catalog-service.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        {{- include "pcp-satellite-catalog-service.labels" . | nindent 8 }}
        {{- with .Values.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- with .Values.image.pullSecrets }}
      imagePullSecrets:
        {{- range . }}
        - name: {{ . }}
        {{- end }}
      {{- end }}
      containers:
        - name: {{ include "pcp-satellite-catalog-service.name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: {{ .Values.app.profile | quote }}
            - name: CONFIG_SERVER_URI
              value: {{ .Values.app.configServerUri | quote }}
            - name: SPRING_CLOUD_CONFIG_LABEL
              value: {{ .Values.app.configLabel | quote }}
            - name: CONFIG_SERVER_FAIL_FAST
              value: {{ .Values.app.configServerFailFast | quote }}
            {{- if .Values.app.adminClientUrl }}
            - name: SPRING_BOOT_ADMIN_CLIENT_URL
              value: {{ .Values.app.adminClientUrl | quote }}
            {{- end }}
            {{- $serviceBaseUrl := include "pcp-satellite-catalog-service.serviceBaseUrl" . }}
            {{- if $serviceBaseUrl }}
            - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_SERVICE_BASE_URL
              value: {{ $serviceBaseUrl | quote }}
            {{- end }}
            {{- if .Values.app.servicePath }}
            - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_SERVICE_PATH
              value: {{ .Values.app.servicePath | quote }}
            {{- end }}
            {{- $managementBaseUrl := include "pcp-satellite-catalog-service.managementBaseUrl" . }}
            {{- if $managementBaseUrl }}
            - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_MANAGEMENT_BASE_URL
              value: {{ $managementBaseUrl | quote }}
            {{- end }}
            {{- $healthUrl := include "pcp-satellite-catalog-service.healthUrl" . }}
            {{- if $healthUrl }}
            - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_HEALTH_URL
              value: {{ $healthUrl | quote }}
            {{- end }}
            {{- with .Values.extraEnv }}
            {{- toYaml . | nindent 12 }}
            {{- end }}
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: http
            initialDelaySeconds: 20
            periodSeconds: 15
            timeoutSeconds: 5
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: http
            initialDelaySeconds: 40
            periodSeconds: 20
            timeoutSeconds: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
