apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: tidbcloud-org-runners
  namespace: actions-runner-system
spec:
  template:
    spec:
      dockerdContainerResources: {}
      image: ""
      imagePullPolicy: IfNotPresent
      organization: tidbcloud
      nodeSelector:
        cloud.google.com/gke-spot: "true"
        cicd/common-runner-resource: "true"
      resources:
        limits:
          cpu: 2
          memory: 7Gi
        requests:
          cpu: 1
          memory: 3Gi
      env:
        - name: AWS_WEB_IDENTITY_TOKEN_FILE
          value: /identity/token
        - name: AZURE_FEDERATED_TOKEN_FILE
          value: /var/run/secrets/azure/tokens/azure-identity-token
      volumeMounts:
        - name: identity
          mountPath: /identity
        - name: azure-identity-token
          mountPath: /var/run/secrets/azure/tokens
      volumes:
        - emptyDir: {}
          name: identity
        - emptyDir: {}
          name: azure-identity-token
      sidecarContainers:
        - env:
            - name: AWS_WEB_IDENTITY_TOKEN_FILE
              value: /identity/token
            - name: AZURE_FEDERATED_TOKEN_FILE
              value: /var/run/secrets/azure/tokens/azure-identity-token
          image: gcr.io/pingcap-dbaas-build/cicd/actions-runner/gcp-web-identity:20240902-gcp
          resources: {}
          name: auth
          volumeMounts:
            - mountPath: /identity
              name: identity
            - mountPath: /var/run/secrets/azure/tokens
              name: azure-identity-token
      labels:
        - gcp

---
apiVersion: actions.summerwind.dev/v1alpha1
kind: HorizontalRunnerAutoscaler
metadata:
  name: tidbcloud-org-runners
  namespace: actions-runner-system
spec:
  scaleTargetRef:
    name: tidbcloud-org-runners
  minReplicas: 25
  maxReplicas: 48
  scaleDownDelaySecondsAfterScaleOut: 60 # Runners in the targeted RunnerDeployment won't be scaled down for 1 minutes instead of the default 10 minutes now
  metrics:
    - type: PercentageRunnersBusy
      scaleUpThreshold: "0.75" # The percentage of busy runners at which the number of desired runners are re-evaluated to scale up
      scaleDownThreshold: "0.25" # The percentage of busy runners at which the number of desired runners are re-evaluated to scale down
      scaleUpAdjustment: 2 # The scale up runner count added to desired count
      scaleDownAdjustment: 2 # The scale down runner count subtracted from the desired count
  scaleUpTriggers:
    - githubEvent: # scales by [amount] replica for [duration] minutes on each check_run event with the type of [type] and the status of [status] received.
        checkRun:
          types: ["created"]
          status: "queued"
      amount: 2
      duration: "5m" # calculate if the replica number added via the trigger is expired or not

---
