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));
}
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));
});
}
Aggregations