apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "novnc.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "novnc.name" . }}
    helm.sh/chart: {{ include "novnc.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "novnc.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "novnc.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        
    spec:
      replicas: 3
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 2        
          maxUnavailable: 0  
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        volumeMounts:
        - name: novnc-config
          mountPath: /etc/novnc
          readOnly: true
        envFrom:
        - configMapRef:
            name: {{ template "novnc.fullname" . }}-env
        ports:
        - name: http
          containerPort: 6080
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /
            port: http
        readinessProbe:
          httpGet:
            path: /
            port: http
        resources:
            {{- toYaml .Values.resources | nindent 12 }}
      - name: openvpn-client 
        image: "registry-intl.eu-central-1.aliyuncs.com/tuffigorapidex/openvpn-client:latest"
        imagePullPolicy: Always
        envFrom:
        - configMapRef:
            name: {{ template "novnc.fullname" . }}-openvpn-client
        securityContext:
          capabilities:
            add:
            - NET_ADMIN
        resources:
            {{- toYaml .Values.resourcesInit | nindent 12 }}
      initContainers:
      - name: wait-openpvn-api
        image: odise/busybox-curl
        command: ["/bin/sh"]
        args: ["-c", "/srv/bin/init.sh"]
        volumeMounts:
        - name: novnc-config-init
          mountPath: /srv/bin
          readOnly: true
        resources:
            {{- toYaml .Values.resourcesInit | nindent 12 }}
      imagePullSecrets:
      - name: {{ .Values.image.secret }}
      - name: {{ .Values.image.secretDocker }}
      volumes:       
      - name: novnc-config
        projected:
          defaultMode: 0644
          sources:
          - configMap:
              name: {{ template "novnc.fullname" . }}-conf
              items:
              - key: config.properties
                path: config.properties
      - name: novnc-config-init
        projected:
          defaultMode: 0777
          sources:
          - configMap:
              name: {{ template "novnc.fullname" . }}-conf
              items:
              - key: init.sh
                path: init.sh