---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{ .Values.name }}"
  labels:
    app: "{{ .Values.name }}"
spec:
  selector:
    matchLabels:
      app: "{{ .Values.name }}"
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        app: "{{ .Values.name }}"
    spec:
      containers:
      - name: "{{ .Values.name }}"
        image: {{ .Values.deployment.image }}:{{ .Values.deployment.tag }}
        imagePullPolicy: Always
        ports:
        - containerPort: 5000
        {{- if .Values.deployment.resources }}
        resources:
          {{- if .Values.deployment.resources.requests }}
          requests:
            memory: {{ .Values.deployment.resources.requests.memory | default "50Mi" | quote }}
            cpu: {{ .Values.deployment.resources.requests.cpu | default "10m" | quote }}
          {{- else}}
          requests:
            memory: "50Mi"
            cpu: "10m"
          {{- end}}
          {{- if .Values.deployment.resources.limits }}
          limits:
            memory: {{ .Values.deployment.resources.limits.memory | default "1024Mi" | quote }}
            cpu: {{ .Values.deployment.resources.limits.cpu | default "1" | quote }}
          {{- else}}  
          limits:
            memory: "1024Mi"
            cpu: "1"
          {{- end }}
        {{- else }}
        resources:
          requests:
            memory: "50Mi"
            cpu: "10m"
          limits:
            memory: "1024Mi"
            cpu: "1"
        {{- end}} 
