global:
  imageRegistry: ""

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 200m
    cert-manager.io/cluster-issuer: "selfsigned-issuer" 
    cert-manager.io/duration: 8760h  
    cert-manager.io/renew-before: 720h
  hosts:
    - host: gitea.example.org
      paths:
        - path: /
          pathType: Prefix
  tls:
    - hosts:
        host: gitea.example.org
      secretName: gitea-tls-secret

# 사설 인증서를 사용 시 아래 내용 추가 
# keycloak의 인증서를 마운트한다.
extraVolumes:
 - name: keycloak-tls
   secret:
     secretName: platform

extraContainerVolumeMounts:
  - name: keycloak-tls
    mountPath: /etc/ssl/certs/ca.crt
    subPath: ca.crt

lifecycleHooks:
  postStart:
    exec:
      command: 
      - "/bin/sh"
      -  "-c"
      - |
        /bin/bash <<'EOF' > /tmp/post_start.log
        su git
        OAUTH_NAME='keycloak'
        AUTH_ID=$(gitea admin auth list --vertical-bars | grep -E "\|${OAUTH_NAME}\s+\|" | grep -iE '\|OAuth2\s+\|' | awk -F " "  "{print \$1}")
        KEYCLOAK_URL="https://keycloak.example.org"
        KEYCLOAK_CLIENT_ID="gitea"
        KEYCLOAK_SECRET='I5TeB3JV82PJjrqFdzsVdhZfCJhcZwNT'
        REALM=paasxpert
        if [[ -z "${AUTH_ID}" ]]; then
          echo "No oauth configuration found with name '${OAUTH_NAME}'. Installing it now..."
          gitea admin auth add-oauth --auto-discover-url "${KEYCLOAK_URL}/auth/realms/${REALM}/.well-known/openid-configuration" --key "${KEYCLOAK_CLIENT_ID}" --name "keycloak" --provider "openidConnect" --secret "${KEYCLOAK_SECRET}" 
          echo '...installed.'
        else
          echo "Existing oauth configuration with name '${OAUTH_NAME}': '${AUTH_ID}'. Running update to sync settings..."
          gitea admin auth update-oauth --id "${AUTH_ID}" --auto-discover-url "${KEYCLOAK_URL}/auth/realms/${REALM}/.well-known/openid-configuration" --key "${KEYCLOAK_CLIENT_ID}" --name "keycloak" --provider "openidConnect" --secret "${KEYCLOAK_SECRET}" 
          echo '...sync settings done.'
        fi
        EOF

## pod 설정
replicaCount: 1

resources:
  requests:
    cpu: 100m
    memory: 300Mi
  limits:
    cpu: 300m
    memory: 500Mi

persistence:
  enabled: true
  size: 10Gi
  storageClass: "longhorn"

## 같은 네임스페이스에 postgresql 배포 가정
gitea:
  admin:   
    username: sudouser
    password: password
    email: "sudouser@cro.com"
  config:
    APP_NAME: paasup git
    RUN_MODE: prod
    server:
      ROOT_URL: https://gitea.example.org
    service:
      DEFAULT_ALLOW_CREATE_ORGANIZATION: true
    repository:
      DEFAULT_BRANCH: master

postgresql:
  enabled: true
  global:
    postgresql:
      postgresqlDatabase: gitea
      postgresqlUsername: gitea
      postgresqlPassword: gitea
      servicePort: 5432
  persistence:
    size: 5Gi