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

Unable to run pods in parallel due to template nesting

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • kubernetes-plugin
    • None
    • Jenkins v2.44
      Kubernetes Plugin v0.10
      Openshift v1.3.0

      Creating multiple podTemplates with different labels allows you to create pods in parallel.

      However the plugin treats all podTemplates in a Run as nested even when they are not. Every podTemplate in the pipeline effectively inherits from previously declared templates.

      Consider the following pipeline.

      stage ('Compile') {
      	podTemplate(label: 'node-0',
      		containers: [containerTemplate(name: 'maven', ...)])
      	{
      	    node('node-0') {
      			container('maven') {
      			    sleep(1)
      			}
      	 	}
      	}
      }
      stage ('Tests') {
          parallel ( 
              "A":  { 
                  podTemplate(label: 'node-a',
      			containers: [containerTemplate(name: 'maven', ...)]))
         	            {
      		           node('node-a') {
      			         container('maven') {		  
        		                sleep (15)
      	                 }
      					}
      				}
              },
               "B": {
      			podTemplate(label: 'node-b',
      			containers: [containerTemplate(name: 'maven', ...)]))
      			{
      					node('node-b') {
      						container('maven') {
      							sleep (15)
      						}
      					}		
      			}
      		}
      	)
      }
      

      This creates a template for node-a that inherits from node-0 and a template for node-b that inherits from both node-a and node-0. Keep adding pod templates and they keep nesting in weird ways.

      Depending on the nesting rules and the names used on each template some containers get created while others don't. The behaviour becomes quite erratic. e.g. I'm seeing the HOME var of one container being set to the start-up command of another (HOME='/bin/sh -c').

      In any case the intention of the pipeline developer here clearly isn't to nest templates.

      The hacky workaround to stop this is to clear all previously stacked template names from the Run before creating a new template.

      Call this function before any occurrence of podTemplate:

      @NonCPS
      def clearTemplateNames() {
      def r = script.currentBuild.rawBuild
      def action = r.getAction(PodTemplateAction.class);
      if(action)

      { action.names.clear() }

      }

            Unassigned Unassigned
            lionelve Lionel Orellana
            Votes:
            4 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved: