apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "guacamole.fullname" . }}-daemon
  labels:
    {{- include "guacamole.labels" . | nindent 4 }}
spec:
{{- if not .Values.guacd.autoscaling.enabled }}
  replicas: {{ .Values.guacd.replicaCount }}
{{- end }}
  selector:
    matchLabels:
      {{- include "guacamole.selectorLabels" . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.guacd.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
        {{- include "guacamole.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.guacd.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "guacamole.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.guacd.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Values.guacd.nameOverride }}
          securityContext:
            {{- toYaml .Values.guacd.securityContext | nindent 12 }}
          image: "{{ .Values.guacd.image.repository }}:{{ .Values.guacd.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.guacd.image.pullPolicy }}
          ports:
            - name: guacd
              containerPort: 4822
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: 4822
          readinessProbe:
            tcpSocket:
              port: 4822
          resources:
            {{- toYaml .Values.guacd.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
