# Source: jenkins/templates/jenkins-controller-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: jenkins
  namespace: jenkins-for-jx
  labels:
    "app.kubernetes.io/name": 'jenkins'
    "helm.sh/chart": "jenkins-3.3.16"
    "app.kubernetes.io/managed-by": "Helm"
    "app.kubernetes.io/instance": "jenkins"
    "app.kubernetes.io/component": "jenkins-controller"
    gitops.jenkins-x.io/pipeline: 'namespaces'
spec:
  serviceName: jenkins
  replicas: 1
  selector:
    matchLabels:
      "app.kubernetes.io/component": "jenkins-controller"
      "app.kubernetes.io/instance": "jenkins"
  template:
    metadata:
      labels:
        "app.kubernetes.io/name": 'jenkins'
        "app.kubernetes.io/managed-by": "Helm"
        "app.kubernetes.io/instance": "jenkins"
        "app.kubernetes.io/component": "jenkins-controller"
      annotations:
        checksum/config: ff70d80e5ca680529f6e2868a875049f2dacffd2cabbc66d13e4ff08df62fb53
    spec:
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
        runAsNonRoot: true
      serviceAccountName: "jenkins"
      initContainers:
        - name: "init"
          image: "jenkins/jenkins:2.277.4-jdk11"
          imagePullPolicy: "Always"
          command: ["sh", "/var/jenkins_config/apply_config.sh"]
          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /var/jenkins_home
              name: jenkins-home
            - mountPath: /var/jenkins_config
              name: jenkins-config
            - mountPath: /usr/share/jenkins/ref/plugins
              name: plugins
            - mountPath: /var/jenkins_plugins
              name: plugin-dir
      containers:
        - name: jenkins
          image: "jenkins/jenkins:2.277.4-jdk11"
          imagePullPolicy: "Always"
          args: ["--httpPort=8080"]
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: JAVA_OPTS
              value: "-Dcasc.reload.token=$(POD_NAME) "
            - name: JENKINS_OPTS
              value: ""
            - name: JENKINS_SLAVE_AGENT_PORT
              value: "50000"
            - name: CASC_JENKINS_CONFIG
              value: /var/jenkins_home/casc_configs
          ports:
            - containerPort: 8080
              name: http
            - containerPort: 50000
              name: agent-listener
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: '/login'
              port: http
            periodSeconds: 10
            timeoutSeconds: 5
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: '/login'
              port: http
            periodSeconds: 10
            timeoutSeconds: 5
          startupProbe:
            failureThreshold: 12
            httpGet:
              path: '/login'
              port: http
            periodSeconds: 10
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /var/jenkins_home
              name: jenkins-home
              readOnly: false
            - mountPath: /var/jenkins_config
              name: jenkins-config
              readOnly: true
            - mountPath: /usr/share/jenkins/ref/plugins/
              name: plugin-dir
              readOnly: false
            - name: sc-config-volume
              mountPath: /var/jenkins_home/casc_configs
            - name: admin-secret
              mountPath: /run/secrets/chart-admin-username
              subPath: jenkins-admin-user
              readOnly: true
            - name: admin-secret
              mountPath: /run/secrets/chart-admin-password
              subPath: jenkins-admin-password
              readOnly: true
        - name: config-reload
          image: "kiwigrid/k8s-sidecar:0.1.275"
          imagePullPolicy: IfNotPresent
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: LABEL
              value: "jenkins-jenkins-config"
            - name: FOLDER
              value: "/var/jenkins_home/casc_configs"
            - name: NAMESPACE
              value: 'jenkins-for-jx'
            - name: REQ_URL
              value: "http://localhost:8080/reload-configuration-as-code/?casc-reload-token=$(POD_NAME)"
            - name: REQ_METHOD
              value: "POST"
            - name: REQ_RETRY_CONNECT
              value: "10"
          resources: {}
          volumeMounts:
            - name: sc-config-volume
              mountPath: "/var/jenkins_home/casc_configs"
            - name: jenkins-home
              mountPath: /var/jenkins_home
      volumes:
        - name: plugins
          emptyDir: {}
        - name: jenkins-config
          configMap:
            name: jenkins
        - name: plugin-dir
          emptyDir: {}
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: jenkins
        - name: sc-config-volume
          emptyDir: {}
        - name: admin-secret
          secret:
            secretName: jenkins
