Package io.jenkins.plugins.kubevirt
Class KubeVirtCloud
java.lang.Object
hudson.model.AbstractModelObject
hudson.model.Actionable
hudson.slaves.Cloud
io.jenkins.plugins.kubevirt.KubeVirtCloud
- All Implemented Interfaces:
ExtensionPoint,Describable<Cloud>,ModelObject,SearchableModelObject,SearchItem,AccessControlled,VMTemplateGroup,ModelObjectWithContextMenu
Jenkins Cloud implementation for KubeVirt / OpenShift Virtualization.
Provides dynamic provisioning of Jenkins agents as virtual machines.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class hudson.slaves.Cloud
Cloud.CloudStateNested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudsonNested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionKubeVirtCloud(String name, String serverUrl, String credentialsId, String namespace, boolean ignoreSsl, String vmCountCap, boolean enableOrphanCleanup, List<KubeVirtTemplate> templates) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTemplate(KubeVirtTemplate template) Add the template to the group.booleancanProvision(Cloud.CloudState state) intCounts all registered KubeVirt agents for this cloud in Jenkins.intcountRegisteredAgentsForTemplate(String templateName) Counts all registered KubeVirt agents for a specific template in Jenkins.intCounts all VMs for this cloud including in-flight provisions.intcountVMsFromKubernetesForTemplate(String templateName) Counts all VMs for a specific template including in-flight provisions.voidDeletes a VM by name after validating ownership.org.kohsuke.stapler.HttpResponsedoCreate(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Creates a new template via the UI.org.kohsuke.stapler.HttpResponsedoMoveTemplateDown(String templateId) org.kohsuke.stapler.HttpResponsedoMoveTemplateUp(String templateId) static List<KubeVirtCloud> Returns all KubeVirt clouds configured in Jenkins.Creates a cloud configuration object for this cloud.Stored display label for the configure form (without fallback toCloud.name).intGets the effective VM count cap for provisioning logic.getTemplate(String id) Gets a template by ID for URL routing.Gets a template by ID.Gets the template descriptor for use in Jelly.intGets the VM count cap as configured (for UI binding).booleanPerforms a lightweight connectivity check against the Kubernetes API server.booleanGets whether orphaned VM cleanup is enabled for this cloud.booleanvoidmoveTemplateDown(String templateId) Moves a template one position later in the list.voidmoveTemplateUp(String templateId) Moves a template one position earlier in the list.provision(Cloud.CloudState state, int excessWorkload) reconfigure(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject form) voidremoveTemplate(KubeVirtTemplate template) Removes the template from the group.voidreplaceTemplate(KubeVirtTemplate oldTemplate, KubeVirtTemplate newTemplate) Replaces the old template with the new template.voidsetDisplayName(String displayName) voidsetTemplates(List<KubeVirtTemplate> templates) Sets the templates for this cloud.Methods inherited from class hudson.slaves.Cloud
all, canProvision, doConfigSubmit, doDoDelete, getACL, getDescriptor, getIcon, getIconAltText, getIconClassName, getSearchUrl, getUrl, provision, reconfigure, registerPermissionsMethods inherited from class hudson.model.Actionable
addAction, addOrReplaceAction, doContextMenu, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, getDynamic, getDynamic, removeAction, removeActions, replaceAction, replaceActionsMethods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError, sendError, sendError, sendErrorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2Methods inherited from interface hudson.search.SearchItem
getSearchGroup, getSearchIconMethods inherited from interface io.jenkins.plugins.kubevirt.VMTemplateGroup
checkManagePermission, hasManagePermission
-
Constructor Details
-
KubeVirtCloud
-
-
Method Details
-
setDisplayName
-
getDisplayNameOrNull
Stored display label for the configure form (without fallback toCloud.name). -
getDisplayName
- Specified by:
getDisplayNamein interfaceModelObject- Overrides:
getDisplayNamein classCloud
-
setTemplates
Sets the templates for this cloud.- Parameters:
templates- the templates to set
-
getServerUrl
-
getCredentialsId
-
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. ReturnsKubeVirtConfiguration.UNLIMITED_CAPACITYif set to 0 (unlimited).- Returns:
- The effective VM count cap, or UNLIMITED_CAPACITY if no limit
-
getTemplates
-
addTemplate
Description copied from interface:VMTemplateGroupAdd the template to the group.- Specified by:
addTemplatein interfaceVMTemplateGroup- Parameters:
template- the template to add
-
replaceTemplate
Description copied from interface:VMTemplateGroupReplaces the old template with the new template.- Specified by:
replaceTemplatein interfaceVMTemplateGroup- Parameters:
oldTemplate- the old template to replacenewTemplate- the new template to replace with
-
removeTemplate
Description copied from interface:VMTemplateGroupRemoves the template from the group.- Specified by:
removeTemplatein interfaceVMTemplateGroup- Parameters:
template- the template to remove
-
getVMTemplateGroupUrl
- Specified by:
getVMTemplateGroupUrlin interfaceVMTemplateGroup- Returns:
- the URL to redirect to after the template is saved.
-
getManagePermission
- Specified by:
getManagePermissionin interfaceVMTemplateGroup- Returns:
- The permission required to manage the templates in this group.
-
getTemplate
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
Gets a template by ID.- Parameters:
id- the template ID- Returns:
- the template, or null if not found
-
moveTemplateUp
Moves a template one position earlier in the list. Earlier templates are preferred when multiple templates match the same label. -
moveTemplateDown
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:
IOExceptionjakarta.servlet.ServletExceptionDescriptor.FormException
-
reconfigure
public Cloud reconfigure(@NonNull org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject form) throws Descriptor.FormException - Overrides:
reconfigurein classCloud- Throws:
Descriptor.FormException
-
getCloudConfig
Creates a cloud configuration object for this cloud.- Returns:
- An immutable configuration object
-
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
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
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:
trueif the cluster responded,falseotherwise
-
provision
public Collection<NodeProvisioner.PlannedNode> provision(Cloud.CloudState state, int excessWorkload) -
canProvision
- Overrides:
canProvisionin classCloud
-
deleteVM
Deletes a VM by name after validating ownership.- Parameters:
vmName- The name of the VM to deletetemplateName- The expected template name for ownership validation- Throws:
VMDeletionException- if the VM cannot be deletedIllegalStateException- if the VM doesn't belong to this instance
-