apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-server
  namespace: imxc
spec:
  selector:
    matchLabels:
      app: auth
  replicas: 1
  template:
    metadata:
      labels:
        app: auth
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cmoa
                operator: In
                values:
                - worker1
      initContainers:
      - name: init-resource
        image: {{ .Values.global.IMXC_IN_REGISTRY }}/init-resource:latest
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-c"]
        args: ['chmod -R 777 /scripts; cp /scripts/init.json /tmp/init.json']
        volumeMounts:
          - name: init
            mountPath: /tmp
      containers:
      - name: auth-server
        image: {{ .Values.global.IMXC_IN_REGISTRY }}/auth-server:{{ .Values.global.AUTH_SERVER_VERSION }}
        imagePullPolicy: IfNotPresent
        command: ["sh", "-c", {{ .Files.Get "scripts/init-auth-server.sh" | quote }}]
        env:
        # spring profile
        - name: SPRING_PROFILES_ACTIVE
          value: prd

        # imxc-api-server configuration
        - name: IMXC_API-SERVER-URL
          value: http://imxc-api-service:8080

        # keycloak configuration
        - name: KEYCLOAK_AUTH-SERVER-URL
          value: "{{ .Values.global.KEYCLOAK_AUTH_SERVER_URL }}"
        - name: KEYCLOAK_REALM
          value: exem
        # eureka configuration
        - name: EUREKA_CLIENT_SERVICE-URL_DEFAULTZONE
          value: http://eureka:8761/eureka
        # log4j
        - name: LOG4J_FORMAT_MSG_NO_LOOKUPS
          value: "true"
        - name: LOGGING_LEVEL_COM_EXEM_CLOUD_REPO
          value: debug
        - name: LOGGING_LEVEL_COM_EXEM_CLOUD_AUTH_AUTHENTICATION_USER_SERVICE
          value: debug
        # 현대카드는 커스텀으로 해당 값 추가. keycloak만 사용(true), keycloak+내부db 사용(false)
        - name: IMXC_KEYCLOAK_ENABLED
          value: "true"
        - name: IMXC_KEYCLOAK_MASTER_PASSWORD
          value: admin
          
        volumeMounts:
          - name: init
            mountPath: /tmp
        resources:
          requests:
            memory: "200Mi"
            cpu: "10m"

      volumes:
      - name: init
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: auth-server-service
  namespace: imxc
spec:
  type: ClusterIP
  selector:
    app: auth
  ports:
    - protocol: TCP
      port: 8480
      #      nodePort: 15016
