---
apiVersion: v1
kind: ConfigMap
metadata:
  name: vhs-webhook-configmap
  namespace: redsky-system
data:
  sidecarconfig.yaml: |
    volumes:
      - name: cloud-credentials
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/secret")) 0 %}
        secret:
          secretName: {% index .Annotations "vhs.carbon-relay.com/secret" %}
        {% else %}
        emptyDir: {}
        {% end %}
    containers:
      - name: vhs
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/secret")) 0 %}
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /root/.config/gcloud/service-account.json
        {% end %}
        imagePullPolicy: IfNotPresent
        volumeMounts:
          # Since we don't know which cloud provider is being used specifically,
          # we'll mount up the secret to each well known location
          # GCP
          - mountPath: /root/.config/gcloud
            name: cloud-credentials
          # AWS
          - mountPath: /root/.aws
            name: cloud-credentials
          # Azure
          - mountPath: /root/.azure/credentials
            name: cloud-credentials

        # Override default image
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/image")) 0 %}
        image: {% index .Annotations "vhs.carbon-relay.com/image" %}
        {% else %}
        image: us.gcr.io/carbon-relay-dev/vhs:latest
        {% end %}

        # Override args
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/args")) 0 %}
        args: {% index .Annotations "vhs.carbon-relay.com/args" %}
        {% else %}
        # Set default to be metrics capture
        args:
        - --input
        - tcp|http
        - --capture-response
        - --address
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/port")) 0 %}
        - 0.0.0.0:{% index .Annotations "vhs.carbon-relay.com/port" %}
        {% else %}
        - 0.0.0.0:80
        {% end %}
        - --prometheus-address
        - 0.0.0.0:9090
        - --flow-duration
        - 3600s
        {% end %}

        # Override command
        {% if ne (len (index .Annotations "vhs.carbon-relay.com/command")) 0 %}
        command: {% index .Annotations "vhs.carbon-relay.com/command" %}
        {% end %}
  mutationconfig.yaml: |
    mutationConfigs:
      - name: vhs
        annotationNamespace: "vhs.carbon-relay.com"
        annotationTrigger: "inject"
        containers:
        - vhs
        volumes:
        - cloud-credentials
        ignoreNamespaces:
        - kube-system
        - redsky-system
