kubernetesjenkinsgroovyjcasc

Jenkins JCASC Kubernetes plugin - Allow podTemplate to have YAML


I'm using Jenkins configuration as code (JCASC).

I'm having a pod template and I want to add NodeSelector + Tolerations. podTemplate doesn't support key of tolerations and NodeSelector so I need to add pod YAML spec...

      agent:
        enabled: true
        podTemplates:
     podTemplates:
          jenkins-slave-pod: |
            - name: jenkins-slave-pod
              label: global-slave
              serviceAccount: jenkins
              idleMinutes: "15"
              containers:
                - name: main
                  image: 'xxxxxx.dkr.ecr.us-west-2.amazonaws.com/jenkins-slave:ecs-global'
                  command: "sleep"
                  args: "30d"
                  privileged: true

I was thinking of adding yaml: and just configuring the spec of the pod... But when I'm adding yaml: and adding yamlStrategy: merge/overrid it ignores the YAML it and only uses my podTemplate instead.

How can I merge/override my podTemplate and add pod with tolerations/nodeSelecotr?

Thats the YAML I want to have inside my podTemplate:


          apiVersion: v1
          kind: Pod
          serviceAccount: jenkins-non-prod
          idleMinutes: "15"
          containers:
          - name: main
            image: 'xxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/jenkins-slave:ecs-global'
            command: "sleep"
            args: "30d"
            privileged: true
          spec:
            nodeSelector:
              karpenter.sh/provisioner-name: jenkins-provisioner
            tolerations:
            - key: "jenkins"
              operator: "Exists"
              effect: "NoSchedule"

enter image description here


Solution

  • I try to give you a little suggestion, let me know if it works.

    If you have an up&running Jenkins instance (with the Kubernetes plugin installed), you can go to “Manage Jenkins”/“Configure Clouds” and prepare your Pod Templates as you see fit. There you will also find the definition of nodeSelector and Toleration.

    Once you have saved the setup you prefer, go to “Manage Jenkins”/“Configuration as Code” and save the JCASC as Code configuration of your Jenkins (click “Download Configuration”).

    You can replicate this working mode for any new configuration you want to add to your Jenkins.