#
#  Copyright 2019 WeBank
#
# Licensed 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: linkis-gateway-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: linkis-gateway
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate

  template:
    metadata:
      labels:
        app: linkis-gateway
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - linkis-gateway
              topologyKey: "kubernetes.io/hostname"
        
      containers:
      - name: linkis-gateway
        image: wedatasphere/linkis:linkis-gateway-0.10.0
        lifecycle:
            preStop:
              exec:
                command: ["sh","/opt/linkis/linkis-gateway/bin/stop.sh"]
        imagePullPolicy: Always
        ports:
        - name: http
          containerPort: 14001
          protocol: TCP
        livenessProbe:
            tcpSocket:
              port: 14001
            initialDelaySeconds: 15
            periodSeconds: 20
        env:
          - name: EUREKA_URL
            valueFrom:
              configMapKeyRef:
                name: eureka-config
                key: eurekaUrl
          - name: SERVER_HEAP_SIZE
            value: 1024M
          - name: START_PORT
            value: "14001"
        volumeMounts:
          - name: linkis-gateway-config
            mountPath: /opt/linkis/conf
#          - name: resultset
#            mountPath: /opt/linkis/data
          - name: varlog
            mountPath: /opt/linkis/linkis-gateway/logs
          - name: hadoop-config
            mountPath: /opt/hadoop/hadoop-2.7.7/etc/hadoop
          - name: hive-config
            mountPath: /opt/hive/apache-hive-2.3.6-bin/conf
          - name: spark-config
            mountPath: /opt/spark/spark-2.4.4-bin-hadoop2.7/conf
      imagePullSecrets:
        - name: registry-key
      volumes:
        - name: linkis-gateway-config
          configMap:
            name: linkis-gateway-config
#        - name: resultset
#          nfs:
#            path: /data/k8s
#            server: 10.206.0.12
        - name: varlog
          hostPath:
            path: /var/log
        - name: eureka-config
          configMap:
            name: eureka-config
        - name: hadoop-config
          hostPath:
            path: /opt/hadoop/hadoop-2.7.7/etc/hadoop
        - name: hive-config
          hostPath:
            path: /opt/hive/apache-hive-2.3.6-bin/conf
        - name: spark-config
          hostPath:
            path: /opt/spark/spark-2.4.4-bin-hadoop2.7/conf
