apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    helm.sh/chart: gitea-actions-0.1.1
    app: gitea-actions-runner
    app.kubernetes.io/name: gitea-actions-runner
    app.kubernetes.io/instance: gitea
    app.kubernetes.io/version: "0.261.3"
    version: "0.261.3"
    app.kubernetes.io/managed-by: Helm
  annotations:
  name: gitea-runner
  namespace: gitea
spec:
  replicas: 6
  selector:
    matchLabels:
      app.kubernetes.io/name: gitea-actions-runner
      app.kubernetes.io/instance: gitea
  template:
    metadata:
      annotations:
        checksum/config: 8f137fabf2c2a2839dc3bfbd54773ef5409b100d0771ab49b37262f52a0a3ecc
      labels:
        helm.sh/chart: gitea-actions-0.1.1
        app: gitea-actions-runner
        app.kubernetes.io/name: gitea-actions-runner
        app.kubernetes.io/instance: gitea
        app.kubernetes.io/version: "0.261.3"
        version: "0.261.3"
        app.kubernetes.io/managed-by: Helm
    spec:
      restartPolicy: Always
      initContainers:
        - name: init-gitea
          image: "docker.io/busybox:1.37.0@sha256:1487d0af5f52b4ba31c7e465126ee2123fe3f2305d638e7827681e7cf6c83d5e"
          command:
            - sh
            - -c
            - |
              echo 'Trying to reach Gitea on http://gitea-http.gitea:3000'
              until timeout 10 wget --no-check-certificate --spider http://gitea-http.gitea:3000; do
                sleep 3
                echo "Trying again in 3 seconds..."
              done
              echo "Gitea has been reached!"
        - name: dind
          image: "docker.io/docker:29.5.2-dind@sha256:6b9cd914eb9c6b342c040a49a27a5eb3804453bae6ecc90f7ff96133595a95e8"
          restartPolicy: Always
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          startupProbe:
            exec:
              command:
                - /usr/bin/test
                - -S
                - /var/run/docker.sock
          livenessProbe:
            exec:
              command:
                - /usr/bin/test
                - -S
                - /var/run/docker.sock
          resources:
            limits:
              ephemeral-storage: 15Gi
            requests:
              ephemeral-storage: 2Gi
          volumeMounts:
            - mountPath: /var/run/
              name: docker-socket
            - mountPath: /var/lib/docker
              name: docker-vol
      containers:
        - name: runner
          image: "docker.io/gitea/runner:1.0.6@sha256:ab581a3e1a260efa0521886ad8051f0e8c4ff1f1d52aa8ef0a2e3ad7465f8b74"
          imagePullPolicy: IfNotPresent
          workingDir: /data
          env:
            - name: GITEA_RUNNER_REGISTRATION_TOKEN
              valueFrom:
                secretKeyRef:
                  name: "gitea-runner-secret"
                  key: "token"
            - name: GITEA_INSTANCE_URL
              value: http://gitea-http.gitea:3000
            - name: CONFIG_FILE
              value: /runner/config.yaml
            - name: TZ
              value: America/Chicago
          resources:
            limits:
              ephemeral-storage: 15Gi
            requests:
              ephemeral-storage: 2Gi
          volumeMounts:
            - mountPath: /runner/config.yaml
              name: runner-config
              subPath: config.yaml
            - mountPath: /var/run/docker.sock
              name: docker-socket
              subPath: docker.sock
            - mountPath: /data
              name: data-runner
            - mountPath: /workspace
              name: workspace-vol
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app.kubernetes.io/name
                      operator: In
                      values:
                        - gitea-actions-act-runner
                topologyKey: kubernetes.io/hostname
              weight: 100
      volumes:
        - name: runner-config
          configMap:
            name: gitea-runner-configmap
        - name: docker-socket
          emptyDir: {}
        - ephemeral:
            volumeClaimTemplate:
              spec:
                accessModes:
                  - ReadWriteOnce
                resources:
                  requests:
                    storage: 20Gi
                storageClassName: ceph-block
          name: workspace-vol
        - ephemeral:
            volumeClaimTemplate:
              spec:
                accessModes:
                  - ReadWriteOnce
                resources:
                  requests:
                    storage: 50Gi
                storageClassName: ceph-block
          name: docker-vol
  volumeClaimTemplates:
    - metadata:
        name: data-runner
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi
