Class KubernetesCloud
java.lang.Object
hudson.model.AbstractModelObject
hudson.model.Actionable
hudson.slaves.Cloud
org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud
- All Implemented Interfaces:
ExtensionPoint,Describable<Cloud>,ModelObject,SearchableModelObject,SearchItem,AccessControlled,ModelObjectWithContextMenu,PodTemplateGroup
- Direct Known Subclasses:
NonConfigurableKubernetesCloud
Kubernetes cloud provider.
Starts agents in a Kubernetes cluster using defined Docker templates for each label.
- Author:
- Carlos Sanchez carlos@apache.org
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested 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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionKubernetesCloud(String name) KubernetesCloud(String name, List<? extends PodTemplate> templates, String serverUrl, String namespace, String jenkinsUrl, String containerCapStr, int connectTimeout, int readTimeout, int retentionTimeout) Deprecated.KubernetesCloud(String name, KubernetesCloud source) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a dynamic pod template.voidAdd a new template to the cloudbooleancanProvision(Cloud.CloudState state) io.fabric8.kubernetes.client.KubernetesClientconnect()Connects to Kubernetes.org.kohsuke.stapler.HttpResponsedoCreate(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Creating a new template.booleanReturns all pod templates for this cloud including the dynamic ones.intintJenkins URL to be used by agents launched by this cloud.Deprecated.getMatchingTemplates(Label label) Deprecated.UsegetTemplatesFor(Label)instead.intLabels for all pods started by the pluginio.fabric8.kubernetes.client.dsl.PodResourcegetPodResource(String namespace, String name) GetPodResourcefromKubernetesClient.Gets the global pod retention policy for the plugin.intintgetTemplate(Label label) GetsPodTemplatethat has the matchingLabel.getTemplate(String id) getTemplatesFor(Label label) Gets all PodTemplates that have the matchingLabel.<T extends KubernetesCloudTrait>
Optional<T> Find configuration trait by type.Get list of traits enabled for this cloud.getUnwrappedTemplate(PodTemplate podTemplate) Unwraps the given pod template.inthashCode()static voidbooleanbooleanDeprecated.booleanbooleanbooleanbooleanbooleanbooleanprovision(Cloud.CloudState state, int excessWorkload) reconfigure(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject form) voidvoidRemove a dynamic pod template.voidRemove avoidreplaceTemplate(PodTemplate oldTemplate, PodTemplate newTemplate) Replaces the old template with the new template.voidsetAddMasterProxyEnvVars(boolean addMasterProxyEnvVars) voidsetCapOnlyOnAlivePods(boolean capOnlyOnAlivePods) Deprecated.voidsetConnectTimeout(int connectTimeout) voidsetContainerCap(Integer containerCap) voidsetContainerCapStr(String containerCapStr) voidsetCredentialsId(String credentialsId) voidsetDefaultsProviderTemplate(String defaultsProviderTemplate) voidsetDirectConnection(boolean directConnection) voidsetGarbageCollection(GarbageCollection garbageCollection) voidsetJenkinsTunnel(String jenkinsTunnel) voidsetJenkinsUrl(String jenkinsUrl) voidsetJnlpregistry(String jnlpregistry) voidDeprecated.voidsetMaxRequestsPerHost(int maxRequestsPerHost) voidsetMaxRequestsPerHostStr(String maxRequestsPerHostStr) voidsetNamespace(String namespace) voidsetPodLabels(List<PodLabel> labels) Set Pod labels for all pods started by the plugin.voidsetPodRetention(PodRetention podRetention) Set the global pod retention policy for the plugin.voidsetReadTimeout(int readTimeout) voidsetRestrictedPssSecurityContext(boolean restrictedPssSecurityContext) voidsetRetentionTimeout(int retentionTimeout) voidsetServerCertificate(String serverCertificate) voidsetServerUrl(String serverUrl) voidsetSkipTlsVerify(boolean skipTlsVerify) voidsetTemplates(List<PodTemplate> templates) voidsetTraits(List<KubernetesCloudTrait> traits) Replace the traits enabled for this cloud.voidsetUsageRestricted(boolean usageRestricted) voidsetUseJenkinsProxy(boolean useJenkinsProxy) voidsetWaitForPodSec(Integer waitForPodSec) voidsetWebSocket(boolean webSocket) toString()Methods inherited from class hudson.slaves.Cloud
all, canProvision, doConfigSubmit, doDoDelete, getACL, getDescriptor, getDisplayName, 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, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2Methods inherited from interface org.csanchez.jenkins.plugins.kubernetes.PodTemplateGroup
checkManagePermission, hasManagePermissionMethods inherited from interface hudson.search.SearchItem
getSearchGroup, getSearchIcon
-
Field Details
-
DEFAULT_MAX_REQUESTS_PER_HOST
public static final int DEFAULT_MAX_REQUESTS_PER_HOST- See Also:
-
DEFAULT_WAIT_FOR_POD_SEC
-
JNLP_NAME
- See Also:
-
DEFAULT_POD_LABELS
Deprecated.label for all pods started by the plugin -
DEFAULT_RETENTION_TIMEOUT_MINUTES
public static final int DEFAULT_RETENTION_TIMEOUT_MINUTESDefault timeout for idle workers that don't correctly indicate exit.- See Also:
-
DEFAULT_READ_TIMEOUT_SECONDS
public static final int DEFAULT_READ_TIMEOUT_SECONDS- See Also:
-
DEFAULT_CONNECT_TIMEOUT_SECONDS
public static final int DEFAULT_CONNECT_TIMEOUT_SECONDS- See Also:
-
-
Constructor Details
-
KubernetesCloud
-
KubernetesCloud
Copy constructor. Allows to create copies of the original kubernetes cloud. Since it's a singleton by design, this method also allows specifying a new name.- Parameters:
name- Name of the cloud to be createdsource- Source Kubernetes cloud implementation- Since:
- 0.13
-
KubernetesCloud
@Deprecated public KubernetesCloud(String name, List<? extends PodTemplate> templates, String serverUrl, String namespace, String jenkinsUrl, String containerCapStr, int connectTimeout, int readTimeout, int retentionTimeout) Deprecated.
-
-
Method Details
-
isUseJenkinsProxy
public boolean isUseJenkinsProxy() -
setUseJenkinsProxy
@DataBoundSetter public void setUseJenkinsProxy(boolean useJenkinsProxy) -
isUsageRestricted
public boolean isUsageRestricted() -
setUsageRestricted
@DataBoundSetter public void setUsageRestricted(boolean usageRestricted) -
getRetentionTimeout
public int getRetentionTimeout() -
setRetentionTimeout
@DataBoundSetter public void setRetentionTimeout(int retentionTimeout) -
getDefaultsProviderTemplate
-
setDefaultsProviderTemplate
-
getTemplates
-
getAllTemplates
Returns all pod templates for this cloud including the dynamic ones.- Returns:
- all pod templates for this cloud including the dynamic ones.
-
setTemplates
-
getServerUrl
-
setServerUrl
-
getServerCertificate
-
setServerCertificate
-
isSkipTlsVerify
public boolean isSkipTlsVerify() -
setSkipTlsVerify
@DataBoundSetter public void setSkipTlsVerify(boolean skipTlsVerify) -
isAddMasterProxyEnvVars
public boolean isAddMasterProxyEnvVars() -
setAddMasterProxyEnvVars
@DataBoundSetter public void setAddMasterProxyEnvVars(boolean addMasterProxyEnvVars) -
getNamespace
-
setNamespace
-
getJnlpregistry
-
setJnlpregistry
-
isRestrictedPssSecurityContext
public boolean isRestrictedPssSecurityContext() -
setRestrictedPssSecurityContext
@DataBoundSetter public void setRestrictedPssSecurityContext(boolean restrictedPssSecurityContext) -
getJenkinsUrl
-
setCapOnlyOnAlivePods
Deprecated. -
isCapOnlyOnAlivePods
Deprecated. -
getGarbageCollection
-
setGarbageCollection
-
getTraits
Get list of traits enabled for this cloud.- Returns:
- configured traits, never null
-
setTraits
Replace the traits enabled for this cloud.- Parameters:
traits- configured traits, ifnulltraits will be cleared.
-
getTrait
Find configuration trait by type.- Type Parameters:
T- trait type- Parameters:
traitType- trait type class- Returns:
- configuration trait or empty if not configured
-
getJenkinsUrlOrDie
- Returns:
- same as
getJenkinsUrlOrNull(), if set - Throws:
IllegalStateException- if no Jenkins URL could be computed.
-
getJenkinsUrlOrNull
Jenkins URL to be used by agents launched by this cloud.Tries in order:
- an explicitly configured URL (
getJenkinsUrl()) - the system property or environment variable
KUBERNETES_JENKINS_URL, unlessisWebSocket()mode andgetCredentialsId()is defined JenkinsLocationConfiguration.getUrl()
- Returns:
- Jenkins URL to be used by agents launched by this cloud. Always ends with a trailing slash. Null if no Jenkins URL could be computed.
- an explicitly configured URL (
-
isWebSocket
public boolean isWebSocket() -
setWebSocket
@DataBoundSetter public void setWebSocket(boolean webSocket) -
isDirectConnection
public boolean isDirectConnection() -
setDirectConnection
@DataBoundSetter public void setDirectConnection(boolean directConnection) -
setJenkinsUrl
-
getJenkinsTunnel
-
setJenkinsTunnel
-
getCredentialsId
-
setCredentialsId
-
getContainerCap
public int getContainerCap() -
setContainerCapStr
-
setContainerCap
-
getContainerCapStr
-
getReadTimeout
public int getReadTimeout() -
setReadTimeout
@DataBoundSetter public void setReadTimeout(int readTimeout) -
getConnectTimeout
public int getConnectTimeout() -
getLabels
Deprecated.usegetPodLabels()Labels for all pods started by the plugin- Returns:
- immutable map of pod labels
-
setLabels
Deprecated.Set pod labels- Parameters:
labels- pod labels
-
getPodLabels
Labels for all pods started by the plugin -
setPodLabels
Set Pod labels for all pods started by the plugin. -
setMaxRequestsPerHostStr
-
setMaxRequestsPerHost
@DataBoundSetter public void setMaxRequestsPerHost(int maxRequestsPerHost) -
getMaxRequestsPerHostStr
-
getMaxRequestsPerHost
public int getMaxRequestsPerHost() -
setConnectTimeout
@DataBoundSetter public void setConnectTimeout(int connectTimeout) -
getPodRetention
Gets the global pod retention policy for the plugin. -
setPodRetention
Set the global pod retention policy for the plugin.- Parameters:
podRetention- the pod retention policy for the plugin.
-
connect
public io.fabric8.kubernetes.client.KubernetesClient connect() throws org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException, IOExceptionConnects to Kubernetes.- Returns:
- Kubernetes client.
- Throws:
org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthExceptionIOException
-
getPodResource
@NonNull public io.fabric8.kubernetes.client.dsl.PodResource getPodResource(@Nullable String namespace, @NonNull String name) throws org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException, IOException GetPodResourcefromKubernetesClient.- Parameters:
namespace- namespace pod is located in, possibly nullname- pod name, not null- Returns:
- pod resource, never null
- Throws:
org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException- if cluster authentication failedIOException- if connection failed- See Also:
-
provision
public Collection<NodeProvisioner.PlannedNode> provision(@NonNull Cloud.CloudState state, int excessWorkload) -
replaceTemplate
Description copied from interface:PodTemplateGroupReplaces the old template with the new template.- Specified by:
replaceTemplatein interfacePodTemplateGroup- Parameters:
oldTemplate- the old template to replacenewTemplate- the new template to replace with
-
getManagePermission
- Specified by:
getManagePermissionin interfacePodTemplateGroup- Returns:
- The permission required to manage the templates in this group.
-
canProvision
- Overrides:
canProvisionin classCloud
-
getTemplate
GetsPodTemplatethat has the matchingLabel.- Parameters:
label- label to look for in templates- Returns:
- the template
-
getTemplate
-
getTemplateById
-
getUnwrappedTemplate
Unwraps the given pod template.- Parameters:
podTemplate- the pod template to unwrap.- Returns:
- the unwrapped pod template
-
getMatchingTemplates
Deprecated.UsegetTemplatesFor(Label)instead.Gets all PodTemplates that have the matchingLabel.- Parameters:
label- label to look for in templates- Returns:
- list of matching templates
-
getTemplatesFor
Gets all PodTemplates that have the matchingLabel.- Parameters:
label- label to look for in templates- Returns:
- list of matching templates
-
addTemplate
Add a new template to the cloud- Specified by:
addTemplatein interfacePodTemplateGroup- Parameters:
t- docker template
-
removeTemplate
Remove a- Specified by:
removeTemplatein interfacePodTemplateGroup- Parameters:
t- docker template
-
getPodTemplateGroupUrl
- Specified by:
getPodTemplateGroupUrlin interfacePodTemplateGroup- Returns:
- the URL to redirect to after the template is saved.
-
addDynamicTemplate
Add a dynamic pod template. Won't be displayed in UI, and persisted separately from the cloud instance.- Parameters:
t- the template to add
-
removeDynamicTemplate
Remove a dynamic pod template.- Parameters:
t- the template to remove
-
equals
-
hashCode
public int hashCode() -
getWaitForPodSec
-
setWaitForPodSec
-
getTemplateDescriptor
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public PodTemplate.DescriptorImpl getTemplateDescriptor() -
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 Creating a new template.- Throws:
IOExceptionjakarta.servlet.ServletExceptionDescriptor.FormException
-
toString
-
reconfigure
public Cloud reconfigure(@NonNull org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject form) throws Descriptor.FormException - Overrides:
reconfigurein classCloud- Throws:
Descriptor.FormException
-
registerPodInformer
-
hpiRunInit
-
getPodLabels()