Skip to content

Commit

Permalink
Correctly check for nullness of label value in canProvision call
Browse files Browse the repository at this point in the history
  • Loading branch information
rkosegi committed Feb 5, 2022
1 parent f1a8663 commit b5fc968
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ private List<HetznerServerTemplate> getTemplates(Label label) {
return serverTemplates.stream().filter(t -> {
//no labels has been provided in template
if (t.getLabels().isEmpty()) {
return t.getMode() != null && t.getMode() == Node.Mode.NORMAL;
return Node.Mode.NORMAL.equals(t.getMode());
} else {
return label.matches(t.getLabels());
if (Node.Mode.NORMAL.equals(t.getMode())) {
return label == null || label.matches(t.getLabels());
} else {
return label != null && label.matches(t.getLabels());
}
}
})
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,20 @@ public void testCanProvisionInNormalMode() {
Cloud.CloudState cloudState = new Cloud.CloudState(new LabelAtom("java"), 1);
assertTrue(cloud.canProvision(cloudState));
}

//see https://github.com/jenkinsci/hetzner-cloud-plugin/issues/15
@Test
public void testCanProvisionNullJobLabel() {
HetznerServerTemplate tmpl1 = new HetznerServerTemplate("tmpl1", null, "img1", "fsn1", "cx31");
tmpl1.setMode(Node.Mode.NORMAL);
HetznerServerTemplate tmpl2 = new HetznerServerTemplate("tmpl1", "label2,label3", "img1", "fsn1", "cx31");
tmpl2.setMode(Node.Mode.EXCLUSIVE);
final HetznerCloud cloud = new HetznerCloud("hcloud-01", "mock-credentials", "10",
Lists.newArrayList(tmpl1, tmpl2)
);
Cloud.CloudState cloudState = new Cloud.CloudState(null, 1);
assertTrue(cloud.canProvision(cloudState));
Cloud.CloudState cloudState2 = new Cloud.CloudState(new LabelAtom("label3"), 1);
assertTrue(cloud.canProvision(cloudState2));
}
}

0 comments on commit b5fc968

Please sign in to comment.