Skip to content

Commit

Permalink
Merge pull request #104 from jeffersongirao/container_step_kube_clien…
Browse files Browse the repository at this point in the history
…t_config

Instantiating Kubernetes Client with proper config in Container Steps
  • Loading branch information
carlossg authored Dec 6, 2016
2 parents bea9517 + 2be70ba commit 92c16d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.Serializable;

Expand All @@ -14,6 +15,10 @@ public class ContainerStep extends AbstractStepImpl implements Serializable {

private final String name;

private static final String DEFAULT_CLOUD = "kubernetes";

private String cloud = DEFAULT_CLOUD;

@DataBoundConstructor
public ContainerStep(String name) {
this.name = name;
Expand All @@ -23,10 +28,19 @@ public String getName() {
return name;
}

public String getCloud() {
return cloud;
}

@DataBoundSetter
public void setCloud(String cloud) {
this.cloud = cloud;
}

@Extension
public static class DescriptorImpl extends AbstractStepDescriptorImpl {

public DescriptorImpl() {
public DescriptorImpl() {
super(ContainerStepExecution.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import hudson.FilePath;
import hudson.LauncherDecorator;
import hudson.model.TaskListener;
import hudson.slaves.Cloud;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import jenkins.model.Jenkins;
import org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
Expand Down Expand Up @@ -45,7 +48,9 @@ public boolean start() throws Exception {
final CountDownLatch podStarted = new CountDownLatch(1);
final CountDownLatch podFinished = new CountDownLatch(1);

client = new DefaultKubernetesClient();
KubernetesCloud cloud = (KubernetesCloud) Jenkins.getInstance().getCloud(step.getCloud());
client = cloud.connect();

decorator = new ContainerExecDecorator(client, podName, containerName, workspace.getRemote(), podAlive, podStarted, podFinished);
context.newBodyInvoker()
.withContext(BodyInvoker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="cloud" title="The cloud to use">
<f:textbox default="kubernetes"/>
</f:entry>
<f:entry field="pod" title="The name of the pod to use">
<f:textbox/>
</f:entry>
Expand Down

0 comments on commit 92c16d4

Please sign in to comment.