apiVersion: apps/v1
kind: Deployment
metadata:
  name: skillhub-server
  labels:
    app.kubernetes.io/name: skillhub-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: skillhub-server
  template:
    metadata:
      labels:
        app.kubernetes.io/name: skillhub-server
    spec:
      containers:
        - name: server
          image: ghcr.io/iflytek/skillhub-server:edge
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: http
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: docker

            # Database
            - name: SPRING_DATASOURCE_URL
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: spring-datasource-url
            - name: SPRING_DATASOURCE_USERNAME
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: spring-datasource-username
            - name: SPRING_DATASOURCE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: spring-datasource-password

            # Redis
            - name: SPRING_DATA_REDIS_HOST
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-host
            - name: SPRING_DATA_REDIS_PORT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-port
            - name: SPRING_DATA_REDIS_CLUSTER_NODES
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-cluster-nodes
                  optional: true
            - name: SPRING_DATA_REDIS_CLUSTER_MAX_REDIRECTS
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-cluster-max-redirects
                  optional: true
            - name: SPRING_DATA_REDIS_SENTINEL_MASTER
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-sentinel-master
                  optional: true
            - name: SPRING_DATA_REDIS_SENTINEL_NODES
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-sentinel-nodes
                  optional: true
            - name: SPRING_DATA_REDIS_SENTINEL_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-sentinel-username
                  optional: true
            - name: SKILLHUB_REDIS_SENTINEL_CHECK_SENTINELS_LIST
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-sentinel-check-list
                  optional: true
            - name: SPRING_DATA_REDIS_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-username
                  optional: true
            - name: SPRING_DATA_REDIS_SSL_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-ssl-enabled
                  optional: true
            - name: SPRING_DATA_REDIS_CONNECT_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-connect-timeout
                  optional: true
            - name: SPRING_DATA_REDIS_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-timeout
                  optional: true
            - name: SPRING_DATA_REDIS_CLIENT_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: redis-client-name
                  optional: true
            - name: SPRING_DATA_REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: redis-password
                  optional: true
            - name: SPRING_DATA_REDIS_SENTINEL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: redis-sentinel-password
                  optional: true

            # Storage
            - name: STORAGE_BASE_PATH
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: storage-base-path
            - name: SKILLHUB_STORAGE_PROVIDER
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: skillhub-storage-provider

            # Scanner
            - name: SKILLHUB_SECURITY_SCANNER_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: skill-scanner-enabled
            - name: SKILLHUB_SECURITY_SCANNER_URL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: skill-scanner-url
            - name: SKILLHUB_SECURITY_SCANNER_MODE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: skill-scanner-mode

            # Session
            - name: SESSION_COOKIE_SECURE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: session-cookie-secure
            - name: SPRING_SESSION_REDIS_REPOSITORY_TYPE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: session-repository-type
            - name: SESSION_REDIS_NAMESPACE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: session-redis-namespace
            - name: SPRING_SESSION_REDIS_CONFIGURE_ACTION
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: session-redis-configure-action
            - name: SKILLHUB_AUTH_ACCOUNT_MERGE_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-account-merge-enabled
            - name: SKILLHUB_AUTH_ACCOUNT_MERGE_SESSION_CUTOVER_COMPLETE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-account-merge-session-cutover-complete

            # LDAP/Active Directory credential login
            - name: SKILLHUB_AUTH_LDAP_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-enabled
            - name: SKILLHUB_AUTH_LDAP_PROVIDER_CODE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-provider-code
            - name: SKILLHUB_AUTH_LDAP_DISPLAY_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-display-name
            - name: SKILLHUB_AUTH_LDAP_AUTHORITY
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-authority
            - name: SKILLHUB_AUTH_LDAP_URL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-url
            - name: SKILLHUB_AUTH_LDAP_START_TLS
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-start-tls
            - name: SKILLHUB_AUTH_LDAP_DIRECTORY_TYPE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-directory-type
            - name: SKILLHUB_AUTH_LDAP_BASE_DN
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-base-dn
            - name: SKILLHUB_AUTH_LDAP_USER_SEARCH_BASE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-user-search-base
            - name: SKILLHUB_AUTH_LDAP_USER_SEARCH_FILTER
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-user-search-filter
            - name: SKILLHUB_AUTH_LDAP_BIND_DN
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-bind-dn
            - name: SKILLHUB_AUTH_LDAP_BIND_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: ldap-bind-password
                  optional: true
            - name: SKILLHUB_AUTH_LDAP_SUBJECT_ATTRIBUTE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-subject-attribute
            - name: SKILLHUB_AUTH_LDAP_SUBJECT_TYPE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-subject-type
            - name: SKILLHUB_AUTH_LDAP_USERNAME_ATTRIBUTE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-username-attribute
            - name: SKILLHUB_AUTH_LDAP_DISPLAY_NAME_ATTRIBUTE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-display-name-attribute
            - name: SKILLHUB_AUTH_LDAP_EMAIL_ATTRIBUTE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-email-attribute
            - name: SKILLHUB_AUTH_LDAP_AVATAR_URL_ATTRIBUTE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-avatar-url-attribute
            - name: SKILLHUB_AUTH_LDAP_EMAIL_AUTHORITATIVE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-email-authoritative
            - name: SKILLHUB_AUTH_LDAP_CONNECT_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-connect-timeout
            - name: SKILLHUB_AUTH_LDAP_READ_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-read-timeout
            - name: SKILLHUB_AUTH_LDAP_POOL_WAIT_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-pool-wait-timeout
            - name: SKILLHUB_AUTH_LDAP_MAX_CONCURRENT_REQUESTS
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-max-concurrent-requests
            - name: SKILLHUB_AUTH_LDAP_MAX_ATTRIBUTE_VALUES
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-ldap-max-attribute-values

            # CAS 2.0/3.0 browser login
            - name: SKILLHUB_AUTH_CAS_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-enabled
            - name: SKILLHUB_AUTH_CAS_PROVIDER_CODE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-provider-code
            - name: SKILLHUB_AUTH_CAS_DISPLAY_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-display-name
            - name: SKILLHUB_AUTH_CAS_AUTHORITY
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-authority
            - name: SKILLHUB_AUTH_CAS_SERVER_URL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-server-url
            - name: SKILLHUB_AUTH_CAS_SERVICE_URL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-service-url
            - name: SKILLHUB_AUTH_CAS_PROTOCOL_VERSION
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-protocol-version
            - name: SKILLHUB_AUTH_CAS_SUBJECT_TYPE
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-subject-type
            - name: SKILLHUB_AUTH_CAS_CONNECT_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-connect-timeout
            - name: SKILLHUB_AUTH_CAS_READ_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-read-timeout
            - name: SKILLHUB_AUTH_CAS_STATE_TTL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-state-ttl
            - name: SKILLHUB_AUTH_CAS_MAX_RESPONSE_BYTES
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-max-response-bytes
            - name: SKILLHUB_AUTH_CAS_ATTRIBUTES_SUBJECT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-attribute-subject
            - name: SKILLHUB_AUTH_CAS_ATTRIBUTES_DISPLAY_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-attribute-display-name
            - name: SKILLHUB_AUTH_CAS_ATTRIBUTES_EMAIL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-attribute-email
            - name: SKILLHUB_AUTH_CAS_ATTRIBUTES_AVATAR_URL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-cas-attribute-avatar-url

            # DingTalk native OAuth2 browser login
            - name: SKILLHUB_AUTH_DINGTALK_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-enabled
            - name: OAUTH2_DINGTALK_DISPLAY_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-display-name
            - name: SKILLHUB_AUTH_DINGTALK_AUTHORITY
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-authority
            - name: SKILLHUB_AUTH_DINGTALK_CONNECT_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-connect-timeout
            - name: SKILLHUB_AUTH_DINGTALK_READ_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-read-timeout
            - name: SKILLHUB_AUTH_DINGTALK_MAX_RESPONSE_BYTES
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: auth-dingtalk-max-response-bytes

            # Bootstrap Admin (non-sensitive from ConfigMap)
            - name: BOOTSTRAP_ADMIN_ENABLED
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: bootstrap-admin-enabled
            - name: BOOTSTRAP_ADMIN_USER_ID
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: bootstrap-admin-user-id
            - name: BOOTSTRAP_ADMIN_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: bootstrap-admin-username
            - name: BOOTSTRAP_ADMIN_DISPLAY_NAME
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: bootstrap-admin-display-name
            - name: BOOTSTRAP_ADMIN_EMAIL
              valueFrom:
                configMapKeyRef:
                  name: skillhub-config
                  key: bootstrap-admin-email

            # Bootstrap Admin Password (sensitive from Secret)
            - name: BOOTSTRAP_ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: bootstrap-admin-password
                  optional: true

            # OAuth2 GitHub (optional)
            - name: OAUTH2_GITHUB_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: oauth2-github-client-id
                  optional: true
            - name: OAUTH2_GITHUB_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: oauth2-github-client-secret
                  optional: true

            # OAuth2 DingTalk (optional)
            - name: OAUTH2_DINGTALK_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: oauth2-dingtalk-client-id
                  optional: true
            - name: OAUTH2_DINGTALK_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: skillhub-secret
                  key: oauth2-dingtalk-client-secret
                  optional: true

          volumeMounts:
            - name: skillhub-storage
              mountPath: /var/lib/skillhub/storage
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: http
            initialDelaySeconds: 20
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: http
            initialDelaySeconds: 30
            periodSeconds: 15
      volumes:
        - name: skillhub-storage
          persistentVolumeClaim:
            claimName: skillhub-storage-pvc
