Class KubeVirtCloud

All Implemented Interfaces:
ExtensionPoint, Describable<Cloud>, ModelObject, SearchableModelObject, SearchItem, AccessControlled, VMTemplateGroup, ModelObjectWithContextMenu

public class KubeVirtCloud extends Cloud implements VMTemplateGroup
Jenkins Cloud implementation for KubeVirt / OpenShift Virtualization. Provides dynamic provisioning of Jenkins agents as virtual machines.
  • Constructor Details

  • Method Details

    • setDisplayName

      @DataBoundSetter public void setDisplayName(String displayName)
    • getDisplayNameOrNull

      @CheckForNull public String getDisplayNameOrNull()
      Stored display label for the configure form (without fallback to Cloud.name).
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface ModelObject
      Overrides:
      getDisplayName in class Cloud
    • setTemplates

      public void setTemplates(List<KubeVirtTemplate> templates)
      Sets the templates for this cloud.
      Parameters:
      templates - the templates to set
    • getServerUrl

      public String getServerUrl()
    • getCredentialsId

      public String getCredentialsId()
    • getNamespace

      public String getNamespace()
    • isIgnoreSsl

      public boolean isIgnoreSsl()
    • isEnableOrphanCleanup

      public boolean isEnableOrphanCleanup()
      Gets whether orphaned VM cleanup is enabled for this cloud. When enabled, a periodic background task will detect and delete VMs that exist in Kubernetes but have no registered Jenkins agent.
      Returns:
      true if orphan cleanup is enabled
    • getVmCountCap

      public int getVmCountCap()
      Gets the VM count cap as configured (for UI binding). Returns the raw value: 0 means unlimited, positive number means that limit.
      Returns:
      The configured VM count cap value
    • getEffectiveVmCountCap

      public int getEffectiveVmCountCap()
      Gets the effective VM count cap for provisioning logic. Returns KubeVirtConfiguration.UNLIMITED_CAPACITY if set to 0 (unlimited).
      Returns:
      The effective VM count cap, or UNLIMITED_CAPACITY if no limit
    • getTemplates

      @NonNull public List<KubeVirtTemplate> getTemplates()
    • addTemplate

      public void addTemplate(KubeVirtTemplate template)
      Description copied from interface: VMTemplateGroup
      Add the template to the group.
      Specified by:
      addTemplate in interface VMTemplateGroup
      Parameters:
      template - the template to add
    • replaceTemplate

      public void replaceTemplate(KubeVirtTemplate oldTemplate, KubeVirtTemplate newTemplate)
      Description copied from interface: VMTemplateGroup
      Replaces the old template with the new template.
      Specified by:
      replaceTemplate in interface VMTemplateGroup
      Parameters:
      oldTemplate - the old template to replace
      newTemplate - the new template to replace with
    • removeTemplate

      public void removeTemplate(KubeVirtTemplate template)
      Description copied from interface: VMTemplateGroup
      Removes the template from the group.
      Specified by:
      removeTemplate in interface VMTemplateGroup
      Parameters:
      template - the template to remove
    • getVMTemplateGroupUrl

      public String getVMTemplateGroupUrl()
      Specified by:
      getVMTemplateGroupUrl in interface VMTemplateGroup
      Returns:
      the URL to redirect to after the template is saved.
    • getManagePermission

      public Permission getManagePermission()
      Specified by:
      getManagePermission in interface VMTemplateGroup
      Returns:
      The permission required to manage the templates in this group.
    • getTemplate

      public KubeVirtTemplate getTemplate(@NonNull String id)
      Gets a template by ID for URL routing. Used by Stapler to route to /cloud/{cloudName}/template/{templateId}
      Parameters:
      id - the template ID
      Returns:
      the template, or null if not found
    • getTemplateById

      public KubeVirtTemplate getTemplateById(@NonNull String id)
      Gets a template by ID.
      Parameters:
      id - the template ID
      Returns:
      the template, or null if not found
    • moveTemplateUp

      public void moveTemplateUp(@NonNull String templateId)
      Moves a template one position earlier in the list. Earlier templates are preferred when multiple templates match the same label.
    • moveTemplateDown

      public void moveTemplateDown(@NonNull String templateId)
      Moves a template one position later in the list.
    • doMoveTemplateUp

      @POST public org.kohsuke.stapler.HttpResponse doMoveTemplateUp(@QueryParameter String templateId) throws IOException
      Throws:
      IOException
    • doMoveTemplateDown

      @POST public org.kohsuke.stapler.HttpResponse doMoveTemplateDown(@QueryParameter String templateId) throws IOException
      Throws:
      IOException
    • getTemplateDescriptor

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public KubeVirtTemplate.DescriptorImpl getTemplateDescriptor()
      Gets the template descriptor for use in Jelly.
      Returns:
      the KubeVirtTemplate descriptor
    • doCreate

      @POST public org.kohsuke.stapler.HttpResponse doCreate(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException, Descriptor.FormException
      Creates a new template via the UI.
      Throws:
      IOException
      jakarta.servlet.ServletException
      Descriptor.FormException
    • reconfigure

      public Cloud reconfigure(@NonNull org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject form) throws Descriptor.FormException
      Overrides:
      reconfigure in class Cloud
      Throws:
      Descriptor.FormException
    • getCloudConfig

      public KubeVirtCloudConfig getCloudConfig()
      Creates a cloud configuration object for this cloud.
      Returns:
      An immutable configuration object
    • getAllClouds

      public static List<KubeVirtCloud> getAllClouds()
      Returns all KubeVirt clouds configured in Jenkins. Used by CloudInitConfig to show which templates use a given config file.
      Returns:
      List of all KubeVirt clouds
    • countVMsFromKubernetes

      public int countVMsFromKubernetes()
      Counts all VMs for this cloud including in-flight provisions. Combines VMs from Kubernetes API with provisions that have been started but not yet reflected in Kubernetes, preventing race conditions.
      Returns:
      The total number of VMs (existing + in-flight)
    • countVMsFromKubernetesForTemplate

      public int countVMsFromKubernetesForTemplate(String templateName)
      Counts all VMs for a specific template including in-flight provisions. Combines VMs from Kubernetes API with provisions that have been started but not yet reflected in Kubernetes.
      Parameters:
      templateName - The template name to count
      Returns:
      The total number of VMs for the template (existing + in-flight)
    • countRegisteredAgents

      public int countRegisteredAgents()
      Counts all registered KubeVirt agents for this cloud in Jenkins. This only counts agents that have completed provisioning and are registered. Used as a fallback if Kubernetes API is unavailable.
      Returns:
      The number of registered agents belonging to this cloud
    • countRegisteredAgentsForTemplate

      public int countRegisteredAgentsForTemplate(String templateName)
      Counts all registered KubeVirt agents for a specific template in Jenkins. This only counts agents that have completed provisioning and are registered. Used as a fallback if Kubernetes API is unavailable.
      Parameters:
      templateName - The template name to count
      Returns:
      The number of registered agents for the given template
    • isCloudReachable

      public boolean isCloudReachable()
      Performs a lightweight connectivity check against the Kubernetes API server. Uses a short timeout to avoid blocking the calling thread for too long.
      Returns:
      true if the cluster responded, false otherwise
    • provision

      public Collection<NodeProvisioner.PlannedNode> provision(Cloud.CloudState state, int excessWorkload)
      Overrides:
      provision in class Cloud
    • canProvision

      public boolean canProvision(Cloud.CloudState state)
      Overrides:
      canProvision in class Cloud
    • deleteVM

      public void deleteVM(String vmName, String templateName)
      Deletes a VM by name after validating ownership.
      Parameters:
      vmName - The name of the VM to delete
      templateName - The expected template name for ownership validation
      Throws:
      VMDeletionException - if the VM cannot be deleted
      IllegalStateException - if the VM doesn't belong to this instance