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
Modifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from class hudson.slaves.Cloud
Cloud.CloudState
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
Field Summary
-
Constructor Summary
ConstructorDescriptionKubernetesCloud
(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 TypeMethodDescriptionvoid
Add a dynamic pod template.void
Add a new template to the cloudboolean
canProvision
(Cloud.CloudState state) io.fabric8.kubernetes.client.KubernetesClient
connect()
Connects to Kubernetes.org.kohsuke.stapler.HttpResponse
doCreate
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Creating a new template.boolean
Returns all pod templates for this cloud including the dynamic ones.int
int
Jenkins URL to be used by agents launched by this cloud.Deprecated.getMatchingTemplates
(Label label) Deprecated.UsegetTemplatesFor(Label)
instead.int
Labels for all pods started by the pluginGets the global pod retention policy for the plugin.int
int
getTemplate
(Label label) GetsPodTemplate
that has the matchingLabel
.getTemplate
(String id) getTemplatesFor
(Label label) Gets all PodTemplates that have the matchingLabel
.getUnwrappedTemplate
(PodTemplate podTemplate) Unwraps the given pod template.int
hashCode()
static void
boolean
boolean
Deprecated.boolean
boolean
boolean
boolean
boolean
boolean
provision
(Cloud.CloudState state, int excessWorkload) reconfigure
(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject form) void
Remove a dynamic pod template.void
Remove avoid
replaceTemplate
(PodTemplate oldTemplate, PodTemplate newTemplate) Replaces the old template with the new template.void
setAddMasterProxyEnvVars
(boolean addMasterProxyEnvVars) void
setCapOnlyOnAlivePods
(boolean capOnlyOnAlivePods) Deprecated.void
setConnectTimeout
(int connectTimeout) void
setContainerCap
(Integer containerCap) void
setContainerCapStr
(String containerCapStr) void
setCredentialsId
(String credentialsId) void
setDefaultsProviderTemplate
(String defaultsProviderTemplate) void
setDirectConnection
(boolean directConnection) void
setGarbageCollection
(GarbageCollection garbageCollection) void
setJenkinsTunnel
(String jenkinsTunnel) void
setJenkinsUrl
(String jenkinsUrl) void
setJnlpregistry
(String jnlpregistry) void
Deprecated.void
setMaxRequestsPerHost
(int maxRequestsPerHost) void
setMaxRequestsPerHostStr
(String maxRequestsPerHostStr) void
setNamespace
(String namespace) void
setPodLabels
(List<PodLabel> labels) Set Pod labels for all pods started by the plugin.void
setPodRetention
(PodRetention podRetention) Set the global pod retention policy for the plugin.void
setReadTimeout
(int readTimeout) void
setRestrictedPssSecurityContext
(boolean restrictedPssSecurityContext) void
setRetentionTimeout
(int retentionTimeout) void
setServerCertificate
(String serverCertificate) void
setServerUrl
(String serverUrl) void
setSkipTlsVerify
(boolean skipTlsVerify) void
setTemplates
(List<PodTemplate> templates) void
setUsageRestricted
(boolean usageRestricted) void
setUseJenkinsProxy
(boolean useJenkinsProxy) void
setWaitForPodSec
(Integer waitForPodSec) void
setWebSocket
(boolean webSocket) toString()
Methods inherited from class hudson.slaves.Cloud
all, canProvision, doConfigSubmit, doDoDelete, getACL, getDescriptor, getDisplayName, getIcon, getIconAltText, getIconClassName, getSearchUrl, getUrl, provision, registerPermissions
Methods inherited from class hudson.model.Actionable
addAction, addOrReplaceAction, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, getDynamic, removeAction, removeActions, replaceAction, replaceActions
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, makeSearchIndex, requirePOST, sendError, sendError, sendError, sendError, sendError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2
-
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
-
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.KubernetesAuthException
IOException
-
provision
public Collection<NodeProvisioner.PlannedNode> provision(@NonNull Cloud.CloudState state, int excessWorkload) -
replaceTemplate
Description copied from interface:PodTemplateGroup
Replaces the old template with the new template.- Specified by:
replaceTemplate
in interfacePodTemplateGroup
- Parameters:
oldTemplate
- the old template to replacenewTemplate
- the new template to replace with
-
canProvision
- Overrides:
canProvision
in classCloud
-
getTemplate
GetsPodTemplate
that 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:
addTemplate
in interfacePodTemplateGroup
- Parameters:
t
- docker template
-
removeTemplate
Remove a- Specified by:
removeTemplate
in interfacePodTemplateGroup
- Parameters:
t
- docker template
-
getPodTemplateGroupUrl
- Specified by:
getPodTemplateGroupUrl
in 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.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException, Descriptor.FormException Creating a new template.- Throws:
IOException
javax.servlet.ServletException
Descriptor.FormException
-
toString
-
reconfigure
public Cloud reconfigure(@NonNull org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject form) throws Descriptor.FormException - Overrides:
reconfigure
in classCloud
- Throws:
Descriptor.FormException
-
hpiRunInit
-
getPodLabels()