Skip to content
Permalink
Browse files
fix some warnings: k8s-test client not closed (#152)
  • Loading branch information
javeme committed Dec 7, 2021
1 parent 77ea9aa commit e081a0a6dc876b59b553a65b20463fee618cbe86
Showing 3 changed files with 21 additions and 6 deletions.
@@ -153,6 +153,7 @@ private static NamespacedKubernetesClient createKubeClient(
Config config;
try {
File file = new File(kubeConfig);
@SuppressWarnings("deprecation")
String kubeConfigContents = FileUtils.readFileToString(file);
config = Config.fromKubeconfig(kubeConfigContents);
} catch (IOException e) {
@@ -336,6 +337,7 @@ public void eventReceived(Action action,
CompletableFuture<?> future = pair.getLeft();
JobObserver observer = pair.getRight();

@SuppressWarnings("resource")
KubernetesDriver driver = KubernetesDriver.this;
JobState jobState = driver.buildJobState(computerJob);

@@ -547,6 +549,7 @@ private Map<String, Object> defaultSpec() {
if (StringUtils.isNotBlank(log4jXmlPath)) {
try {
File file = new File(log4jXmlPath);
@SuppressWarnings("deprecation")
String log4jXml = FileUtils.readFileToString(file);
spec.withLog4jXml(log4jXml);
} catch (IOException exception) {
@@ -95,19 +95,21 @@ protected void updateOptions(String key, Object value) {
@Before
public void setup() throws IOException {
this.initConfig();
this.kubeClient = new DefaultKubernetesClient()
.inNamespace(this.namespace);
@SuppressWarnings("resource")
DefaultKubernetesClient client = new DefaultKubernetesClient();
this.kubeClient = client.inNamespace(this.namespace);

this.createCRD(this.kubeClient);
this.initKubernetesDriver();
this.initOperator();
}

@After
public void teardown() throws IOException, ExecutionException,
InterruptedException {
public void teardown() throws InterruptedException, ExecutionException {
this.driver.close();
this.entrypoint.shutdown();
this.operatorFuture.get();
this.kubeClient.close();
Set<String> keySet = OperatorOptions.instance().options().keySet();
for (String key : keySet) {
System.clearProperty(key);
@@ -28,10 +28,12 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -72,6 +74,7 @@ public class KubernetesDriverTest extends AbstractK8sTest {
public KubernetesServer server = new KubernetesServer(true, true);

@Before
@Override
public void setup() throws IOException {
this.initConfig();
Config configuration = this.server.getClient().getConfiguration();
@@ -102,8 +105,9 @@ public void setup() throws IOException {
KubeConfigUtils.persistKubeConfigIntoFile(config, absolutePath);
System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE, absolutePath);

this.kubeClient = new DefaultKubernetesClient()
.inNamespace(this.namespace);
@SuppressWarnings("resource")
DefaultKubernetesClient client = new DefaultKubernetesClient();
this.kubeClient = client.inNamespace(this.namespace);

this.initPullSecret();
this.initKubernetesDriver();
@@ -113,6 +117,12 @@ public void setup() throws IOException {
}
}

@After
@Override
public void teardown() throws InterruptedException, ExecutionException {
super.teardown();
}

@Test
public void testConstruct() {
String namespace = Whitebox.getInternalState(this.driver, "namespace");

0 comments on commit e081a0a

Please sign in to comment.