apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: tidbcloud-org-runners-ksyun
  namespace: actions-runner-system
spec:
  template:
    spec:
      dockerdContainerResources: {}
      image: summerwind/actions-runner:latest
      imagePullPolicy: Always
      organization: tidbcloud
      # repository: tidbcloud/cicd-sample
      group: ksyun
      imagePullSecrets:
        - name: gcr-json-key
      resources:
        limits:
          cpu: 2
          memory: 7Gi
        requests:
          cpu: 1
          memory: 3Gi
      env:
        - name: AWS_WEB_IDENTITY_TOKEN_FILE
          value: /identity/token
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/google/key/gcp-jwt
      volumeMounts:
        - name: identity
          mountPath: /identity
        - name: gcp-jwt
          mountPath: /var/secrets/google/key
      volumes:
        - emptyDir: {}
          name: identity
        - name: gcp-jwt
          secret:
            secretName: gcp-jwt
      sidecarContainers:
        - env:
            - name: AWS_WEB_IDENTITY_TOKEN_FILE
              value: /identity/token
            # created & mounted through secrets
            - name: GOOGLE_APPLICATION_CREDENTIALS
              value: /var/secrets/google/key/gcp-jwt
            - name: GOOGLE_AUDIENCE
              value: "114667344163696279999"
          image: gcr.io/pingcap-dbaas-build/cicd/actions-runner/gcp-web-identity:20231108-ksyun
          imagePullPolicy: Always
          resources: {}
          name: auth
          volumeMounts:
            - mountPath: /identity
              name: identity
            - mountPath: /var/secrets/google/key
              name: gcp-jwt
      labels:
        - ksyun

---
apiVersion: actions.summerwind.dev/v1alpha1
kind: HorizontalRunnerAutoscaler
metadata:
  name: runner-deployment-autoscaler
spec:
  scaleTargetRef:
    kind: RunnerDeployment
    name: tidbcloud-org-runners-ksyun
  minReplicas: 1
  maxReplicas: 2
  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
