---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: gitlab-ci-runner
  labels:
    app: gitlab-ci-runner
spec:
  updateStrategy:
    type: RollingUpdate
  replicas: 1
  serviceName: gitlab-ci-runner
  selector:
    matchLabels:
      app: gitlab-ci-runner
  template:
    metadata:
      labels:
        app: gitlab-ci-runner
    spec:
      volumes:
        - name: gitlab-ci-runner-scripts
          projected:
            sources:
              - configMap:
                  name: gitlab-ci-runner-scripts
                  items:
                    - key: run.sh
                      path: run.sh
                      mode: 0755
      serviceAccountName: gitlab-ci
      securityContext:
        runAsNonRoot: true
        runAsUser: 999
        supplementalGroups: [999]
      containers:
        - image: gitlab/gitlab-runner:alpine-v13.10.0
          name: gitlab-ci-runner
          command:
            - /scripts/run.sh
          envFrom:
            - configMapRef:
                name: gitlab-ci-runner-cm
            - secretRef:
                name: gitlab-ci-token
          env:
            - name: RUNNER_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          ports:
            - containerPort: 9100
              name: http-metrics
              protocol: TCP
          volumeMounts:
            - name: gitlab-ci-runner-scripts
              mountPath: "/scripts"
              readOnly: true
      restartPolicy: Always
