# Identity Service Deployment with Entra VerifiedID configuration
apiVersion: apps/v1
kind: Deployment
metadata:
  name: identity-service
  namespace: the-order-prod
  labels:
    app: identity-service
    component: identity
spec:
  replicas: 3
  selector:
    matchLabels:
      app: identity-service
  template:
    metadata:
      labels:
        app: identity-service
        component: identity
    spec:
      containers:
      - name: identity-service
        image: ghcr.io/the-order/identity-service:latest
        ports:
        - containerPort: 4002
          name: http
        env:
        - name: PORT
          value: "4002"
        - name: NODE_ENV
          value: "production"
        # Entra VerifiedID Configuration
        - name: ENTRA_TENANT_ID
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_TENANT_ID
        - name: ENTRA_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_CLIENT_ID
        - name: ENTRA_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_CLIENT_SECRET
        - name: ENTRA_CREDENTIAL_MANIFEST_ID
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_CREDENTIAL_MANIFEST_ID
        - name: ENTRA_MANIFESTS
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_MANIFESTS
              optional: true
        - name: ENTRA_RATE_LIMIT_ISSUANCE
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_RATE_LIMIT_ISSUANCE
              optional: true
        - name: ENTRA_RATE_LIMIT_VERIFICATION
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_RATE_LIMIT_VERIFICATION
              optional: true
        - name: ENTRA_RATE_LIMIT_STATUS_CHECK
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_RATE_LIMIT_STATUS_CHECK
              optional: true
        - name: ENTRA_RATE_LIMIT_GLOBAL
          valueFrom:
            secretKeyRef:
              name: entra-verifiedid-secrets
              key: ENTRA_RATE_LIMIT_GLOBAL
              optional: true
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 4002
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 4002
          initialDelaySeconds: 10
          periodSeconds: 5
        volumeMounts:
        - name: config
          mountPath: /app/config
          readOnly: true
      volumes:
      - name: config
        configMap:
          name: identity-service-config
---
apiVersion: v1
kind: Service
metadata:
  name: identity-service
  namespace: the-order-prod
spec:
  selector:
    app: identity-service
  ports:
  - port: 80
    targetPort: 4002
    protocol: TCP
  type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: identity-service-ingress
  namespace: the-order-prod
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rate-limit: "100"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - api.theorder.org
    secretName: identity-service-tls
  rules:
  - host: api.theorder.org
    http:
      paths:
      - path: /vc
        pathType: Prefix
        backend:
          service:
            name: identity-service
            port:
              number: 80
      - path: /eidas
        pathType: Prefix
        backend:
          service:
            name: identity-service
            port:
              number: 80

