---
apiVersion: v1
kind: Namespace
metadata:
  name: vault-radar
  labels:
    app: vault-radar-agent

---
apiVersion: v1
kind: Secret
metadata:
  name: vault-radar-secrets
  namespace: vault-radar
  labels:
    app: vault-radar-agent
type: Opaque
data:
  HCP_PROJECT_ID: $HCP_PROJECT_ID_BASE64
  HCP_RADAR_AGENT_POOL_ID: $HCP_RADAR_AGENT_POOL_ID_BASE64
  HCP_CLIENT_ID: $HCP_CLIENT_ID_BASE64
  HCP_CLIENT_SECRET: $HCP_CLIENT_SECRET_BASE64
  VAULT_RADAR_GIT_TOKEN: $VAULT_RADAR_GIT_TOKEN_BASE64

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vault-radar-agent
  namespace: vault-radar
  labels:
    app: vault-radar-agent
spec:
  replicas: 2
  selector:
    matchLabels:
      app: vault-radar-agent
  template:
    metadata:
      labels:
        app: vault-radar-agent
    spec:
      containers:
        - name: vault-radar-agent
          image: $IMAGE_REGISTRY/vault-radar:$IMAGE_TAG
          command: ["vault-radar"]
          args: ["agent", "exec"]
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 1000m
              memory: 1024Mi
            requests:
              cpu: 100m
              memory: 512Mi
          env:
            - name: HCP_PROJECT_ID
              valueFrom:
                secretKeyRef:
                  name: vault-radar-secrets
                  key: HCP_PROJECT_ID
            - name: HCP_RADAR_AGENT_POOL_ID
              valueFrom:
                secretKeyRef:
                  name: vault-radar-secrets
                  key: HCP_RADAR_AGENT_POOL_ID
            - name: HCP_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: vault-radar-secrets
                  key: HCP_CLIENT_ID
            - name: HCP_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: vault-radar-secrets
                  key: HCP_CLIENT_SECRET
            - name: VAULT_RADAR_GIT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: vault-radar-secrets
                  key: VAULT_RADAR_GIT_TOKEN
            - name: HCP_API_ADDRESS
              value: $HCP_API_ADDRESS
            - name: HCP_AUTH_URL
              value: $HCP_AUTH_URL
