1

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

EilonA
  • 361
  • 5
  • 17

1 Answers1

1

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.

glv
  • 994
  • 1
  • 1
  • 15
  • I've tried it. And in the configuration it adds yaml: - yamls: | - two keys with the spec.. I tried deploying it with no success.. seems like its not accurate – EilonA Mar 16 '23 at 12:31
  • 1
    So after doing the change from UI and testing that it worked from there, you completely replaced your "local" JCASC by the Jenkins-generated one, right? What error do you get? – glv Mar 16 '23 at 12:38
  • No errors at all. It just show the RAW for YAML empty in the UI, and doesn't use my spec. I have added a new screen shot of how I added it.. it adds to keys of yaml and yamls in the configuration – EilonA Mar 20 '23 at 16:11
  • Anyone knows? adding two keys of yaml and yamls isn't working – EilonA Mar 28 '23 at 14:08
  • Fixed using yaml: configuration like suggested – EilonA Apr 09 '23 at 11:54