# Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# 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: wso2apim-dashboard-analytics-deployment
  namespace: wso2
spec:
  replicas: 1
  selector:
    matchLabels:
      deployment: wso2apim-dashboard-analytics
  minReadySeconds: 30
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        deployment: wso2apim-dashboard-analytics
    spec:
      initContainers:
        - name: init-wait-mysql
          image: alpine
          command: ["sh", "-c", "for i in $(seq 1 300); do nc -zvw1 wso2apim-with-analytics-rdbms-service 3306 && exit 0 || sleep 3; done; exit 1"]
      containers:
        - name: wso2apim-dashboard-analytics
          image: pubudu/wso2am-analytics-dashboard:3.1.0-rc1
          resources:
            limits:
              memory: "2Gi"
            requests:
              memory: "2Gi"
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - nc -z localhost 9643
            initialDelaySeconds: 10
            periodSeconds: 30
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - nc -z localhost 9643
            initialDelaySeconds: 3
            periodSeconds: 20
          lifecycle:
            preStop:
              exec:
                command:  ['sh', '-c', '${WSO2_SERVER_HOME}/bin/dashboard.sh stop']
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsUser: 802
          ports:
            -
              containerPort: 9643
              protocol: "TCP"
          volumeMounts:
          - name: apim-analytics-conf-dashboard
            mountPath: /home/wso2carbon/wso2-config-volume/conf/dashboard
      volumes:
      - name: apim-analytics-conf-dashboard
        configMap:
          name: dash-conf
      hostAliases:
        - ip: "127.0.0.1"
          hostnames:
            - "wso2apim-analytics"
