apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    rep-addon: v2-relay-agent
    rep-cluster: "{{ .DownloadData.ClusterID }}"
  name: "kube-proxy-agent-{{ .DownloadData.ClusterID }}"
  namespace: paralus-system
spec:
  progressDeadlineSeconds: 1800
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: "kube-proxy-agent-{{ .DownloadData.ClusterID }}"
  template:
    metadata:
      labels:
        app: "kube-proxy-agent-{{ .DownloadData.ClusterID }}"
    spec:
      containers:
      - args:
        - --mode=client
        - --log-level=3
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: MAX_DIALS
          valueFrom:
            configMapKeyRef:
              key: maxDials
              name: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"
              optional: true
        - name: RELAY_CONFIGMAP_NAME
          value: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"
        - name: DIALOUT_PROXY
          valueFrom:
            configMapKeyRef:
              key: httpsProxy
              name: proxy-config
              optional: true
        - name: DIALOUT_PROXY_AUTHENTICATION
          valueFrom:
            configMapKeyRef:
              key: proxyAuth
              name: proxy-config
              optional: true
        - name: HTTP_PROXY
          valueFrom:
            configMapKeyRef:
              key: httpProxy
              name: proxy-config
              optional: true
        - name: HTTPS_PROXY
          valueFrom:
            configMapKeyRef:
              key: httpsProxy
              name: proxy-config
              optional: true
        - name: NO_PROXY
          valueFrom:
            configMapKeyRef:
              key: noProxy
              name: proxy-config
              optional: true
        - name: ALLOW_INSECURE_BOOTSTRAP
          valueFrom:
            configMapKeyRef:
              key: allowInsecureBootstrap
              name: proxy-config
              optional: true
        image: "{{ .DownloadData.RelayImage }}"
        imagePullPolicy: IfNotPresent
        name: "kube-proxy-agent-{{ .DownloadData.ClusterID }}"
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/config
          name: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"
      initContainers:
      - command:
        - sh
        - -c
        - ulimit -n 65536
        image: busybox:1.33
        imagePullPolicy: IfNotPresent
        name: set-limits
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      priorityClassName: paralus-cluster-critical
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
      volumes:
      - configMap:
          defaultMode: 420
          name: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"
        name: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"

---
apiVersion: v1
kind: ConfigMap
data:
  clusterID: "{{ .DownloadData.ClusterID }}"
  maxDials: "8"
  relays: '[{"token":"{{ .DownloadData.Token }}","addr":"{{ .DownloadData.SentryAddr }}","endpoint":"{{ .DownloadData.HostName }}","name":"{{ .DownloadData.TemplateName }}","templateToken":"{{ .DownloadData.TemplateToken }}"}]'
metadata:
  labels:
    rep-addon: v2-relay-agent
    rep-cluster: "{{ .DownloadData.ClusterID }}"
  name: "kube-proxy-agent-config-{{ .DownloadData.ClusterID }}"
  namespace: paralus-system
