# A Kubernetes job to deploy an instance of kubeflow in a codelab
# project.
#
# This job sets up a single project.
# It is largely used as a template by kubeflow.testing.bulk_deploy.
# That python script will use this YAML file as a template for submitting 1 job per project.
apiVersion: batch/v1
kind: Job
metadata:
  generateName: setup-codelab-
  # namespace should
  namespace: kubeflow-jlewi
  labels:
    job: setup-codelab
spec:
  # We are seeing problems with network connectivity.
  backoffLimit: 3
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        job: setup-codelab
    spec:
      initContainers:
      - command:        
        - /usr/local/bin/checkout_repos.sh 
        - --depth=all
        # Keep repos in sync with other jobs
        # Suggest pinning to specific comits to avoid being broken  by changes
        - --repos=kubeflow/kubeflow@9741891,kubeflow/testing@HEAD:527
        - --src_dir=/src
        env:
        - name: PYTHONPATH
          value: /src/kubeflow/testing/py:/src/kubeflow/kubeflow
        image: gcr.io/kubeflow-ci/test-worker@sha256:dd559f89b3cbd926ec563559995f25025eecc6290b3146f17f82d2f084d07ee2
        imagePullPolicy: IfNotPresent
        name: checkout
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /src
          name: src
      containers:
      - name: deploy
        image: gcr.io/kubeflow-ci/test-worker@sha256:dd559f89b3cbd926ec563559995f25025eecc6290b3146f17f82d2f084d07ee2
        env:
        - name: PYTHONPATH
          value: /src/kubeflow/testing/py
        # TODO(jlewi): We aren't using workload identity because gcloud appears to be flaky.
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/user-gcp-sa.json
        # We need to set the KUBECONFIG variable because some of the code uses the existence
        # of this variable to determine how to authenticate to the cluster
        - name: KUBECONFIG
          value: /src/.kube
        command:
        - python
        - -m
        - kubeflow.testing.create_unique_kf_instance
        - --apps_dir=/src/apps
        - --kubeflow_repo=
        # The project fact will be overwritten when jobs are created from bulk-deploy
        - --project=kf-test-9990
        - --no-use_self_cert
        - --oauth_file=gs://kf-codelab-admin/test-project-iap.oauth.yaml
        # The remaining arguments customize how Kubeflow is setup.
        # You can change the values here in the template to change how bulk deploy will setup kubeflow instances
        - --name=kfv06            
        - --setup_project
        - --zone=us-west1-b
        # uncomment for v0.7
        #- --kfctl_path=https://github.com/kubeflow/kubeflow/releases/download/v0.7.0/kfctl_v0.7.0_linux.tar.gz  
        #- --kfctl_config=https://raw.githubusercontent.com/kubeflow/manifests/v0.7-branch/kfdef/kfctl_gcp_iap.0.7.0.yaml
        - --kfctl_path=https://github.com/kubeflow/kubeflow/releases/download/v0.6.2/kfctl_v0.6.2_linux.tar.gz
        - --kfctl_config=https://raw.githubusercontent.com/kubeflow/kubeflow/v0.6-branch/bootstrap/config/kfctl_gcp_iap.0.6.2.yaml        
        resources:
          requests:
            memory: "500Mi"
            cpu: "1"  
        volumeMounts:
        - mountPath: /src
          name: src
        - name: gcp-secret
          mountPath: /var/secrets
          readOnly: true
      # Use a Kubeflow service account which is mapped to a GSA
      serviceAccount: default-editor
      restartPolicy: Never
      volumes:
      - name: src
        emptyDir: {}
      - name: gcp-secret
        secret:
          secretName: user-gcp-sa