---
kind: Service
apiVersion: v1
metadata:
  name: imxc-api-service
  namespace: imxc
spec:
  type: NodePort
  selector:
    app: imxc-api
  ports:
  - protocol: TCP
    name: api
    port: 8080
    targetPort: 8080
    nodePort: 32080
  - protocol: TCP
    name: netty
    port: 10100
    targetPort: 10100
    nodePort: 31100
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: imxc-api
  namespace: imxc
  labels:
    app: imxc-api
spec:
  revisionHistoryLimit: 0
  replicas: 1
  selector:
    matchLabels:
      app: imxc-api
  template:
    metadata:
      labels:
        app: imxc-api
        build: develop
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cmoa
                operator: In
                values:
                - worker2
      securityContext:
        #runAsNonRoot: true
        runAsUser: 1577
      initContainers:
      - name: cloudmoa-api-permission-fix
        image: {{ .Values.global.IMXC_IN_REGISTRY }}/busybox:latest
        imagePullPolicy: IfNotPresent
        securityContext:
          runAsUser: 0
#        - sh
#        - -c
#        - "chmod -R 777 /home/cloudmoa/notification/cloudmoa_alert.log"
        volumeMounts:
        - mountPath: /home/cloudmoa/notification/
          name: notification-upper-directory
        - mountPath: /home/cloudmoa/notification/cloudmoa_alert.log
          name: notification-directory
      containers:
      - name: imxc-api
        image: {{ .Values.global.IMXC_IN_REGISTRY }}/api-server:{{ .Values.global.API_SERVER_VERSION }}
        resources:
          requests:
            cpu: 200m
            memory: 500Mi 
          limits:
            cpu: 2000m
            memory: 5000Mi
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c", {{ .Files.Get "scripts/init-api-server.sh" | quote }}]
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: prd
        - name: SPRING_ELASTIC_URLS
          value: elasticsearch
        - name: SPRING_ELASTIC_PORT
          value: "9200"
        - name: SPRING_DATAGATE_URLS
          value: "{{ .Values.global.DATAGATE_INSIDE_IP }}"
        - name: SPRING_DATAGATE_PORT
          value: "{{ .Values.global.DATAGATE_INSIDE_PORT }}"
        - name: SPRING_REDIS_URLS
          value: {{ .Values.global.REDIS_URLS }}
        - name: SPRING_REDIS_PORT
          value: "{{ .Values.global.REDIS_PORT }}"
        - name: SPRING_REDIS_PASSWORD
          value: {{ .Values.global.REDIS_PASSWORD }}
        - name: SPRING_DATASOURCE_URL
          value: jdbc:log4jdbc:postgresql://postgres:5432/postgresdb
        - name: SPRING_BOOT_ADMIN_CLIENT_URL
          value: http://{{ .Values.global.IMXC_ADMIN_SERVER_DNS }}:8888
        - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_NAME
          value: Intermax Cloud API Server
        - name: SPRING_BOOT_ADMIN_CLIENT_ENABLED
          value: "false"
        - name: OPENTRACING_JAEGER_ENABLED
          value: "false"
        - name: SPRING_JPA_PROPERTIES_HIBERNATE_GENERATE_STATISTICS
          value: "false"
        - name: IMXC_REPORT_ENABLED
          value: "true"
        - name: IMXC_ALERT_PERSIST
          value: "true"
        - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_METADATA_TAGS_ENVIRONMENT
          value: Demo
        - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_PREFERIP
          value: "true"
        - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_METADATA_TAGS_NODENAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: SPRING_BOOT_ADMIN_CLIENT_INSTANCE_METADATA_TAGS_PODNAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: SPRING_BOOT_ADMIN_CLIENT_AUTODEREGISTRATION
          value: "true"
        - name: SPRING_JPA_HIBERNATE_DDL-AUTO
          value: validate 
        - name: KEYCLOAK_AUTH-SERVER-URL
          value: "{{ .Values.global.KEYCLOAK_AUTH_SERVER_URL }}"
        - name: KEYCLOAK_REALM
          value: exem
        - name: KEYCLOAK_RESOURCE
          value: "{{ .Values.global.KEYCLOAK_RESOURCE }}"
        - name: SPRING_KEYCLOAK_MASTER_USERNAME
          value: "{{ .Values.global.KEYCLOAK_MASTER_USERNAME }}"
        - name: SPRING_KEYCLOAK_MASTER_PASSWORD
          value: "{{ .Values.global.KEYCLOAK_MASTER_PASSWORD }}"
        - name: SPRING_LDAP_USE
          value: "{{ .Values.global.IMXC_LDAP_USE }}"
        - name: TIMEZONE
          value: Asia/Seoul
        - name: IMXC_PROMETHEUS_URL
          value: http://base-cortex-nginx/prometheus
        - name: IMXC_PROMETHEUS_NAMESPACE
          value: "imxc"
        - name: LOGGING_LEVEL_ROOT
          value: info
        - name: IMXC_ALERT_NOTIFICATION_FILE_USE
          value: "true"
        - name: IMXC_ALERT_NOTIFICATION_FILE_FILE-LIMIT-SIZE-MB
          value: "10"
        - name: IMXC_ALERT_NOTIFICATION_FILE_PATH
          value: /cloudmoa_noti
        - name: IMXC_ALERT_NOTIFICATION_FILE_NAME
          value: cloudmoa_alert.log
        - name: IMXC_ALERT_NOTIFICATION_FILE_FORMAT
          value: $[name]/($[level])/$[data]/$[message]
        - name: IMXC_ALERT_NOTIFICATION_FILE_LEVELCONTRACT
          value: "true"
          #R30020210730 추가 :: 현대카드는 true로 설정
        - name: IMXC_ALERT_NOTIFICATION_MAIL_MAIL-HOST
          value: "exemmail1.ex-em.com"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_MAIL-PORT
          value: "587"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_MAIL-USERNAME
          value: "imxc@ex-em.com"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_MAIL-PASSWORD
          value: "1234"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_PROTOCOL
          value: "smtp"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_STARTTLS-REQ
          value: "true"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_STARTTLS-ENB
          value: "true"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_SMTP-AUTH
          value: "true"
        - name: IMXC_ALERT_NOTIFICATION_MAIL_DEBUG
          value: "true"
        - name: IMXC_ANOMALY_BLACK-LIST
          value: "false"
        - name: IMXC_VERSION_SAAS
          value: "false"
        - name: LOGGING_LEVEL_COM_EXEM_CLOUD_API_SERVER_KUBERNETES_SERVICE
          value: info
        - name: IMXC_WEBSOCKET_SCHEDULE_PERIOD_5SECOND
          value: "30000"
        - name: IMXC_CACHE_INFO_1MCACHE
          value: "0 0/1 * * * ?"
        - name: IMXC_EXECUTION_LOG_USE
          value: "false"
        - name: IMXC_EXECUTION_PERMISSION_LOG_USE
          value: "false"
        - name: IMXC_EXECUTION_CODE-LOG_USE
          value: "false"
        - name: IMXC_PORTAL_INFO_URL
          value: "{{ .Values.global.IMXC_PORTAL_INFO_URL }}"
        # Do not remove below rows related to AGENT-INSTALL. Added by youngmin 2021-03-29.
        - name: AGENT-INSTALL_COLLECTION-SERVER_KAFKA_IP
          value: {{ .Values.global.KAFKA_IP }}
        - name: AGENT-INSTALL_COLLECTION-SERVER_KAFKA_INTERFACE-PORT
          value: "{{ .Values.global.KAFKA_INTERFACE_PORT }}"
        - name: AGENT-INSTALL_COLLECTION-SERVER_APISERVER_IP
          value: {{ .Values.global.IMXC_API_SERVER_IP }}
        - name: AGENT-INSTALL_COLLECTION-SERVER_APISERVER_NETTY-PORT
          value: "{{ .Values.global.APISERVER_NETTY_PORT }}"
        - name: AGENT-INSTALL_REGISTRY_URL
          value: {{ .Values.global.IMXC_IN_REGISTRY }}
        - name: AGENT-INSTALL_IMAGE_TAG
          value: {{ .Values.global.AGENT_IMAGE_TAG }}
        - name: AGENT-INSTALL_JAEGER_AGENT_CLUSTERIP
          value: {{ .Values.global.JAEGER_AGENT_CLUSTERIP }}
        - name: AGENT-INSTALL_JAEGER_JAVA-SPECIALAGENT-CLASSPATH
          value: {{ .Values.global.JAEGER_JAVA_SPECIALAGENT_CLASSPATH }}
        - name: AGENT-INSTALL_COLLECTION-SERVER_DATAGATE_IP
          value: "{{ .Values.global.DATAGATE_OUTSIDE_IP }}"
        - name: AGENT-INSTALL_COLLECTION-SERVER_DATAGATE_PORT
          value: "{{ .Values.global.DATAGATE_OUTSIDE_PORT }}"
        - name: IMXC_REST-CONFIG_MAX-CON
          value: "200"
        - name: IMXC_REST-CONFIG_MAX-CON-ROUTE
          value: "65"
        # log4j
        - name: LOG4J_FORMAT_MSG_NO_LOOKUPS
          value: "true"
        # Elasticsearch for Security
        - name: SPRING_ELASTIC_SSL_USERNAME
          value: "{{ .Values.global.CMOA_ES_ID }}"
        - name: SPRING_ELASTIC_SSL_PASSWORD
          value: "{{ .Values.global.CMOA_ES_PW }}"
        - name: IMXC_BACK-LOGIN_ENABLED
          value: "{{ .Values.global.BACKLOGIN }}"
        - name: IMXC_UI_URL
          value: "{{ .Values.global.IMXC_UI_URL }}"
        volumeMounts:
        - mountPath: /var/log/imxc-audit.log
          name: auditlog
        - mountPath: /home/cloudmoa/notification/cloudmoa_alert.log
          name: notification-directory
        - mountPath: /home/cloudmoa/notification/
          name: notification-upper-directory
      volumes:
      - name: auditlog
        hostPath:
          path: {{ .Values.global.AUDITLOG_PATH }}/imxc-audit.log
          type: FileOrCreate
      - name: notification-upper-directory
        hostPath:
          path: /home/
          type: DirectoryOrCreate
      - name: notification-directory
        hostPath:
          path: /home/cloudmoa_event.log
          type: FileOrCreate
