apiVersion: apps/v1
kind: Deployment
metadata:
  name: datamon-coord-pg-demo

spec:
  selector:
    matchLabels:
      app: datamon-coord-pg-demo
  replicas: 1
  template:
    metadata:
      labels:
        app: datamon-coord-pg-demo
    spec:
      initContainers:
      - name: init-application-wrap
        image: gcr.io/onec-co/datamon-pg-sidecar:latest
        imagePullPolicy: "$PULL_POLICY"
        command: ["sh", "-c",
        "mkdir /tmp/coord/.scripts; cp wrap_application.sh /tmp/coord/.scripts/wrap_application.sh; chmod a+x /tmp/coord/.scripts/wrap_application.sh; echo 'placed application wrapper'"]
        stdin: true
        tty: true
        volumeMounts:
        - mountPath: /tmp/coord
          name: container-coord
      containers:
      - name: demo-app
        image: gcr.io/onec-co/datamon-pg-demo-coord-app:latest
        imagePullPolicy: "$PULL_POLICY"

        # command: ["/bin/tini"]
        # args: ["--", "/bin/zsh"]

        command: ["/tmp/coord/.scripts/wrap_application.sh"]
        args: ["-s", "-c", "/tmp/coord", "-b", "postgres", "--",
        "./mock_application_pg.sh",
        "5430", "5429",
        "$SOME_CONST", "$IS_INIT"]

        stdin: true
        tty: true
        volumeMounts:
        - mountPath: /tmp/coord
          name: container-coord
      - name: datamon-sidecar
        image: gcr.io/onec-co/datamon-pg-sidecar:latest
        imagePullPolicy: "$PULL_POLICY"

        # command: ["/bin/tini"]
        # args: ["--", "/bin/zsh"]

        command: ["./wrap_datamon_pg.sh"]
        args: []

        # args: ["-S",
        # "-V", "$IGNORE_VERSION_MISMATCH",
        # "-c", "/tmp/coord",
        # "-x",
        # "-r", "ransom-datamon-test-repo",
        # "-l", "$OUTPUT_LABEL",
        # "-m", "postgres coordination example",
        # "-p", "5430",
        # "-x",
        # "-r", "ransom-datamon-test-repo",
        # "-m", "postgres coordination example input",
        # "-p", "5429",
        # "-s",
        # "-r", "ransom-datamon-test-repo",
        # "-l", "pg-coord-example-input",
        # ]

        securityContext:
          privileged: true
        stdin: true
        tty: true
        volumeMounts:
        - mountPath: /pg_stage
          name: staging-area
        - mountPath: /tmp/coord
          name: container-coord
        - mountPath: /tmp/gac
          name: google-application-credentials

        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /tmp/gac/google-application-credentials.json

        - name: dm_pg_opts
          value: ";:S;V:$IGNORE_VERSION_MISMATCH;c:/tmp/coord"
        - name: dm_pg_db_db1
          value: ";:r:ransom-datamon-test-repo;l:$OUTPUT_LABEL;m:postgres coordination example;p:5430"
        - name: dm_pg_db_db2
          value: ";:r:ransom-datamon-test-repo;m:postgres coordination example input;p:5429;sr:ransom-datamon-test-repo;sl:pg-coord-example-input"

      volumes:
      - name: container-coord
        emptyDir: {}
      - name: staging-area
        emptyDir: {}
      - name: google-application-credentials
        secret:
          secretName: google-application-credentials
