# Source: jenkins/templates/jenkins-master-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: jx
  labels:
    "app.kubernetes.io/name": 'jenkins'
    "helm.sh/chart": "jenkins-2.6.4"
    "app.kubernetes.io/managed-by": "Helm"
    "app.kubernetes.io/instance": "jenkins"
    "app.kubernetes.io/component": "jenkins-master"
    gitops.jenkins-x.io/pipeline: 'namespaces'
  annotations:
    wave.pusher.com/update-on-config-change: 'true'
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      "app.kubernetes.io/component": "jenkins-master"
      "app.kubernetes.io/instance": "jenkins"
  template:
    metadata:
      labels:
        "app.kubernetes.io/name": 'jenkins'
        "helm.sh/chart": "jenkins-2.6.4"
        "app.kubernetes.io/managed-by": "Helm"
        "app.kubernetes.io/instance": "jenkins"
        "app.kubernetes.io/component": "jenkins-master"
      annotations:
        checksum/config: b05abd5535906f472a097cd69309dfa622a30d6387bcfbe34353cb635db79843
    spec:
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
      serviceAccountName: "jenkins"
      initContainers:
        - name: "copy-default-config"
          image: "jenkins/jenkins:lts"
          imagePullPolicy: "Always"
          command: ["sh", "/var/jenkins_config/apply_config.sh"]
          env:
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: jenkins
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: jenkins
                  key: jenkins-admin-user
          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /var/jenkins_home
              name: jenkins-home
            - mountPath: /var/jenkins_config
              name: jenkins-config
            - mountPath: /var/jenkins_jobs
              name: jenkins-jobs
              readOnly: true
            - mountPath: /usr/share/jenkins/ref/secrets/
              name: secrets-dir
            - mountPath: /usr/share/jenkins/ref/plugins
              name: plugins
            - mountPath: /var/jenkins_plugins
              name: plugin-dir
      containers:
        - name: jenkins
          image: "jenkins/jenkins:lts"
          imagePullPolicy: "Always"
          args: ["--argumentsRealm.passwd.$(ADMIN_USER)=$(ADMIN_PASSWORD)", "--argumentsRealm.roles.$(ADMIN_USER)=admin", "--httpPort=8080"]
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: JAVA_OPTS
              value: "\n-Dcasc.reload.token=$(POD_NAME) \n"
            - name: JENKINS_OPTS
              value: ""
            - name: JENKINS_SLAVE_AGENT_PORT
              value: "50000"
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: jenkins
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: jenkins
                  key: jenkins-admin-user
            - name: CASC_JENKINS_CONFIG
              value: /var/jenkins_home/casc_configs
          ports:
            - containerPort: 8080
              name: http
            - containerPort: 50000
              name: slavelistener
          livenessProbe:
            httpGet:
              path: "/login"
              port: http
            initialDelaySeconds: 90
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 5
          readinessProbe:
            httpGet:
              path: "/login"
              port: http
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /var/jenkins_home
              name: jenkins-home
              readOnly: false
            - mountPath: /var/jenkins_config
              name: jenkins-config
              readOnly: true
            - mountPath: /var/jenkins_jobs
              name: jenkins-jobs
              readOnly: true
            - mountPath: /usr/share/jenkins/ref/secrets/
              name: secrets-dir
              readOnly: false
            - mountPath: /usr/share/jenkins/ref/plugins/
              name: plugin-dir
              readOnly: false
            - name: sc-config-volume
              mountPath: /var/jenkins_home/casc_configs
        - name: jenkins-sc-config
          image: "kiwigrid/k8s-sidecar:0.1.193"
          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: "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: tmp
          emptyDir: {}
        - name: jenkins-config
          configMap:
            name: jenkins
        - name: jenkins-jobs
          configMap:
            name: jenkins-jobs
        - name: secrets-dir
          emptyDir: {}
        - name: plugin-dir
          emptyDir: {}
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: jenkins
        - name: sc-config-volume
          emptyDir: {}
