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

yamlMergeStrategy merge() doesn't inherit volume mounts from parent pod template

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

      Agent declaration with yaml template: 

      inheritFrom 'k8s-dind'
      yamlMergeStrategy merge()
      yaml """
        apiVersion: v1
        kind: Pod
        spec:
         containers:
         - name: apaasdevops
           image: <repo_URL>/apaas/apaas-devops:1.20
           workingDir: /home/jenkins
           command: ['cat']
           tty: true
      """
      

      Agent declaration with container template: 

      inheritFrom 'k8s-dind'
      containerTemplate {
         name 'apaasdevops'
         image '<repo_name>/apaas/apaas-devops:1.20'
         workingDir '/home/jenkins'
         ttyEnabled true
         command 'cat'
         args ''
      }
      

       

      Container templates inherit the env and volume mounts from parent pod as shown below

      spec:
        containers:
        - command:
          - "cat"
          env:
          - name: "DOCKER_HOST"
            value: "tcp://<IP_ADDRESS>"
          image: "*****/apaas/apaas-devops:1.20"
          imagePullPolicy: "IfNotPresent"
          name: "apaasdevops"
          resources:
            limits: {}
            requests: {}
          securityContext:
            privileged: false
          tty: true
          volumeMounts:
          - mountPath: "/var/lib/docker"
            name: "volume-0"
            readOnly: false
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
          workingDir: "/home/jenkins"
        - args:
          - "-disableHttpsCertValidation"
          - "********"

      But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent

      spec:
        containers:
        - command:
          - "cat"
          image: "*****/apaas/apaas-devops:1.20"
          name: "apaasdevops"
          tty: true
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
          workingDir: "/home/jenkins"
        - args:
          - "-disableHttpsCertValidation"
          - "********"

       kubernetes plugin used is 1.25.4 version

      Below volume mount is configured in parent pod 'k8s-dind' which is not getting inherited in yaml template but gets inherited in container template

      - mountPath: "/var/lib/docker" 
        name: "volume-0" 
        readOnly: false
      

       

       

          [JENKINS-64599] yamlMergeStrategy merge() doesn't inherit volume mounts from parent pod template

          Apoorva created issue -
          Apoorva made changes -
          Description Original: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           

           
          New: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           kubernetes plugin used is [1.25.4|https://build1-stg.cci.nokia.net/pluginManager/plugin/kubernetes/thirdPartyLicenses] version

           
          Apoorva made changes -
          Description Original: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           kubernetes plugin used is [1.25.4|https://build1-stg.cci.nokia.net/pluginManager/plugin/kubernetes/thirdPartyLicenses] version

           
          New: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           kubernetes plugin used is 1.25.4 version

           
          Apoorva made changes -
          Description Original: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           kubernetes plugin used is 1.25.4 version

           
          New: Agent declaration with yaml template: 
          {code:java}
          inheritFrom 'k8s-dind'
          yamlMergeStrategy merge()
          yaml """
            apiVersion: v1
            kind: Pod
            spec:
             containers:
             - name: apaasdevops
               image: <repo_URL>/apaas/apaas-devops:1.20
               workingDir: /home/jenkins
               command: ['cat']
               tty: true
          """
          {code}
          Agent declaration with container template: 
          {code:java}
          inheritFrom 'k8s-dind'
          containerTemplate {
             name 'apaasdevops'
             image '<repo_name>/apaas/apaas-devops:1.20'
             workingDir '/home/jenkins'
             ttyEnabled true
             command 'cat'
             args ''
          }
          {code}
           

          Container templates inherit the env and volume mounts from parent pod as shown below
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              env:
              - name: "DOCKER_HOST"
                value: "tcp://&lt;IP_ADDRESS>"
              image: "*****/apaas/apaas-devops:1.20"
              imagePullPolicy: "IfNotPresent"
              name: "apaasdevops"
              resources:
                limits: {}
                requests: {}
              securityContext:
                privileged: false
              tty: true
              volumeMounts:
              - mountPath: "/var/lib/docker"
                name: "volume-0"
                readOnly: false
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
          But yaml template is not not inheriting volume mounts and env even though yamlMergeStrategy merge() is used while defining agent
          {noformat}
          spec:
            containers:
            - command:
              - "cat"
              image: "*****/apaas/apaas-devops:1.20"
              name: "apaasdevops"
              tty: true
              volumeMounts:
              - mountPath: "/home/jenkins"
                name: "workspace-volume"
                readOnly: false
              workingDir: "/home/jenkins"
            - args:
              - "-disableHttpsCertValidation"
              - "********"{noformat}
           kubernetes plugin used is 1.25.4 version

          Below volume mount is configured in parent pod 'k8s-dind' {color:#172b4d}which is not getting inherited in yaml template but gets inherited in container template{color}
          {code:java}
          - mountPath: "/var/lib/docker"
            name: "volume-0"
            readOnly: false
          {code}
           

           

            Unassigned Unassigned
            appu Apoorva
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: