# In the future, build the kubernetes cluster from the official docker account
# Also ensure that proper tagging/versioning is done i.e. remove :latest tag and instead use the digest of the container

apiVersion: apps/v1
kind: Deployment
metadata:
  name: 'gaas-deployment'
  labels:
    app: gaas-deployment
spec:
  selector:
    matchLabels:
      app: gaas
  replicas: 1
  template:
    metadata:
      name: 'gaas'
      labels:
        app: gaas
    spec:
      volumes:
        - name: shared-jobs
          persistentVolumeClaim:
            claimName: shared-jobs-claim
        - name: flowconfig-templates
          configMap:
            name: flowconfig-templates
        - name: gaas-config
          configMap:
            name: gaas-config
      containers:
        - name: gobblin-service
          image: apache/gobblin:latest
          args: ["--mode", "gobblin-as-service", "--jvmopts", "-DmysqlCredentials.user=$(MYSQL_USERNAME) -DmysqlCredentials.password=$(MYSQL_PASSWORD) -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"]
          env:
            - name: MYSQL_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mysql-credentials
                  key: username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-credentials
                  key: password
          volumeMounts:
            - name: shared-jobs
              mountPath: /etc/gobblin-as-service/jobs
            - name: flowconfig-templates
              mountPath: /etc/templateCatalog
            - name: gaas-config
              mountPath: /home/gobblin/conf/gobblin-as-service/application.conf
              subPath: gaas-application.conf
      # dependency on mysql to be initialized before gaas can be initialized
      initContainers:
        - name: init-mysql
          image: busybox:1.28
          command: ['sh', '-c', 'until nslookup mysql; do echo waiting for mysql; sleep 2; done;']


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gobblin-standalone-deployment
  labels:
    app: gobblin-standalone-deployment
spec:
  selector:
    matchLabels:
      app: gobblin-standalone
  replicas: 1
  template:
    metadata:
      name: 'gobblin-standalone'
      labels:
        app: gobblin-standalone
    spec:
      volumes:
        - name: shared-jobs
          persistentVolumeClaim:
            claimName: shared-jobs-claim
        - name: standalone-config
          configMap:
            name: standalone-config
      containers:
        - name: gobblin-standalone
          image: apache/gobblin:latest
          args: ["--mode", "standalone"]
          volumeMounts:
            - name: shared-jobs
              mountPath: /etc/gobblin-standalone/jobs
            - name: standalone-config
              mountPath: /home/gobblin/conf/standalone/application.conf
              subPath: standalone-application.conf
          env:
            - name: GOBBLIN_JOB_CONFIG_DIR
              value: /etc/gobblin-standalone/jobs
