# ===============LICENSE_START=======================================================
# Acumos Apache-2.0
# ===================================================================================
# Copyright (C) 2019 AT&T Intellectual Property & Tech Mahindra. All rights reserved.
# ===================================================================================
# This Acumos software file is distributed by AT&T and Tech Mahindra
# under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============LICENSE_END=========================================================

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: <ACUMOS_NAMESPACE>
  name: mlwb-notebook
  labels:
    app: mlwb-notebook
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mlwb-notebook
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mlwb-notebook
        <ACUMOS_SERVICE_LABEL_KEY>: <MLWB_NOTEBOOK_SERVICE_LABEL>
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: <ACUMOS_SERVICE_LABEL_KEY>
                operator: NotIn
                values:
                - <MLWB_NOTEBOOK_SERVICE_LABEL>
            topologyKey: "kubernetes.io/node"
      imagePullSecrets:
      - name: acumos-registry
      containers:
      - name: mlwb-notebook
        image: <MLWB_NOTEBOOK_SERVICE_IMAGE>
        env:
        - name: SPRING_APPLICATION_JSON
          value: '{
            "server": {
              "port": 9089
            },
            "dateformat": "yyyy-MM-dd-HH-mm-ss-SSS",
            "resultsetSize": 2000,
            "outputFolder": "/tmp",
            "cmndatasvc": {
              "endpointurl": "http://<ACUMOS_CDS_HOST>:<ACUMOS_CDS_PORT>/ccds",
              "user": "<ACUMOS_CDS_USER>",
              "pwd": "<ACUMOS_CDS_PASSWORD>"
            },
            "projectservice": {
              "url": "http://mlwb-project-service:9088/mlWorkbench/v1/project"
            },
            "jupyterhub": {
              "url": "https://<MLWB_JUPYTERHUB_DOMAIN>:<MLWB_JUPYTERHUB_PORT>",
              "token":"<MLWB_JUPYTERHUB_API_TOKEN>",
              "storepass": "changeit",
              "installcert": <MLWB_JUPYTERHUB_INSTALL_CERT>
            },
            "jupyternotebook": {
              "url": "https://<MLWB_JUPYTERHUB_DOMAIN>:<MLWB_JUPYTERHUB_PORT>"
            },
            "jwt" : {
              "secretkey": "<ACUMOS_JWT_KEY>"
            },
            "useexternalnotebook": <MLWB_JUPYTERHUB_EXTERNAL_NOTEBOOK_SERVICE>
          }'
        command: ["/bin/sh", "-c"]
        args:
        - set -x;
          cd maven;
          keytool -import -file certs/<MLWB_JUPYTERHUB_CERT> -alias jupyterhub -keystore /opt/java/openjdk/lib/security/cacerts -storepass changeit -noprompt;
          java -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -jar notebook-service*.jar;
        ports:
        - containerPort: 9089
        volumeMounts:
        - mountPath: /maven/logs
          name: logs
        - mountPath: /maven/certs
          name: certs-volume
      restartPolicy: Always
      volumes:
      - name: certs-volume
        secret:
          secretName: mlwb-jupyterhub-certs
      - name: logs
        persistentVolumeClaim:
          claimName: <MLWB_NOTEBOOK_SERVICE_LABEL>
