apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: {{.Values.runlabel}}
  name: appserver-deployment
spec:
  template:
     metadata:
        name: {{.Values.deployment.name}}
        labels:
          run: {{.Values.runlabel}}
     spec:
        containers:
          - image: {{.Values.deployment.appimage}}
            imagePullPolicy: IfNotPresent
            name: {{.Values.deployment.appimagename}}
          - image: {{.Values.deployment.dpgimage}}
            imagePullPolicy: IfNotPresent
            name: {{.Values.deployment.dpgimagename}}
            readinessProbe:
              httpGet:
                path: /healthz
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 10
              periodSeconds: 5
            livenessProbe:
              httpGet:
                path: /liveness
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 10
              periodSeconds: 10

            env:
             - name: KMS
               valueFrom:
                 configMapKeyRef:
                   name: {{.Values.configuration.configmapname}}
                   key: KMS
             - name: CERT_PATH
               valueFrom:
                  secretKeyRef:
                    name: dpg-secret 
                    key: server.crt
             - name: KEY_PATH
               valueFrom:
                  secretKeyRef:
                    name: dpg-secret
                    key: server.key
             - name: TLS_ENABLED
               valueFrom:
                  configMapKeyRef:
                    name: {{.Values.configuration.configmapname}}
                    key: TLS_ENABLED
             - name: REG_TOKEN
               valueFrom:
                  configMapKeyRef:
                    name: {{.Values.configuration.configmapname}}
                    key: REG_TOKEN
             - name: DESTINATION_URL
               valueFrom:
                  configMapKeyRef:
                    name: {{.Values.configuration.configmapname}}
                    key: DESTINATION_URL       

             

  replicas: {{.Values.deployment.replicas}}
  selector:
      matchLabels:
        run: {{.Values.runlabel}}
---
apiVersion: v1
kind: Service
metadata:
  name: {{.Values.service.name}}
spec:
  selector:
    run: {{.Values.runlabel}}
  type: {{.Values.service.type}}
  ports:
    - name: {{.Values.service.appPortName}}
      port: {{.Values.service.appPort}}
      targetPort: {{.Values.service.apptargetPort}}
      nodePort: {{.Values.service.appnodePort}}
    - name: {{.Values.service.probesPortName}}
      port: {{.Values.service.probesPort}}
      targetPort: {{.Values.service.probesTargetPort}}
      nodePort: {{.Values.service.probesNodePort}}
---
apiVersion: v1
data:
  server.crt: {{.Values.configuration.servercrt}}
  server.key: {{.Values.configuration.serverkey}}
kind: Secret
metadata:
  name: {{.Values.configuration.secretname}}
type: Opaque
---

apiVersion: v1
items:
- apiVersion: v1
  data:
    TLS_ENABLED: {{.Values.configuration.tlsenabled | quote}}
    KMS: {{.Values.configuration.kms}}
    REG_TOKEN:  {{.Values.configuration.reg_token}}
    DESTINATION_URL:  {{.Values.configuration.appurl}}
  kind: ConfigMap
  metadata:
    name: {{.Values.configuration.configmapname}}
kind: List
metadata:
