Skip to content

Commit 244fc73

Browse files
committed
Clean up
1 parent 336800d commit 244fc73

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesProvisioningLimits.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,26 @@ public final class KubernetesProvisioningLimits {
4040
*/
4141
private final Map<String, Integer> cloudCounts = new HashMap<>();
4242

43-
public static void init() {
44-
get().initInstance();
45-
}
46-
4743
/**
4844
* Initialize limits counter
49-
* @return whether the instance was already initialized
45+
* @return whether the instance was already initialized before this call.
5046
*/
5147
private synchronized boolean initInstance() {
52-
if (init) {
53-
return true;
48+
boolean previousInit = init;
49+
if (!init) {
50+
Queue.withLock(() -> {
51+
Jenkins.get().getNodes()
52+
.stream()
53+
.filter(KubernetesSlave.class::isInstance)
54+
.map(KubernetesSlave.class::cast)
55+
.forEach(node -> {
56+
cloudCounts.put(node.getCloudName(), getGlobalCount(node.getCloudName()) + node.getNumExecutors());
57+
podTemplateCounts.put(node.getTemplateId(), getPodTemplateCount(node.getTemplateId()) + node.getNumExecutors());
58+
});
59+
});
60+
init = true;
5461
}
55-
Queue.withLock(() -> {
56-
Jenkins.get().getNodes()
57-
.stream()
58-
.filter(KubernetesSlave.class::isInstance)
59-
.map(KubernetesSlave.class::cast)
60-
.forEach(node -> {
61-
cloudCounts.put(node.getCloudName(), getGlobalCount(node.getCloudName()) + node.getNumExecutors());
62-
podTemplateCounts.put(node.getTemplateId(), getPodTemplateCount(node.getTemplateId()) + node.getNumExecutors());
63-
});
64-
});
65-
init = true;
66-
return false;
62+
return previousInit;
6763
}
6864

6965
/**

0 commit comments

Comments
 (0)