# A Kubernetes ConfigMap providing the configuration-as-code
# default config for Kubernetes plugin and an example job
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: jenkins-configuration-as-code
data:
  configuration-as-code.yaml: |
    unclassified:
      location:
        url: http://jenkins/
    jenkins:
      clouds:
        - kubernetes:
            name: "advanced-k8s-config"
            serverUrl: "https://advanced-k8s-config:443"
            skipTlsVerify: true
            namespace: "default"
            credentialsId: "advanced-k8s-credentials"
            jenkinsUrl: "http://jenkins/"
            connectTimeout: 0
            readTimeout: 0
            containerCapStr: 100
            maxRequestsPerHostStr: 64
            retentionTimeout: 5
            templates:
              - name: "k8s-agent"
                namespace: "default"
                label: "linux-x86_64"
                nodeUsageMode: EXCLUSIVE
                containers:
                  - name: "jnlp"
                    image: "jenkins/inbound-agent:latest"
                    alwaysPullImage: true
                    workingDir: "/home/jenkins"
                    ttyEnabled: true
                    resourceRequestCpu: "500m"
                    resourceLimitCpu: "1000m"
                    resourceRequestMemory: "1Gi"
                    resourceLimitMemory: "2Gi"
                volumes:
                  - emptyDirVolume:
                      memory: false
                      mountPath: "/tmp"
                idleMinutes: "1"
                activeDeadlineSeconds: "120"
                slaveConnectTimeout: "1000"
    credentials:
      system:
        domainCredentials:
          - credentials:
              - fileSystemServiceAccountCredential:
                  id: "advanced-k8s-credentials"
    jobs:
      - script: >
        pipelineJob('configuration-as-code') {
            definition {
                cps {
                    sandbox()
                    script("""
                      node('linux-x86_64') {
                          sh "hostname"
                      }
                    """.stripIndent())
                }
            }
        }
