# --------------------------------------------------------------------
# Copyright (c) 2020, WSO2 Inc. (http://wso2.com) 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.
# -----------------------------------------------------------------------

# Deployment for router and enforcer

apiVersion: apps/v1
kind: Deployment
metadata:
  name: choreo-connect-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: choreo-connect-deployment
  template:
    metadata:
      labels:
        app: choreo-connect-deployment
    spec:
      containers:
        - name: choreo-connect-enforcer
          volumeMounts:
            - mountPath: /home/wso2/security/truststore
              name: enforcer-truststore-vol
            - mountPath: /home/wso2/security/keystore
              name: enforcer-keystore-vol
            - mountPath: /home/wso2/conf/log4j2.properties
              subPath: log4j2.properties
              name: log4j2-vol
            - mountPath: /home/wso2/lib/dropins
              name: dropins-vol
          image: wso2/choreo-connect-enforcer:1.1.0-m1-SNAPSHOT
          imagePullPolicy: IfNotPresent
          env:
            - name: ENFORCER_PRIVATE_KEY_PATH
              value: "/home/wso2/security/keystore/mg.key"
            - name: ENFORCER_PUBLIC_CERT_PATH
              value: "/home/wso2/security/keystore/mg.pem"
            - name: TRUSTED_CA_CERTS_PATH
              value: "/home/wso2/security/truststore"
            - name: ADAPTER_HOST_NAME
              value: "adapter"
            - name: ADAPTER_HOST
              value: "adapter"
            - name: ADAPTER_XDS_PORT
              value: "18000"
            - name: ENFORCER_LABEL
              value: "Default"
            - name: ENFORCER_REGION
              value: "UNKNOWN"
            - name: XDS_MAX_MSG_SIZE
              value: "4194304"
            - name: XDS_MAX_RETRIES
              value: "3"
            - name: JAVA_OPTS
              value: "-Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2"
            - name: apim_admin_pwd
              value: "admin"
            - name: enforcer_admin_pwd
              value: "admin"
            - name: tm_admin_pwd
              value: "admin"
            - name: analytics_authURL
              value: "https://localhost:8080"
            - name: analytics_authToken
              value: ""
          resources:
            requests:
              memory: "1000Mi"
              cpu: "1000m"
            limits:
              memory: "1000Mi"
              cpu: "1000m"
          ports:
            - containerPort: 8081
            - containerPort: 9001
          startupProbe:
            exec:
              command: [ "sh", "check_health.sh" ]
            periodSeconds: 5
            failureThreshold: 30
          livenessProbe:
            exec:
              command: [ "sh", "check_health.sh" ]
            initialDelaySeconds: 5
            periodSeconds: 30
          readinessProbe:
            exec:
              command: [ "sh", "check_health.sh" ]
            initialDelaySeconds: 5
            periodSeconds: 5
        - name: choreo-connect-router
          volumeMounts:
            - mountPath: /home/wso2/security/keystore
              name: router-keystore-vol
            - mountPath: /home/wso2/security/truststore
              name: router-truststore-vol
          image: wso2/choreo-connect-router:1.1.0-m1-SNAPSHOT
          imagePullPolicy: IfNotPresent
          env:
            - name: ROUTER_ADMIN_HOST
              value: "0.0.0.0"
            - name: ROUTER_ADMIN_PORT
              value: "9000"
            - name: ROUTER_CLUSTER
              value: "default_cluster"
            - name: ROUTER_LABEL
              value: "Default"
            - name: ROUTER_PRIVATE_KEY_PATH
              value: "/home/wso2/security/keystore/mg.key"
            - name: ROUTER_PUBLIC_CERT_PATH
              value: "/home/wso2/security/keystore/mg.pem"
            - name: ADAPTER_HOST
              value: "adapter"
            - name: ADAPTER_PORT
              value: "18000"
            - name: ADAPTER_CA_CERT_PATH
              value: "/home/wso2/security/truststore/mg.pem"
            - name: ENFORCER_HOST
              value: "127.0.0.1"
            - name: ENFORCER_PORT
              value: "8081"
            - name: ENFORCER_ANALYTICS_HOST
              value: "127.0.0.1"
            - name: ENFORCER_ANALYTICS_RECEIVER_PORT
              value: "18090"
            - name: ENFORCER_CA_CERT_PATH
              value: "/home/wso2/security/truststore/mg.pem"
            - name: CONCURRENCY
              value: "2"
          resources:
            requests:
              memory: "500Mi"
              cpu: "1000m"
            limits:
              memory: "500Mi"
              cpu: "1000m"
          ports:
            - containerPort: 9000
            - containerPort: 9095
          startupProbe:
            httpGet:
              port: 9095
              path: /ready
              scheme: HTTPS
              httpHeaders:
                - name: Host
                  value: gw.wso2.com
            failureThreshold: 30
            periodSeconds: 5
          livenessProbe:
            httpGet:
              port: 9095
              path: /health
              scheme: HTTPS
              httpHeaders:
                - name: Host
                  value: gw.wso2.com
            periodSeconds: 10
          readinessProbe:
            httpGet:
              port: 9095
              path: /ready
              scheme: HTTPS
              httpHeaders:
                - name: Host
                  value: gw.wso2.com
            periodSeconds: 5
      volumes:
        - name: router-keystore-vol
          secret:
            secretName: router-keystore
        - name: router-truststore-vol
          secret:
            secretName: router-truststore
        - name: enforcer-truststore-vol
          secret:
            secretName: enforcer-truststore
        - name: enforcer-keystore-vol
          secret:
            secretName: enforcer-keystore
        - name: config-toml-vol
          configMap:
            name: config-toml
        - name: log4j2-vol
          configMap:
            name: log4j2
        - name: logconfig-toml-vol
          configMap:
            name: logconfig-toml
        - name: dropins-vol
          emptyDir: {}
      restartPolicy: Always
