kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: jobmanager-amd64
  namespace: default
spec:
  selector:
    matchLabels:
      jobmanager-node: pod
  template:
    metadata:
      name: jobmanager-amd64
      labels:
        jobmanager-node: pod
        app: jobmanager
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/path: "/metrics"
    spec:
      
      hostNetwork: true    
      nodeSelector:
        jobmanager: active
        archType: amd64
      initContainers:
      #During this Pod's initialization, check that postgres service is up and running before starting this pod
      - name: check-postgres-ready
        image: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/apulistech/busybox:v1.28

        command: ['sh', '-c', "until nc -vz 192.168.2.163 5432; do echo 'Waiting for postgres service'; sleep 2; done;" ]

      containers:
      - name: jobmanager
        image: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/apulistech/dlworkspace_restfulapi2:v1.5.0-rc8

        command: ["/runScheduler.sh"]
        imagePullPolicy: Always
        env:
        - name: INIT_CONTAINER_IMAGE
          value: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/apulistech/dlworkspace_init-container:latest

        volumeMounts:
        - mountPath: /usr/bin/kubectl
          name: kubectl-binary
          readOnly: true
        - mountPath: /root/.kube/config
          name: kubeconfig
          readOnly: true
        - mountPath: /RestfulAPI/config.yaml
          name: apiconfig
          subPath: config.yaml
        - mountPath: /var/log/dlworkspace
          name: log
        - mountPath: /dlwsdata/work
          name: aiplatform-app-data-pvc
          subPath: work/
        - mountPath: /dlwsdata/storage
          name: aiplatform-model-data-pvc
        - mountPath:  /dlwsdata/jobfiles
          name: aiplatform-app-data-pvc
          subPath: jobfiles/
        - mountPath:  /dlwsdata/label
          name: aiplatform-label-data-pvc
        ports:
        - containerPort: 9200
          hostPort: 9200
          name: job-mgr
          protocol: TCP
        - containerPort: 9201
          hostPort: 9201
          name: user-mgr
          protocol: TCP
        - containerPort: 9202
          hostPort: 9202
          name: node-mgr
          protocol: TCP
        - containerPort: 9203
          hostPort: 9203
          name: joblog-mgr
          protocol: TCP
        - containerPort: 9204
          hostPort: 9204
          name: cmd-mgr
          protocol: TCP
        - containerPort: 9205
          hostPort: 9205
          name: endpoint-mgr
          protocol: TCP
        - containerPort: 9206
          hostPort: 9206
          name: job-mgr2
          protocol: TCP
        - containerPort: 9207
          hostPort: 9207
          name: job-mgr3
          protocol: TCP
        - containerPort: 9208
          hostPort: 9208
          name: job-mgr4
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          initialDelaySeconds: 3
          periodSeconds: 30
          successThreshold: 1
          tcpSocket:
            port: 9200
          timeoutSeconds: 10
      - name: redis
        image: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/redis:5.0.6-alpine

        command: ["redis-server", "--port", "9300", "--maxmemory", "100mb", "--maxmemory-policy", "allkeys-lru"]
        ports:
        - containerPort: 9300
          hostPort: 9300
          name: prom-ign-redis
          protocol: TCP
      volumes:
      - name: kubectl-binary
        hostPath:
          path: /opt/kube/bin/kubectl

      - name: kubeconfig
        hostPath:
          path: /root/.kube/config
      - name: apiconfig
        configMap:
          name: restful-cm
      - name: log
        hostPath:
          path: /var/log/clustermanager
      - name: resolv
        hostPath:
          path: /etc/resolv.conf
      - name: aiplatform-app-data-pvc
        persistentVolumeClaim:
          claimName: aiplatform-app-data-pvc
      - name: aiplatform-model-data-pvc
        persistentVolumeClaim:
          claimName: aiplatform-model-data-pvc
      - name: aiplatform-label-data-pvc
        persistentVolumeClaim:
          claimName: aiplatform-label-data-pvc

      tolerations:
      - key: CriticalAddonsOnly
        operator: Exists
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
