#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: StatefulSet
metadata:
  name: kylin-job
  namespace: kylin-example
  labels:
    app: kylin
    role: job
    environment: poc
    version: 3.0.1
    hadoop.version: cdh5.7
spec:
  serviceName: kylin-job-svc
  replicas: 1
  selector:
    matchLabels:
      app: kylin
      role: job
  template:
    metadata:
      labels:
        app: kylin
        role: job
    spec:
      containers:
        - name: kylin
          image: kylin-client:3.0.1-cdh57
          imagePullPolicy: IfNotPresent
          command:
            - sh
            - -c
          args:
            - cp $KYLIN_HOME/tomcat-config/* $KYLIN_HOME/tomcat/conf;
              cp $KYLIN_HOME/kylin-more-config $KYLIN_HOME/tomcat/webapps/kylin/WEB-INF/classes/;
              $TOOL_HOME/bootstrap.sh server -d;
          ports:
            - containerPort: 7070
            - containerPort: 7443
          volumeMounts:
            - name: kylin-job-config
              mountPath: /home/apache_kylin/kylin/conf
            - name: tomcat-config
              mountPath: /home/apache_kylin/kylin/tomcat-config
            - name: kylin-more-config
              mountPath: /home/apache_kylin/kylin/kylin-more-config/
            - name: hadoop-config
              mountPath: /etc/hadoop/conf
            - name: hive-config
              mountPath: /etc/hive/conf
            - name: hbase-config
              mountPath: /etc/hbase/conf
            - name: kylin-logs
              mountPath: /home/apache_kylin/kylin/logs
            - name: tomcat-logs
              mountPath: /home/apache_kylin/kylin/tomcat/logs
          resources:
            requests:
              memory: 2Gi
              cpu: 1000m
            limits:
              memory: 2Gi
              cpu: 1000m
        - name: filebeat
          image: docker.elastic.co/beats/filebeat:6.4.3
          args:
            - -c
            - /usr/share/filebeat/config/filebeat.yml
            - -e
          volumeMounts:
            - name: kylin-logs
              mountPath: /home/apache_kylin/kylin/logs
            - name: tomcat-logs
              mountPath: /home/apache_kylin/kylin/tomcat/logs
            - name: filebeat-config
              mountPath: /usr/share/filebeat/config
              readOnly: true
          resources:
            requests:
              memory: 1Gi
              cpu: 300m
            limits:
              memory: 1Gi
              cpu: 300m
      volumes:
        - name: kylin-logs
          emptyDir:
            sizeLimit: 3Gi
        - name: tomcat-logs
          emptyDir:
            sizeLimit: 2Gi
        - configMap:
            name: hadoop-config
          name: hadoop-config
        - configMap:
            name: hive-config
          name: hive-config
        - configMap:
            name: hbase-config
          name: hbase-config
        - configMap:
            name: kylin-job-config
          name: kylin-job-config
        - configMap:
            name: tomcat-config
          name: tomcat-config
        - configMap:
            name: filebeat-config
          name: filebeat-config
        - configMap:
            name: kylin-more-config
          name: kylin-more-config
  updateStrategy:
    type: RollingUpdate