-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from Vlatombe/planned_node_builder
Allow customization of NodeProvisioner.PlannedNode using extension point
- Loading branch information
Showing
6 changed files
with
291 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/org/csanchez/jenkins/plugins/kubernetes/PlannedNodeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
|
||
import hudson.model.Label; | ||
import hudson.slaves.NodeProvisioner; | ||
|
||
/** | ||
* A builder of {@link hudson.slaves.NodeProvisioner.PlannedNode} implementations for Kubernetes. | ||
* Can be subclassed to provide alternative implementations of {@link hudson.slaves.NodeProvisioner.PlannedNode}. | ||
*/ | ||
public abstract class PlannedNodeBuilder { | ||
private KubernetesCloud cloud; | ||
private PodTemplate template; | ||
private Label label; | ||
private int numExecutors = 1; | ||
|
||
/** | ||
* Returns the {@link KubernetesCloud}. | ||
* @return the {@link KubernetesCloud}. | ||
*/ | ||
public KubernetesCloud getCloud() { | ||
return cloud; | ||
} | ||
|
||
/** | ||
* Returns the {@link PodTemplate}. | ||
* @return | ||
*/ | ||
public PodTemplate getTemplate() { | ||
return template; | ||
} | ||
|
||
public Label getLabel() { | ||
return label; | ||
} | ||
|
||
public int getNumExecutors() { | ||
return numExecutors; | ||
} | ||
|
||
/** | ||
* @param cloud the {@link KubernetesCloud} instance to use. | ||
* @return the current builder. | ||
*/ | ||
public PlannedNodeBuilder cloud(KubernetesCloud cloud) { | ||
this.cloud = cloud; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param template the {@link PodTemplate} instance to use. | ||
* @return the current builder. | ||
*/ | ||
public PlannedNodeBuilder template(PodTemplate template) { | ||
this.template = template; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param label the {@link Label} to use. | ||
* @return the current builder. | ||
*/ | ||
public PlannedNodeBuilder label(Label label) { | ||
this.label = label; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param numExecutors the number of executors. | ||
* @return the current builder. | ||
*/ | ||
public PlannedNodeBuilder numExecutors(int numExecutors) { | ||
this.numExecutors = numExecutors; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the {@link hudson.slaves.NodeProvisioner.PlannedNode} instance based on the given inputs. | ||
* @return a {@link hudson.slaves.NodeProvisioner.PlannedNode} configured from this builder. | ||
*/ | ||
public abstract NodeProvisioner.PlannedNode build(); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/csanchez/jenkins/plugins/kubernetes/PlannedNodeBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.csanchez.jenkins.plugins.kubernetes; | ||
|
||
import hudson.ExtensionList; | ||
import hudson.ExtensionPoint; | ||
|
||
/** | ||
* A factory of {@link PlannedNodeBuilder} instances. | ||
*/ | ||
public abstract class PlannedNodeBuilderFactory implements ExtensionPoint { | ||
/** | ||
* Returns all registered implementations of {@link PlannedNodeBuilderFactory}. | ||
* @return all registered implementations of {@link PlannedNodeBuilderFactory}. | ||
*/ | ||
public static ExtensionList<PlannedNodeBuilderFactory> all() { | ||
return ExtensionList.lookup(PlannedNodeBuilderFactory.class); | ||
} | ||
|
||
/** | ||
* Returns a new instance of {@link PlannedNodeBuilder}. | ||
* @return a new instance of {@link PlannedNodeBuilder}. | ||
*/ | ||
public static PlannedNodeBuilder createInstance() { | ||
for (PlannedNodeBuilderFactory factory: all()) { | ||
PlannedNodeBuilder plannedNodeBuilder = factory.newInstance(); | ||
if (plannedNodeBuilder != null) { | ||
return plannedNodeBuilder; | ||
} | ||
} | ||
return new StandardPlannedNodeBuilder(); | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link PlannedNodeBuilder}. | ||
* @return a new instance of {@link PlannedNodeBuilder}. | ||
*/ | ||
public abstract PlannedNodeBuilder newInstance(); | ||
} |
Oops, something went wrong.