Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-64787

YAML Merge/Combine doesn't honor all Pod spec fields

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • kubernetes-plugin
    • None

      Only some specific fields are taken into account during merge. Only some specific child Pod fields are merged into resulting Pod but other may exists (e.g. host aliases)

      Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#podspec-v1-core

      Location: https://github.com/jenkinsci/kubernetes-plugin/blob/ba1e934d2143f05c432c1941989af73b8b443a89/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateUtils.java#L293

       

      Example:

      pipeline {
          agent {
              kubernetes {
                  inheritFrom 'default'
                  yamlMergeStrategy: merge(),
                  yaml """
      spec:
          hostAliases:
            - ip: 10.0.0.1
              hostnames:
                - some.virtualized.service.company.com
      """
              }
          }
      
          stages {
              stage('Main') {
                  steps {
                      script {
                          # Better to see build logs with generated YAML
                          sh 'cat /etc/hosts'
                      }
                  }
              }
          }
      }

      Host aliases are lost but if inheritance is disabled, field is kept.

            Unassigned Unassigned
            loganmzz Logan Mzz
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: