Use hashset to avoid node iteration
@@ -2196,13 +2196,17 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
* but we also call this periodically to self-heal any data out-of-sync issue.
*/
/*package*/ void trimLabels() {
+ Set<Label> nodeLabels = new HashSet<>(this.getAssignedLabels());
+ this.getNodes().forEach(n -> nodeLabels.addAll(n.getAssignedLabels()));
for (Iterator<Label> itr = labels.values().iterator(); itr.hasNext();) {
Label l = itr.next();
+ if (nodeLabels.contains(l) || this.clouds.stream().anyMatch(c -> c.canProvision(l))) {
resetLabel(l);
- if(l.isEmpty())
+ } else {
itr.remove();
}
}
+ }
/**
* Binds {@link AdministrativeMonitor}s to URL.
