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

Nested pod templates inherit container of upper level pod

XMLWordPrintable

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

      kubernetes plugin version: 1.17.2

      When I run a podTemplate nested, it inherit the containers of the upper level podTemplate. It is a weird behaviour is better to explain it with an example

      Code:

      podTemplate(showRawYaml: true, label: "alpine1", cloud: "Build farm", containers: [
        containerTemplate(name: 'alpine', image: 'alpine', ttyEnabled: true, command: "cat")]) {
          node ("alpine1") {
              container('alpine') {
                  sh 'whoami'
                  podTemplate(showRawYaml: true, label: "golang", cloud: "Build farm", containers: [
                    containerTemplate(name: 'golang', image: 'golang', ttyEnabled: true, command: "cat")]) {
                    node ("golang") {
                      container('golang') {
                        sh 'sleep 120'
                      }
                    }
                  }
              }
          }
      } 

       

      Expected

      • alpine pod template containers: {jnlp} {alpine}
      • golang pod template containers: {jnlp} {golang}

      What I have:

      • alpine pod template containers: {jnlp} {alpine}
      • golang pod template containers: {jnlp} {golang} {alpine}

       

       Log(removed env variables):

       Still waiting to schedule task
      Waiting for next available executor on 'alpine1-dgpx2-5jp6k'
      Agent alpine1-prfs1-ghwvg is provisioned from template Kubernetes Pod Template
      ---
      apiVersion: "v1"
      kind: "Pod"
      metadata:
        annotations:
          buildUrl: "https://..."
        labels:
          jenkins: "slave"
          jenkins/alpine1: "true"
        name: "alpine1-prfs1-ghwvg"
      spec:
        containers:
        - command:
          - "cat"
          env:
          - name: "JENKINS_SECRET"
            ...
          image: "alpine"
          imagePullPolicy: "IfNotPresent"
          name: "alpine"
          resources:
            limits: {}
            requests: {}
          securityContext:
            privileged: false
          tty: true
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
          workingDir: "/home/jenkins"
        - env:
          - name: "JENKINS_SECRET"
            ...
          image: "jenkins/jnlp-slave:alpine"
          name: "jnlp"
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
        nodeSelector: {}
        restartPolicy: "Never"
        volumes:
        - emptyDir: {}
          name: "workspace-volume"
      
      Running on alpine1-prfs1-ghwvg in /home/jenkins/workspace/CII_test_pod_template_nest
      [Pipeline] {
      [Pipeline] container
      [Pipeline] {
      [Pipeline] sh
      + whoami
      root
      [Pipeline] podTemplate
      [Pipeline] {
      [Pipeline] node
      Still waiting to schedule task
      'golang-t6g4f-4tzqr' is offline
      Agent golang-t6g4f-4tzqr is provisioned from template Kubernetes Pod Template
      ---
      apiVersion: "v1"
      kind: "Pod"
      metadata:
        annotations:
          buildUrl: "https://..."
        labels:
          jenkins: "slave"
          jenkins/golang: "true"
        name: "golang-t6g4f-4tzqr"
      spec:
        containers:
        - command:
          - "cat"
          env:
          - name: "JENKINS_SECRET"
            ...
          image: "alpine"
          imagePullPolicy: "IfNotPresent"
          name: "alpine"
          resources:
            limits: {}
            requests: {}
          securityContext:
            privileged: false
          tty: true
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
          workingDir: "/home/jenkins"
        - command:
          - "cat"
          env:
          - name: "JENKINS_SECRET"
            ...
          image: "golang"
          imagePullPolicy: "IfNotPresent"
          name: "golang"
          resources:
            limits: {}
            requests: {}
          securityContext:
            privileged: false
          tty: true
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
          workingDir: "/home/jenkins"
        - env:
          - name: "JENKINS_SECRET"
            ...
          image: "jenkins/jnlp-slave:alpine"
          name: "jnlp"
          volumeMounts:
          - mountPath: "/home/jenkins"
            name: "workspace-volume"
            readOnly: false
        nodeSelector: {}
        restartPolicy: "Never"
        volumes:
        - emptyDir: {}
          name: "workspace-volume"
      
      Running on golang-t6g4f-4tzqr in /home/jenkins/workspace/CII_test_pod_template_nest
      [Pipeline] {
      [Pipeline] container
      [Pipeline] {
      [Pipeline] sh
      + sleep 120
      

       

       

       

       

            Unassigned Unassigned
            sermelo Sergio Merino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: