{{- $osSelector := printf "kubernetes.io/os" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.label }}
  labels:
    app: {{ .Values.label }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Values.label }}
  template:
    metadata:
      labels:
        app: {{ .Values.label }}
    spec:
      serviceAccountName: {{ template "localstack.serviceAccountName" . }}
      securityContext:
        runAsUser: 1000
        runAsGroup: 3000
        fsGroup: 2000
      nodeSelector:
        {{ $osSelector }}: "linux"
        {{- with .Values.nodeSelector }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
      containers:
        - name: {{ .Values.label }}
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - containerPort: {{ .Values.containerPort }}
          livenessProbe:
            exec:
              command:
                - curl 
                - http://localhost:{{ .Values.containerPort }}/health
            initialDelaySeconds: 15
            periodSeconds: 15
          env:
            - name: LOCALSTACK_EDGE_PORT
              value: {{ .Values.containerPort | quote }}
            - name: LOCALSTACK_SERVICES
              value: {{ .Values.services | quote }}
            - name: LOCALSTACK_DEFAULT_REGION
              value: {{ .Values.defaultRegion | quote }}
            - name: LOCALSTACK_START_WEB
              value: "0"
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
