#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

PROJECT=${PROJECT:-""}
if [[ -z $PROJECT ]] ; then
  echo "expected PROJECT to be set" >&2
  exit 1
fi

INFRA_CONFIG_DIR=${INFRA_CONFIG_DIR:-""}
if [[ -z $INFRA_CONFIG_DIR ]] ; then
  echo "expected INFRA_CONFIG_DIR to be set" >&2
  exit 1
fi

cat << EOF > "${INFRA_CONFIG_DIR}/config.yaml"
server:
  manifestDirectoryPrefix: "${INFRA_CONFIG_DIR}"
configServiceUrl: http://config-service.gitops:8090
identityImage: gcr.io/pingcap-gardener/jenkins/gcp-web-identity:20201201
gardener:
  gardenerProjectName: nightly
  gardenBaseDomain: dev.shared.aws.tidbcloud.com
  kubeConfigPath: "${INFRA_CONFIG_DIR}/garden-kubeconfig.yaml"
  nodeImage: "centos-v20210420"
  storageNodeImage: "centos-tidb-v20210420"
import:
  skipBanMyBuckets: true
  centralRoleARN: TODO
crossplane:
  # default provider-aws by infra-api
  awsProviderName: provider-aws
  # default provider-gcp by infra-api
  gcpProviderName: provider-gcp
# make controller only watch object with the labels
predicate:
  matchExpressions:
  - key: "cloud.pingcap.com/reconciler"
    operator: "In"
    values:
    - ${PROJECT}
dns:
  publicHostedZoneDomain: clusters.dev.tidb-cloud.com
  publicHostedZoneID: Z001609810TV4E79YOP22
observabilityAgentConfig:
  openAPIAddress: "http://k8s-observab-globalin-22824fa614-584301555.us-west-2.elb.amazonaws.com"
  createO11yInfraPath: "/api/v1/clusters"
  deleteO11yInfraPath: "/api/v1/clusters"
  getO11yInfraPath: "/api/v1/clusters"
  pauseO11yInfraPath: "/api/v1/clusters"
  resumeO11yInfraPath: "/api/v1/clusters"
  auth0GetTokenURL: "https://tidb-soc2.us.auth0.com/oauth/token"
  auth0Audience: "https://tidb-soc2.us.auth0.com/api/v2/"
  effectiveRegion:
    - aws-us-west-2-*
    - gcp-us-west1-*
  version: 20221205
featureGates:
  tidb_expose_oom_path_for_new_cluster:
    all: true                   # enable for all tenants and projects
    # enabledProjects: [43562]    # enable for specific project
    # enabledTenants: [30060]     # enable for specific tenant
    # disabledProjects: [30060]     # disable for specific project
    # disabledTenants: [30060]     # disable for specific tenant
  tidb_expose_oom_path_for_existing_cluster:
    all: false
  tidb_expose_replayer_path_for_new_cluster:
    all: true
  tidb_expose_replayer_path_for_existing_cluster:
    all: false
EOF
