Skip to content

Commit bb60083

Browse files
authored
Merge pull request #1291 from Vlatombe/kubernetes-client-one-more-followup
2 parents 54b077b + 63c2a37 commit bb60083

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,4 @@ private static StandardCredentials resolveCredentials(@CheckForNull String crede
188188
return c;
189189
}
190190

191-
private static class WithContextClassLoader implements AutoCloseable {
192-
193-
private final ClassLoader previousClassLoader;
194-
195-
public WithContextClassLoader(ClassLoader classLoader) {
196-
this.previousClassLoader = Thread.currentThread().getContextClassLoader();
197-
Thread.currentThread().setContextClassLoader(classLoader);
198-
}
199-
200-
@Override
201-
public void close() {
202-
Thread.currentThread().setContextClassLoader(previousClassLoader);
203-
}
204-
}
205191
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
import io.fabric8.kubernetes.api.model.Toleration;
5555
import io.fabric8.kubernetes.api.model.Volume;
5656
import io.fabric8.kubernetes.api.model.VolumeMount;
57-
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
5857
import io.fabric8.kubernetes.client.KubernetesClient;
58+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
5959
import io.fabric8.kubernetes.client.KubernetesClientException;
6060

6161
import static hudson.Util.replaceMacro;
@@ -599,7 +599,8 @@ public static String substitute(String s, Map<String, String> properties, String
599599

600600
public static Pod parseFromYaml(String yaml) {
601601
String s = yaml;
602-
try (KubernetesClient client = new DefaultKubernetesClient()) {
602+
try (WithContextClassLoader ignored = new WithContextClassLoader(PodTemplateUtils.class.getClassLoader());
603+
KubernetesClient client = new KubernetesClientBuilder().build()) {
603604
// JENKINS-57116
604605
if (StringUtils.isBlank(s)) {
605606
LOGGER.log(Level.WARNING, "[JENKINS-57116] Trying to parse invalid yaml: \"{0}\"", yaml);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.csanchez.jenkins.plugins.kubernetes;
2+
3+
// TODO post 2.362 use jenkins.util.SetContextClassLoader
4+
class WithContextClassLoader implements AutoCloseable {
5+
6+
private final ClassLoader previousClassLoader;
7+
8+
public WithContextClassLoader(ClassLoader classLoader) {
9+
this.previousClassLoader = Thread.currentThread().getContextClassLoader();
10+
Thread.currentThread().setContextClassLoader(classLoader);
11+
}
12+
13+
@Override
14+
public void close() {
15+
Thread.currentThread().setContextClassLoader(previousClassLoader);
16+
}
17+
}

src/test/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesTestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static void assumeWindows(String buildNumber) {
160160
}
161161

162162
public static boolean isWindows(@CheckForNull String buildNumber) {
163-
try (KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder(Config.autoConfigure(null)).build())) {
163+
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
164164
for (Node n : client.nodes().list().getItems()) {
165165
Map<String, String> labels = n.getMetadata().getLabels();
166166
String os = labels.get("kubernetes.io/os");

0 commit comments

Comments
 (0)