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
- Direct Known Subclasses:
NonConfigurableKubernetesCloud
public class KubernetesCloud extends Cloud
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 Classes Modifier and Type Class Description static class
KubernetesCloud.DescriptorImpl
static class
KubernetesCloud.PodTemplateSourceImpl
-
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
Fields Modifier and Type Field Description static int
DEFAULT_CONNECT_TIMEOUT_SECONDS
static int
DEFAULT_MAX_REQUESTS_PER_HOST
static Map<String,String>
DEFAULT_POD_LABELS
Deprecated.static int
DEFAULT_READ_TIMEOUT_SECONDS
static int
DEFAULT_RETENTION_TIMEOUT_MINUTES
Default timeout for idle workers that don't correctly indicate exit.static Integer
DEFAULT_WAIT_FOR_POD_SEC
static String
JNLP_NAME
-
Constructor Summary
Constructors Constructor Description KubernetesCloud(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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addDynamicTemplate(PodTemplate t)
Add a dynamic pod template.void
addTemplate(PodTemplate t)
Add a new template to the cloudboolean
canProvision(Cloud.CloudState state)
io.fabric8.kubernetes.client.KubernetesClient
connect()
Connects to Kubernetes.boolean
equals(Object o)
List<PodTemplate>
getAllTemplates()
Returns all pod templates for this cloud including the dynamic ones.int
getConnectTimeout()
int
getContainerCap()
String
getContainerCapStr()
String
getCredentialsId()
String
getDefaultsProviderTemplate()
String
getJenkinsTunnel()
String
getJenkinsUrl()
String
getJenkinsUrlOrDie()
String
getJenkinsUrlOrNull()
Jenkins URL to be used by agents launched by this cloud.String
getJnlpregistry()
Map<String,String>
getLabels()
Deprecated.usegetPodLabels()
ArrayList<PodTemplate>
getMatchingTemplates(Label label)
Deprecated.UsegetTemplatesFor(Label)
instead.int
getMaxRequestsPerHost()
String
getMaxRequestsPerHostStr()
String
getNamespace()
List<PodLabel>
getPodLabels()
Labels for all pods started by the pluginPodRetention
getPodRetention()
Gets the global pod retention policy for the plugin.int
getReadTimeout()
int
getRetentionTimeout()
String
getServerCertificate()
String
getServerUrl()
PodTemplate
getTemplate(Label label)
GetsPodTemplate
that has the matchingLabel
.PodTemplate
getTemplateById(String id)
List<PodTemplate>
getTemplates()
List<PodTemplate>
getTemplatesFor(Label label)
Gets all PodTemplates that have the matchingLabel
.PodTemplate
getUnwrappedTemplate(PodTemplate podTemplate)
Unwraps the given pod template.Integer
getWaitForPodSec()
int
hashCode()
static void
hpiRunInit()
boolean
isAddMasterProxyEnvVars()
boolean
isCapOnlyOnAlivePods()
Deprecated.boolean
isDirectConnection()
boolean
isRestrictedPssSecurityContext()
boolean
isSkipTlsVerify()
boolean
isUsageRestricted()
boolean
isUseJenkinsProxy()
boolean
isWebSocket()
Collection<NodeProvisioner.PlannedNode>
provision(Cloud.CloudState state, int excessWorkload)
void
removeDynamicTemplate(PodTemplate t)
Remove a dynamic pod template.void
removeTemplate(PodTemplate t)
Remove avoid
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
setJenkinsTunnel(String jenkinsTunnel)
void
setJenkinsUrl(String jenkinsUrl)
void
setJnlpregistry(String jnlpregistry)
void
setLabels(Map<String,String> labels)
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)
String
toString()
-
Methods inherited from class hudson.slaves.Cloud
all, canProvision, getACL, getDescriptor, getDisplayName, 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 Detail
-
DEFAULT_MAX_REQUESTS_PER_HOST
public static final int DEFAULT_MAX_REQUESTS_PER_HOST
- See Also:
- Constant Field Values
-
DEFAULT_WAIT_FOR_POD_SEC
public static final Integer DEFAULT_WAIT_FOR_POD_SEC
-
JNLP_NAME
public static final String JNLP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_POD_LABELS
@Deprecated public static final Map<String,String> DEFAULT_POD_LABELS
Deprecated.label for all pods started by the plugin
-
DEFAULT_RETENTION_TIMEOUT_MINUTES
public static final int DEFAULT_RETENTION_TIMEOUT_MINUTES
Default timeout for idle workers that don't correctly indicate exit.- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT_SECONDS
public static final int DEFAULT_READ_TIMEOUT_SECONDS
- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIMEOUT_SECONDS
public static final int DEFAULT_CONNECT_TIMEOUT_SECONDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
KubernetesCloud
@DataBoundConstructor public KubernetesCloud(String name)
-
KubernetesCloud
public KubernetesCloud(@NonNull String name, @NonNull KubernetesCloud source)
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 Detail
-
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
public String getDefaultsProviderTemplate()
-
setDefaultsProviderTemplate
@DataBoundSetter public void setDefaultsProviderTemplate(String defaultsProviderTemplate)
-
getTemplates
@NonNull public List<PodTemplate> getTemplates()
-
getAllTemplates
@NonNull public List<PodTemplate> getAllTemplates()
Returns all pod templates for this cloud including the dynamic ones.- Returns:
- all pod templates for this cloud including the dynamic ones.
-
setTemplates
@DataBoundSetter public void setTemplates(@NonNull List<PodTemplate> templates)
-
getServerUrl
public String getServerUrl()
-
setServerUrl
@DataBoundSetter public void setServerUrl(@NonNull String serverUrl)
-
getServerCertificate
public String getServerCertificate()
-
setServerCertificate
@DataBoundSetter public void setServerCertificate(String serverCertificate)
-
isSkipTlsVerify
public boolean isSkipTlsVerify()
-
setSkipTlsVerify
@DataBoundSetter public void setSkipTlsVerify(boolean skipTlsVerify)
-
isAddMasterProxyEnvVars
public boolean isAddMasterProxyEnvVars()
-
setAddMasterProxyEnvVars
@DataBoundSetter public void setAddMasterProxyEnvVars(boolean addMasterProxyEnvVars)
-
getNamespace
public String getNamespace()
-
setNamespace
@DataBoundSetter public void setNamespace(String namespace)
-
getJnlpregistry
public String getJnlpregistry()
-
setJnlpregistry
@DataBoundSetter public void setJnlpregistry(String jnlpregistry)
-
isRestrictedPssSecurityContext
public boolean isRestrictedPssSecurityContext()
-
setRestrictedPssSecurityContext
@DataBoundSetter public void setRestrictedPssSecurityContext(boolean restrictedPssSecurityContext)
-
getJenkinsUrl
@CheckForNull public String getJenkinsUrl()
-
setCapOnlyOnAlivePods
@DataBoundSetter @Deprecated public void setCapOnlyOnAlivePods(boolean capOnlyOnAlivePods)
Deprecated.
-
isCapOnlyOnAlivePods
@Deprecated public boolean isCapOnlyOnAlivePods()
Deprecated.
-
getJenkinsUrlOrDie
@NonNull public String getJenkinsUrlOrDie()
- Returns:
- same as
getJenkinsUrlOrNull()
, if set - Throws:
IllegalStateException
- if no Jenkins URL could be computed.
-
getJenkinsUrlOrNull
@CheckForNull public String 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
@DataBoundSetter public void setJenkinsUrl(String jenkinsUrl)
-
getJenkinsTunnel
public String getJenkinsTunnel()
-
setJenkinsTunnel
@DataBoundSetter public void setJenkinsTunnel(String jenkinsTunnel)
-
getCredentialsId
public String getCredentialsId()
-
setCredentialsId
@DataBoundSetter public void setCredentialsId(String credentialsId)
-
getContainerCap
public int getContainerCap()
-
setContainerCapStr
@DataBoundSetter public void setContainerCapStr(String containerCapStr)
-
setContainerCap
public void setContainerCap(Integer containerCap)
-
getContainerCapStr
public String getContainerCapStr()
-
getReadTimeout
public int getReadTimeout()
-
setReadTimeout
@DataBoundSetter public void setReadTimeout(int readTimeout)
-
getConnectTimeout
public int getConnectTimeout()
-
getLabels
@Deprecated public Map<String,String> getLabels()
Deprecated.usegetPodLabels()
Labels for all pods started by the plugin- Returns:
- immutable map of pod labels
-
setLabels
@Deprecated public void setLabels(Map<String,String> labels)
Deprecated.Set pod labels- Parameters:
labels
- pod labels
-
getPodLabels
@NonNull public List<PodLabel> getPodLabels()
Labels for all pods started by the plugin
-
setPodLabels
@DataBoundSetter public void setPodLabels(@CheckForNull List<PodLabel> labels)
Set Pod labels for all pods started by the plugin.
-
setMaxRequestsPerHostStr
@DataBoundSetter public void setMaxRequestsPerHostStr(String maxRequestsPerHostStr)
-
setMaxRequestsPerHost
@DataBoundSetter public void setMaxRequestsPerHost(int maxRequestsPerHost)
-
getMaxRequestsPerHostStr
public String getMaxRequestsPerHostStr()
-
getMaxRequestsPerHost
public int getMaxRequestsPerHost()
-
setConnectTimeout
@DataBoundSetter public void setConnectTimeout(int connectTimeout)
-
getPodRetention
public PodRetention getPodRetention()
Gets the global pod retention policy for the plugin.
-
setPodRetention
@DataBoundSetter public void setPodRetention(PodRetention podRetention)
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, IOException
Connects 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)
-
canProvision
public boolean canProvision(@NonNull Cloud.CloudState state)
- Overrides:
canProvision
in classCloud
-
getTemplate
@CheckForNull public PodTemplate getTemplate(@CheckForNull Label label)
GetsPodTemplate
that has the matchingLabel
.- Parameters:
label
- label to look for in templates- Returns:
- the template
-
getTemplateById
@CheckForNull public PodTemplate getTemplateById(@NonNull String id)
-
getUnwrappedTemplate
public PodTemplate getUnwrappedTemplate(PodTemplate podTemplate)
Unwraps the given pod template.- Parameters:
podTemplate
- the pod template to unwrap.- Returns:
- the unwrapped pod template
-
getMatchingTemplates
@Deprecated public ArrayList<PodTemplate> getMatchingTemplates(@CheckForNull Label label)
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
public List<PodTemplate> getTemplatesFor(@CheckForNull Label label)
Gets all PodTemplates that have the matchingLabel
.- Parameters:
label
- label to look for in templates- Returns:
- list of matching templates
-
addTemplate
public void addTemplate(PodTemplate t)
Add a new template to the cloud- Parameters:
t
- docker template
-
removeTemplate
public void removeTemplate(PodTemplate t)
Remove a- Parameters:
t
- docker template
-
addDynamicTemplate
public void addDynamicTemplate(PodTemplate t)
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
public void removeDynamicTemplate(PodTemplate t)
Remove a dynamic pod template.- Parameters:
t
- the template to remove
-
getWaitForPodSec
public Integer getWaitForPodSec()
-
setWaitForPodSec
@DataBoundSetter public void setWaitForPodSec(Integer waitForPodSec)
-
hpiRunInit
@Initializer(after=SYSTEM_CONFIG_LOADED) public static void hpiRunInit()
-
-