apiVersion: v1
kind: ConfigMap
metadata:
  name: service-template
data:
  template: |
    {
      "apiVersion": "serving.knative.dev/v1",
      "kind": "Service",
      "metadata": {
        "name": "%s",
        "namespace": "{{ .Release.Namespace }}",
        "labels": {
          "networking.knative.dev/visibility": "cluster-local"
        }
      },
      "spec": {
        "template": {
          "metadata": {
            "labels": {
              "direktiv-app": "direktiv"
            },
            "annotations": {
              "autoscaling.knative.dev/minScale": "%d"
            }
          },
          "spec": {
            "serviceAccountName": "%s",
            "containers": [
              {
                "image": "%s",
                "name": "direktiv-container",
                "env": [
                {{- if or (ne .Values.http_proxy "") (ne .Values.https_proxy "") }}
                {
                  "name": "HTTPS_PROXY",
                  "value": "{{ .Values.http_proxy }}"
                },
                {
                  "name": "HTTPS_PROXY",
                  "value": "{{ .Values.https_proxy }}"
                },
                {
                  "name": "NO_PROXY",
                  "value": "{{ .Values.no_proxy }}"
                }
                {{- end }}
                ],
                "volumeMounts": [
                  {
                    "name": "workdir",
                    "mountPath": "/mnt/shared"
                  }
                ],
    						"resources": {
                  "requests": {
                    "cpu": %f,
                    "memory": "%s"
                  },
                  "limits": {
                    "cpu": %f,
                    "memory": "%s"
                  }
                }
              },
              {
                "image": "%s",
                "name": "direktiv-sidecar",
                "env": [
                  {
                    "name": "DIREKTIV_DB",
                    "valueFrom": {
                      "secretKeyRef": {
                        "name": "{{ include "direktiv.fullname" . }}",
                        "key": "sidecarDb"
                      }
                    }
                  },
                  {{- if or (ne .Values.http_proxy "") (ne .Values.https_proxy "") }}
                  {
                    "name": "HTTPS_PROXY",
                    "value": "{{ .Values.http_proxy }}"
                  },
                  {
                    "name": "HTTPS_PROXY",
                    "value": "{{ .Values.https_proxy }}"
                  },
                  {
                    "name": "NO_PROXY",
                    "value": "{{ .Values.no_proxy }}"
                  },
                  {{- end }}
                  {
                    "name": "DIREKTIV_DEBUG",
                    "value": "{{ .Values.debug }}"
                  },
                  {
                    "name": "DIREKTIV_FLOW_ENDPOINT",
                    "value": "direktiv-kube:///{{ include "direktiv.fullname" . }}-flow.{{ .Release.Namespace }}:7777"
                  }
                ],
                "ports": [
                  {
                    "containerPort": 8890
                  }
                ],
                "volumeMounts": [
                  {{- if ne .Values.flow.certificate "none" }}
                  {
                    "name": "certs",
                    "mountPath": "/etc/certs/direktiv",
                    "readOnly": true
                  },
                  {{- end }}
                  {
                    "name": "workdir",
                    "mountPath": "/mnt/shared"
                  }
                ]
              }
            ],
            "volumes": [
              {{- if ne .Values.flow.certificate "none" }}
              {
                "name": "certs",
                "secret": {
                  "secretName": "{{ .Values.flow.certificate }}"
                }
              },
              {{- end }}
              {
                "name": "workdir",
                "emptyDir": {}
              }
            ]
          }
        }
      }
    }
