apiVersion: v1
kind: ConfigMap
metadata:
  name: jenkins-casc-config
data:
  jenkins.yaml: |
    jenkins:
      mode: EXCLUSIVE
      numExecutors: 0
      scmCheckoutRetryCount: 2
      disableRememberMe: true

      clouds:
        - kubernetes:
            name: "kubernetes"
            serverUrl: "https://kubernetes.default"
            skipTlsVerify: true
            namespace: "{{ .Values.Agent.WorkerNamespace }}"
            credentialsId: "k8s-service-account"
            jenkinsUrl: "http://{{template "jenkins.fullname" . }}.{{ .Release.Namespace }}:80"
            jenkinsTunnel: "{{ template "jenkins.fullname" . }}-agent.{{ .Release.Namespace }}:50000"
            containerCapStr: "2"
            connectTimeout: "60"
            readTimeout: "60"
            maxRequestsPerHostStr: "32"
            templates:
              - name: "base"
                namespace: "{{ .Values.Agent.WorkerNamespace }}"
                label: "base"
                nodeUsageMode: "NORMAL"
                idleMinutes: 0
                containers:
                - name: "base"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.Base.Image }}:{{ .Values.Agent.Builder.Base.Tag }}{{ template "jenkins.agent.variant" . }}"
                  command: "cat"
                  args: ""
                  ttyEnabled: true
                  privileged: {{ template "jenkins.agent.privileged" . }}
                  resourceRequestCpu: "100m"
                  resourceLimitCpu: "4000m"
                  resourceRequestMemory: "100Mi"
                  resourceLimitMemory: "8192Mi"
                - name: "jnlp"
                  image: "{{ .Values.Agent.Image }}:{{ .Values.Agent.ImageTag }}"
                  args: "^${computer.jnlpmac} ^${computer.name}"
                  resourceRequestCpu: "50m"
                  resourceLimitCpu: "500m"
                  resourceRequestMemory: "400Mi"
                  resourceLimitMemory: "1536Mi"
                workspaceVolume:
                  emptyDirWorkspaceVolume:
                    memory: false
                volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_sonar_cache"
                    mountPath: "/root/.sonar/cache"
                yaml: |
                  spec:
                    affinity:
                      nodeAffinity:
                        preferredDuringSchedulingIgnoredDuringExecution:
                        - weight: 1
                          preference:
                            matchExpressions:
                            - key: node-role.kubernetes.io/worker
                              operator: In
                              values:
                              - ci
                    tolerations:
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "NoSchedule"
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "PreferNoSchedule"
                    containers:
                    - name: "base"
                      resources:
                        requests:
                          ephemeral-storage: "1Gi"
                        limits:
                          ephemeral-storage: "10Gi"
                    securityContext:
                      fsGroup: 1000

              - name: "nodejs"
                namespace: "{{ .Values.Agent.WorkerNamespace }}"
                label: "nodejs"
                nodeUsageMode: "EXCLUSIVE"
                idleMinutes: 0
                containers:
                - name: "nodejs"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.NodeJs.Image }}:{{ .Values.Agent.Builder.NodeJs.Tag }}{{ template "jenkins.agent.variant" . }}"
                  command: "cat"
                  args: ""
                  ttyEnabled: true
                  privileged: {{ template "jenkins.agent.privileged" . }}
                  resourceRequestCpu: "100m"
                  resourceLimitCpu: "4000m"
                  resourceRequestMemory: "100Mi"
                  resourceLimitMemory: "8192Mi"
                - name: "jnlp"
                  image: "{{ .Values.Agent.Image }}:{{ .Values.Agent.ImageTag }}"
                  args: "^${computer.jnlpmac} ^${computer.name}"
                  resourceRequestCpu: "50m"
                  resourceLimitCpu: "500m"
                  resourceRequestMemory: "400Mi"
                  resourceLimitMemory: "1536Mi"
                workspaceVolume:
                  emptyDirWorkspaceVolume:
                    memory: false
                volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_nodejs_yarn_cache"
                    mountPath: "/root/.yarn"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_nodejs_npm_cache"
                    mountPath: "/root/.npm"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_sonar_cache"
                    mountPath: "/root/.sonar/cache"
                yaml: |
                  spec:
                    affinity:
                      nodeAffinity:
                        preferredDuringSchedulingIgnoredDuringExecution:
                        - weight: 1
                          preference:
                            matchExpressions:
                            - key: node-role.kubernetes.io/worker
                              operator: In
                              values:
                              - ci
                    tolerations:
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "NoSchedule"
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "PreferNoSchedule"
                    containers:
                    - name: "nodejs"
                      resources:
                        requests:
                          ephemeral-storage: "1Gi"
                        limits:
                          ephemeral-storage: "10Gi"
                    securityContext:
                      fsGroup: 1000

              - name: "maven"
                namespace: "{{ .Values.Agent.WorkerNamespace }}"
                label: "maven"
                nodeUsageMode: "EXCLUSIVE"
                idleMinutes: 0
                containers:
                - name: "maven"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.Maven.Image }}:{{ .Values.Agent.Builder.Maven.Tag }}{{ template "jenkins.agent.variant" . }}"
                  command: "cat"
                  args: ""
                  ttyEnabled: true
                  privileged: {{ template "jenkins.agent.privileged" . }}
                  resourceRequestCpu: "100m"
                  resourceLimitCpu: "4000m"
                  resourceRequestMemory: "100Mi"
                  resourceLimitMemory: "8192Mi"
                - name: "jnlp"
                  image: "{{ .Values.Agent.Image }}:{{ .Values.Agent.ImageTag }}"
                  args: "^${computer.jnlpmac} ^${computer.name}"
                  resourceRequestCpu: "50m"
                  resourceLimitCpu: "500m"
                  resourceRequestMemory: "400Mi"
                  resourceLimitMemory: "1536Mi"
                workspaceVolume:
                  emptyDirWorkspaceVolume:
                    memory: false
                volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_maven_cache"
                    mountPath: "/root/.m2"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_sonar_cache"
                    mountPath: "/root/.sonar/cache"
                yaml: |
                  spec:
                    affinity:
                      nodeAffinity:
                        preferredDuringSchedulingIgnoredDuringExecution:
                        - weight: 1
                          preference:
                            matchExpressions:
                            - key: node-role.kubernetes.io/worker
                              operator: In
                              values:
                              - ci
                    tolerations:
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "NoSchedule"
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "PreferNoSchedule"
                    containers:
                    - name: "maven"
                      resources:
                        requests:
                          ephemeral-storage: "1Gi"
                        limits:
                          ephemeral-storage: "10Gi"
                      volumeMounts:
                      - name: config-volume
                        mountPath: /opt/apache-maven-3.5.3/conf/settings.xml
                        subPath: settings.xml
                    volumes:
                      - name: config-volume
                        configMap:
                          name: ks-devops-agent
                          items:
                          - key: MavenSetting
                            path: settings.xml
                    securityContext:
                      fsGroup: 1000

              - name: "mavenjdk11"
                label: "jdk11 maven java"
                inheritFrom: "maven"
                containers:
                - name: "maven"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.mavenJDK11.image }}:{{ .Values.Agent.Builder.mavenJDK11.tag }}{{ template "jenkins.agent.variant" . }}"

              - name: "go"
                namespace: "{{ .Values.Agent.WorkerNamespace }}"
                label: "go"
                nodeUsageMode: "EXCLUSIVE"
                idleMinutes: 0
                containers:
                - name: "go"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.Golang.Image }}:{{ .Values.Agent.Builder.Golang.Tag }}{{ template "jenkins.agent.variant" . }}"
                  command: "cat"
                  args: ""
                  ttyEnabled: true
                  privileged: {{ template "jenkins.agent.privileged" . }}
                  resourceRequestCpu: "100m"
                  resourceLimitCpu: "4000m"
                  resourceRequestMemory: "100Mi"
                  resourceLimitMemory: "8192Mi"
                - name: "jnlp"
                  image: "{{ .Values.Agent.Image }}:{{ .Values.Agent.ImageTag }}"
                  args: "^${computer.jnlpmac} ^${computer.name}"
                  resourceRequestCpu: "50m"
                  resourceLimitCpu: "500m"
                  resourceRequestMemory: "400Mi"
                  resourceLimitMemory: "1536Mi"
                workspaceVolume:
                  emptyDirWorkspaceVolume:
                    memory: false
                volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_go_cache"
                    mountPath: "/home/jenkins/go/pkg"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_sonar_cache"
                    mountPath: "/root/.sonar/cache"
                yaml: |
                  spec:
                    affinity:
                      nodeAffinity:
                        preferredDuringSchedulingIgnoredDuringExecution:
                        - weight: 1
                          preference:
                            matchExpressions:
                            - key: node-role.kubernetes.io/worker
                              operator: In
                              values:
                              - ci
                    tolerations:
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "NoSchedule"
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "PreferNoSchedule"
                    containers:
                    - name: "go"
                      resources:
                        requests:
                          ephemeral-storage: "1Gi"
                        limits:
                          ephemeral-storage: "10Gi"
                    securityContext:
                      fsGroup: 1000

              - name: "go16"
                label: "go16"
                inheritFrom: "go"
                containers:
                - name: "go"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.golang16.image }}:{{ .Values.Agent.Builder.golang16.tag }}{{ template "jenkins.agent.variant" . }}"

              - name: "python"
                namespace: "{{ .Values.Agent.WorkerNamespace }}"
                label: "python"
                nodeUsageMode: "EXCLUSIVE"
                idleMinutes: 0
                containers:
                - name: "python"
                  image: "{{ .Values.Agent.Builder.Registry }}/{{ .Values.Agent.Builder.python.image }}:{{ .Values.Agent.Builder.python.tag }}{{ template "jenkins.agent.variant" . }}"
                  command: "cat"
                  args: ""
                  ttyEnabled: true
                  privileged: {{ template "jenkins.agent.privileged" . }}
                  resourceRequestCpu: "100m"
                  resourceLimitCpu: "4000m"
                  resourceRequestMemory: "100Mi"
                  resourceLimitMemory: "8192Mi"
                - name: "jnlp"
                  image: "{{ .Values.Agent.Image }}:{{ .Values.Agent.ImageTag }}"
                  args: "^${computer.jnlpmac} ^${computer.name}"
                  resourceRequestCpu: "50m"
                  resourceLimitCpu: "500m"
                  resourceRequestMemory: "400Mi"
                  resourceLimitMemory: "1536Mi"
                workspaceVolume:
                  emptyDirWorkspaceVolume:
                    memory: false
                volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_python_pip_cache"
                    mountPath: "/root/.cache/pip"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_python_pipenv_cache"
                    mountPath: "/root/.local/share/virtualenvs"
                - hostPathVolume:
                    hostPath: "/var/data/jenkins_sonar_cache"
                    mountPath: "/root/.sonar/cache"
                yaml: |
                  spec:
                    affinity:
                      nodeAffinity:
                        preferredDuringSchedulingIgnoredDuringExecution:
                        - weight: 1
                          preference:
                            matchExpressions:
                            - key: node-role.kubernetes.io/worker
                              operator: In
                              values:
                              - ci
                    tolerations:
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "NoSchedule"
                    - key: "node.kubernetes.io/ci"
                      operator: "Exists"
                      effect: "PreferNoSchedule"
                    containers:
                    - name: "python"
                      resources:
                        requests:
                          ephemeral-storage: "1Gi"
                        limits:
                          ephemeral-storage: "10Gi"
                    securityContext:
                      fsGroup: 1000

      securityRealm:
    {{- if eq .Values.securityRealm.type "ldap" }}
        ldap:
          configurations:
          - displayNameAttributeName: "uid"
            mailAddressAttributeName: "mail"
            inhibitInferRootDN: false
            managerDN: "cn=admin,dc=kubesphere,dc=io"
            managerPasswordSecret: "admin"
            rootDN: "dc=kubesphere,dc=io"
            userSearchBase: "ou=Users"
            userSearch: "(&(objectClass=inetOrgPerson)(|(uid={0})(mail={0})))"
            groupSearchBase: "ou=Groups"
            groupSearchFilter: "(&(objectClass=posixGroup)(cn={0}))"
            server: "ldap://{{.Values.securityRealm.ldap.host }}"
          disableMailAddressResolver: false
          disableRolePrefixing: true
    {{ else }}
      authorizationStrategy: loggedInUsersCanDoAnything
    {{- end }}

    unclassified:
      location:
        url: {{ .Values.Master.HostName }}
      kubespheretokenauthglobalconfiguration:
        cacheConfiguration:
          size: 20
          ttl: 300
        enabled: {{ .Values.ksAuth.enabled }}
        {{- if .Values.ksAuth.enabled }}
        {{- if .Values.ksAuth.server }}
        server: {{ .Values.ksAuth.server }}
        {{ else }}
        server: "http://{{ include "ks-devops.apiserver-fullname" . }}.{{ .Release.Namespace }}:9090/"
        {{- end }}
        {{- end }}
      eventDispatcher:
        receiver: "http://{{ include "ks-devops.apiserver-fullname" . }}.{{ .Release.Namespace }}:9090/v1alpha3/webhooks/jenkins"
      gitLabServers:
        servers:
        - name: "https://gitlab.com"
          serverUrl: "https://gitlab.com"
