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

public class KubernetesCloud extends Cloud implements PodTemplateGroup
Kubernetes cloud provider. Starts agents in a Kubernetes cluster using defined Docker templates for each label.
Author:
Carlos Sanchez carlos@apache.org
  • Field Details

    • DEFAULT_MAX_REQUESTS_PER_HOST

      public static final int DEFAULT_MAX_REQUESTS_PER_HOST
      See Also:
    • DEFAULT_WAIT_FOR_POD_SEC

      public static final Integer DEFAULT_WAIT_FOR_POD_SEC
    • JNLP_NAME

      public static final String JNLP_NAME
      See Also:
    • 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:
    • 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

      @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 created
      source - 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

      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.
    • getGarbageCollection

      public GarbageCollection getGarbageCollection()
    • setGarbageCollection

      @DataBoundSetter public void setGarbageCollection(GarbageCollection garbageCollection)
    • 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:

      1. an explicitly configured URL (getJenkinsUrl())
      2. the system property or environment variable KUBERNETES_JENKINS_URL, unless isWebSocket() mode and getCredentialsId() is defined
      3. 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.
    • 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.
      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)
      Overrides:
      provision in class Cloud
    • replaceTemplate

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

      public boolean canProvision(@NonNull Cloud.CloudState state)
      Overrides:
      canProvision in class Cloud
    • getTemplate

      @CheckForNull public PodTemplate getTemplate(@CheckForNull Label label)
      Gets PodTemplate that has the matching Label.
      Parameters:
      label - label to look for in templates
      Returns:
      the template
    • getTemplate

      @CheckForNull public PodTemplate getTemplate(@NonNull String id)
    • 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.
      Gets all PodTemplates that have the matching Label.
      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 matching Label.
      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
      Specified by:
      addTemplate in interface PodTemplateGroup
      Parameters:
      t - docker template
    • removeTemplate

      public void removeTemplate(PodTemplate t)
      Remove a
      Specified by:
      removeTemplate in interface PodTemplateGroup
      Parameters:
      t - docker template
    • getPodTemplateGroupUrl

      public String getPodTemplateGroupUrl()
      Specified by:
      getPodTemplateGroupUrl in interface PodTemplateGroup
      Returns:
      the URL to redirect to after the template is saved.
    • 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
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getWaitForPodSec

      public Integer getWaitForPodSec()
    • setWaitForPodSec

      @DataBoundSetter public void setWaitForPodSec(Integer waitForPodSec)
    • 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

      public String toString()
      Overrides:
      toString in class Object
    • reconfigure

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

      @Initializer(after=SYSTEM_CONFIG_LOADED) public static void hpiRunInit()