Skip to content
Snippets Groups Projects
Commit f95ad41f authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Merge branch '302-move-application-availability-checks-from-janitor-to-platform' into 'develop'

Creating new API client each time requested

See merge request !256
parents 866e5099 eeb56255
No related branches found
No related tags found
2 merge requests!273Release 1.8.0 update,!256Creating new API client each time requested
Pipeline #95098 passed
......@@ -4,7 +4,6 @@ import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.kubernetes.remote.entities.KCluster;
import org.springframework.beans.factory.annotation.Value;
......@@ -32,18 +31,13 @@ public class KubernetesApiClientFactory {
private static final String OAUTH_TOKEN = "TODO REPLACE";
private Config config;
private KubernetesClient client;
/**
* Client is created only when necessary
*
* @return KubernetesClient instance
*/
public synchronized KubernetesClient getClient() {
if (this.client == null) {
this.client = new KubernetesClientBuilder().withConfig(getConfig()).build();
}
return this.client;
return new KubernetesClientBuilder().withConfig(getConfig()).build();
}
/**
......@@ -85,9 +79,4 @@ public class KubernetesApiClientFactory {
}
}
@PreDestroy
protected void preDestroy() {
client.close();
}
}
......@@ -66,13 +66,13 @@ public class KubernetesApiClientService {
}
public void scaleDeployment(KCluster kCluster, String namespace, String deploymentName, int replicas) {
KubernetesClient client = initClient(kCluster);
client.apps()
.deployments()
.inNamespace(namespace)
.withName(deploymentName)
.scale(replicas);
client.close();
try (KubernetesClient client = initClient(kCluster)) {
client.apps()
.deployments()
.inNamespace(namespace)
.withName(deploymentName)
.scale(replicas);
}
}
private KubernetesClient initClient(KCluster kCluster) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment