Search in sources :

Example 6 with KubernetesSlave

use of org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave in project kubernetes-plugin by jenkinsci.

the class KubernetesPipelineTest method podTemplateWithMultipleLabels.

@Test
public void podTemplateWithMultipleLabels() throws Exception {
    PodTemplate pt = new PodTemplate();
    pt.setName("podTemplate");
    pt.setLabel("label1 label2");
    ContainerTemplate jnlp = new ContainerTemplate("jnlp", "jenkins/inbound-agent:4.3-4-alpine");
    pt.setContainers(Collections.singletonList(jnlp));
    cloud.addTemplate(pt);
    SemaphoreStep.waitForStart("pod/1", b);
    Map<String, String> labels = getLabels(cloud, this, name);
    labels.put("jenkins/label", "label1_label2");
    KubernetesSlave node = r.jenkins.getNodes().stream().filter(KubernetesSlave.class::isInstance).map(KubernetesSlave.class::cast).findAny().get();
    assertTrue(node.getAssignedLabels().containsAll(Label.parse("label1 label2")));
    PodList pods = cloud.connect().pods().withLabels(labels).list();
    assertThat("Expected one pod with labels " + labels + " but got: " + pods.getItems().stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()), pods.getItems(), hasSize(1));
    SemaphoreStep.success("pod/1", null);
    r.assertBuildStatusSuccess(r.waitForCompletion(b));
}
Also used : ContainerTemplate(org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate) PodList(io.fabric8.kubernetes.api.model.PodList) Pod(io.fabric8.kubernetes.api.model.Pod) KubernetesSlave(org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave) PodTemplate(org.csanchez.jenkins.plugins.kubernetes.PodTemplate) Test(org.junit.Test)

Example 7 with KubernetesSlave

use of org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave in project kubernetes-plugin by jenkinsci.

the class RestartPipelineTest method taskListenerAfterRestart_multipleLabels.

@Test
public void taskListenerAfterRestart_multipleLabels() {
    AtomicReference<String> projectName = new AtomicReference<>();
    story.then(r -> {
        configureAgentListener();
        configureCloud();
        WorkflowRun b = getPipelineJobThenScheduleRun(r);
        projectName.set(b.getParent().getFullName());
        r.waitForMessage("+ sleep", b);
    });
    story.then(r -> {
        WorkflowRun b = r.jenkins.getItemByFullName(projectName.get(), WorkflowJob.class).getBuildByNumber(1);
        Optional<Node> first = r.jenkins.getNodes().stream().filter(KubernetesSlave.class::isInstance).findFirst();
        assertTrue("Kubernetes node should be present after restart", first.isPresent());
        KubernetesSlave node = (KubernetesSlave) first.get();
        r.waitForMessage("Ready to run", b);
        waitForTemplate(node).getListener().getLogger().println("This got printed");
        r.waitForMessage("This got printed", b);
        b.getExecutor().interrupt();
        r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
    });
}
Also used : Node(hudson.model.Node) KubernetesSlave(org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave) AtomicReference(java.util.concurrent.atomic.AtomicReference) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

KubernetesSlave (org.csanchez.jenkins.plugins.kubernetes.KubernetesSlave)7 Node (hudson.model.Node)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 ArrayList (java.util.ArrayList)2 ContainerTemplate (org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 AbortException (hudson.AbortException)1 EnvVars (hudson.EnvVars)1 FilePath (hudson.FilePath)1 Launcher (hudson.Launcher)1 LauncherDecorator (hudson.LauncherDecorator)1 Proc (hudson.Proc)1 Computer (hudson.model.Computer)1 TaskListener (hudson.model.TaskListener)1 ItemListener (hudson.model.listeners.ItemListener)1 Cloud (hudson.slaves.Cloud)1