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

vSphere plugin not respecting or saving per slave instance Cap

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • vsphere-cloud-plugin
    • None
    • Jenkins 2.14
      vSphere Plugin 2.14

      Even though the vSphere configuration for dynamic slaves has a field for setting a per slave instance cap, that cap is not honored and does not seem to actually be saved in the config.xml file.

      In my slave definition, I set the slave instance cap to 2. But in the Jenkins log, I was finding this:
      There are 0 number of VMs with the prefix UbuntuSlave-1. The instance cap for VMs with that prefix is: 2147483647

      When I looked at the definition in the config.xml for the cloud, you can see that there is no per instance cap in the config.

      My instance cap globally is 2 slaves that should be started. That is not honored either. It seems to limit the number of slaves actually used for builds, but then it seems to actually generate more slaves that that. I will attach the xml snippet from config, and a screenshot of what happened for the number of slaves generated.

          [JENKINS-36878] vSphere plugin not respecting or saving per slave instance Cap

          Greg Smith added a comment -

          XML Snippet of slave configuration. Note, the instance cap of 2 per slave is not in this configuration in the templates for the individual slave types:

          <clouds>
          <org.jenkinsci.plugins.vSphereCloud plugin="vsphere-cloud@2.13">
          <name>vSphereCloud</name>
          <vsDescription>Corp VC</vsDescription>
          <maxOnlineSlaves>2</maxOnlineSlaves>
          <vsConnectionConfig>
          <vsHost>https://redacted.com</vsHost>
          <credentialsId>df687fdb-ed89-4f9e-aa38-f3de8f40c79f</credentialsId>
          </vsConnectionConfig>
          <instanceCap>3</instanceCap>
          <templates>
          <org.jenkinsci.plugins.vSphereCloudSlaveTemplate>
          <cloneNamePrefix>Windows10Slave-1</cloneNamePrefix>
          <masterImageName>base-win10-1</masterImageName>
          <snapshotName></snapshotName>
          <linkedClone>true</linkedClone>
          <cluster></cluster>
          <resourcePool>BuildSlaves</resourcePool>
          <datastore></datastore>
          <templateDescription></templateDescription>
          <numberOfExecutors>1</numberOfExecutors>
          <remoteFS>/cygdrive/c/Users/Tanium</remoteFS>
          <labelString>windows10</labelString>
          <mode>EXCLUSIVE</mode>
          <forceVMLaunch>true</forceVMLaunch>
          <waitForVMTools>true</waitForVMTools>
          <launchDelay>10</launchDelay>
          <limitedRunCount>1</limitedRunCount>
          <saveFailure>false</saveFailure>
          <credentialsId>849621ed-4001-46ba-ad2c-b3b34248d2f9</credentialsId>
          <nodeProperties/>
          <POWER_ON>true</POWER_ON>
          </org.jenkinsci.plugins.vSphereCloudSlaveTemplate>
          <org.jenkinsci.plugins.vSphereCloudSlaveTemplate>
          <cloneNamePrefix>UbuntuSlave-1</cloneNamePrefix>
          <masterImageName>ubuntu-14.04-amd64</masterImageName>
          <snapshotName></snapshotName>
          <linkedClone>true</linkedClone>
          <cluster></cluster>
          <resourcePool>BuildSlaves</resourcePool>
          <datastore></datastore>
          <templateDescription></templateDescription>
          <numberOfExecutors>1</numberOfExecutors>
          <remoteFS>/home/vagrant</remoteFS>
          <labelString>ubuntu1404</labelString>
          <mode>EXCLUSIVE</mode>
          <forceVMLaunch>true</forceVMLaunch>
          <waitForVMTools>true</waitForVMTools>
          <launchDelay>10</launchDelay>
          <limitedRunCount>1</limitedRunCount>
          <saveFailure>false</saveFailure>
          <credentialsId>7e5ce264-01ce-4b73-915e-87cc7263ca4b</credentialsId>
          <nodeProperties/>
          <POWER_ON>true</POWER_ON>
          </org.jenkinsci.plugins.vSphereCloudSlaveTemplate>
          </templates>
          </org.jenkinsci.plugins.vSphereCloud>
          </clouds>

          Greg Smith added a comment - XML Snippet of slave configuration. Note, the instance cap of 2 per slave is not in this configuration in the templates for the individual slave types: <clouds> <org.jenkinsci.plugins.vSphereCloud plugin="vsphere-cloud@2.13"> <name>vSphereCloud</name> <vsDescription>Corp VC</vsDescription> <maxOnlineSlaves>2</maxOnlineSlaves> <vsConnectionConfig> <vsHost> https://redacted.com </vsHost> <credentialsId>df687fdb-ed89-4f9e-aa38-f3de8f40c79f</credentialsId> </vsConnectionConfig> <instanceCap>3</instanceCap> <templates> <org.jenkinsci.plugins.vSphereCloudSlaveTemplate> <cloneNamePrefix>Windows10Slave-1</cloneNamePrefix> <masterImageName>base-win10-1</masterImageName> <snapshotName></snapshotName> <linkedClone>true</linkedClone> <cluster></cluster> <resourcePool>BuildSlaves</resourcePool> <datastore></datastore> <templateDescription></templateDescription> <numberOfExecutors>1</numberOfExecutors> <remoteFS>/cygdrive/c/Users/Tanium</remoteFS> <labelString>windows10</labelString> <mode>EXCLUSIVE</mode> <forceVMLaunch>true</forceVMLaunch> <waitForVMTools>true</waitForVMTools> <launchDelay>10</launchDelay> <limitedRunCount>1</limitedRunCount> <saveFailure>false</saveFailure> <credentialsId>849621ed-4001-46ba-ad2c-b3b34248d2f9</credentialsId> <nodeProperties/> <POWER_ ON>true</POWER _ON> </org.jenkinsci.plugins.vSphereCloudSlaveTemplate> <org.jenkinsci.plugins.vSphereCloudSlaveTemplate> <cloneNamePrefix>UbuntuSlave-1</cloneNamePrefix> <masterImageName>ubuntu-14.04-amd64</masterImageName> <snapshotName></snapshotName> <linkedClone>true</linkedClone> <cluster></cluster> <resourcePool>BuildSlaves</resourcePool> <datastore></datastore> <templateDescription></templateDescription> <numberOfExecutors>1</numberOfExecutors> <remoteFS>/home/vagrant</remoteFS> <labelString>ubuntu1404</labelString> <mode>EXCLUSIVE</mode> <forceVMLaunch>true</forceVMLaunch> <waitForVMTools>true</waitForVMTools> <launchDelay>10</launchDelay> <limitedRunCount>1</limitedRunCount> <saveFailure>false</saveFailure> <credentialsId>7e5ce264-01ce-4b73-915e-87cc7263ca4b</credentialsId> <nodeProperties/> <POWER_ ON>true</POWER _ON> </org.jenkinsci.plugins.vSphereCloudSlaveTemplate> </templates> </org.jenkinsci.plugins.vSphereCloud> </clouds>

          pjdarton added a comment -

          I've been doing some digging and the issue goes much deeper than just the problems with the configuration.
          Even after fixing the configuration load/save issues so that the code knows what the instance cap should be, it still doesn't obey it. This is because it doesn't keep track of what slaves it has kicked off, and it doesn't seem to be able to count the number within vSphere, so each time Jenkins asks for more, it initiates the cloning of more slaves (until the slaves start coming online and providing the capacity that Jenkins is asking for, at which point Jenkins stops asking for more).
          I've got some a local build which fixes that, but it's a non-trivial change.

          pjdarton added a comment - I've been doing some digging and the issue goes much deeper than just the problems with the configuration. Even after fixing the configuration load/save issues so that the code knows what the instance cap should be, it still doesn't obey it. This is because it doesn't keep track of what slaves it has kicked off, and it doesn't seem to be able to count the number within vSphere, so each time Jenkins asks for more, it initiates the cloning of more slaves (until the slaves start coming online and providing the capacity that Jenkins is asking for, at which point Jenkins stops asking for more). I've got some a local build which fixes that, but it's a non-trivial change.

          pjdarton added a comment -

          OK, pull request https://github.com/jenkinsci/vsphere-cloud-plugin/pull/48 has been issued.

          We've been using this code here@work for a while now and it seems solid.
          (although I did add unit-tests for some bits).

          pjdarton added a comment - OK, pull request https://github.com/jenkinsci/vsphere-cloud-plugin/pull/48 has been issued. We've been using this code here@work for a while now and it seems solid. (although I did add unit-tests for some bits).

          Code changed in jenkins
          User: Peter Darton
          Path:
          src/main/java/org/jenkinsci/plugins/vSphereCloud.java
          src/main/java/org/jenkinsci/plugins/vSphereCloudProvisionedSlave.java
          src/main/java/org/jenkinsci/plugins/vSphereCloudSlaveTemplate.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningRecord.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningState.java
          src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java
          src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningStateTest.java
          http://jenkins-ci.org/commit/vsphere-cloud-plugin/4310c6cfa453fe59882406c821f0bb0c61173d26
          Log:
          Bugfix: JENKINS-36878: vSphere now respects per-slave instance cap.
          Bugfix: JENKINS-32112: NPE bug in vSphere.getTemplate().
          Enhancement: vSphere.java now distributes load over all matching
          templates. This satisfies JENKINS-30203 if Jenkins is configured with a
          template.
          Correction: Jenkins UI no longer offers facility to manually create a
          Cloud-provisioned slave (the cloud provisions those itself). Normal
          vSphere slaves are still manually provisionable.
          Cleaned up logging in vSphere.java.
          Typo in vSphereCloudSlaveTemplate: getNumberOfExceutors ->
          getNumberOfExecutors.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Peter Darton Path: src/main/java/org/jenkinsci/plugins/vSphereCloud.java src/main/java/org/jenkinsci/plugins/vSphereCloudProvisionedSlave.java src/main/java/org/jenkinsci/plugins/vSphereCloudSlaveTemplate.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningRecord.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningState.java src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningStateTest.java http://jenkins-ci.org/commit/vsphere-cloud-plugin/4310c6cfa453fe59882406c821f0bb0c61173d26 Log: Bugfix: JENKINS-36878 : vSphere now respects per-slave instance cap. Bugfix: JENKINS-32112 : NPE bug in vSphere.getTemplate(). Enhancement: vSphere.java now distributes load over all matching templates. This satisfies JENKINS-30203 if Jenkins is configured with a template. Correction: Jenkins UI no longer offers facility to manually create a Cloud-provisioned slave (the cloud provisions those itself). Normal vSphere slaves are still manually provisionable. Cleaned up logging in vSphere.java. Typo in vSphereCloudSlaveTemplate: getNumberOfExceutors -> getNumberOfExecutors.

          Code changed in jenkins
          User: Jason Swager
          Path:
          src/main/java/org/jenkinsci/plugins/vSphereCloud.java
          src/main/java/org/jenkinsci/plugins/vSphereCloudLauncher.java
          src/main/java/org/jenkinsci/plugins/vSphereCloudProvisionedSlave.java
          src/main/java/org/jenkinsci/plugins/vSphereCloudSlaveTemplate.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningRecord.java
          src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningState.java
          src/main/resources/org/jenkinsci/plugins/vSphereCloudSlaveTemplate/config.jelly
          src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java
          src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningStateTest.java
          http://jenkins-ci.org/commit/vsphere-cloud-plugin/1e87f49a9aeda83f9c0a0306fc4bad6bacff403b
          Log:
          Merge pull request #48 from pjdarton/fix_jenkins_36878

          Fix JENKINS-36878 and JENKINS-32112

          Compare: https://github.com/jenkinsci/vsphere-cloud-plugin/compare/19e12f7c00ca...1e87f49a9aed

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jason Swager Path: src/main/java/org/jenkinsci/plugins/vSphereCloud.java src/main/java/org/jenkinsci/plugins/vSphereCloudLauncher.java src/main/java/org/jenkinsci/plugins/vSphereCloudProvisionedSlave.java src/main/java/org/jenkinsci/plugins/vSphereCloudSlaveTemplate.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithm.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningRecord.java src/main/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningState.java src/main/resources/org/jenkinsci/plugins/vSphereCloudSlaveTemplate/config.jelly src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningAlgorithmTest.java src/test/java/org/jenkinsci/plugins/vsphere/tools/CloudProvisioningStateTest.java http://jenkins-ci.org/commit/vsphere-cloud-plugin/1e87f49a9aeda83f9c0a0306fc4bad6bacff403b Log: Merge pull request #48 from pjdarton/fix_jenkins_36878 Fix JENKINS-36878 and JENKINS-32112 Compare: https://github.com/jenkinsci/vsphere-cloud-plugin/compare/19e12f7c00ca...1e87f49a9aed

          pjdarton added a comment -

          Fixed in the next release (probably 2.14).

          pjdarton added a comment - Fixed in the next release (probably 2.14).

          pjdarton added a comment -

          I found a bug in my code that was causing serialization issues.

          pjdarton added a comment - I found a bug in my code that was causing serialization issues.

          pjdarton added a comment -

          pjdarton added a comment - New pull request issued. https://github.com/jenkinsci/vsphere-cloud-plugin/pull/50

          pjdarton added a comment -

          Pull request merged.

          pjdarton added a comment - Pull request merged.

            Unassigned Unassigned
            gregcovertsmith Greg Smith
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: