⚗️ Build client once
This commit is contained in:
parent
0b1ebc0774
commit
d8dcb462da
@ -19,17 +19,14 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class IngressResource
|
public class IngressResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Ingress> getIngresses(@QueryParam("namespace") String namespace)
|
public List<Ingress> getIngresses(@QueryParam("namespace") String namespace)
|
||||||
{
|
{
|
||||||
if(namespace != null)
|
if(namespace != null)
|
||||||
{
|
{
|
||||||
return clientProvider.getClient().network().v1().ingresses().inNamespace(namespace).list().getItems();
|
return ClientProvider.getClient().network().v1().ingresses().inNamespace(namespace).list().getItems();
|
||||||
}
|
}
|
||||||
return clientProvider.getClient().network().v1().ingresses().list().getItems();
|
return ClientProvider.getClient().network().v1().ingresses().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,6 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class LogResource
|
public class LogResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@ -34,7 +31,7 @@ public class LogResource
|
|||||||
if(podOptional.isPresent())
|
if(podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
return List.of(clientProvider.getClient().pods().inNamespace(pod.getMetadata().getNamespace()).withName(pod.getMetadata().getName()).getLog().split("\\r?\\n"));
|
return List.of(ClientProvider.getClient().pods().inNamespace(pod.getMetadata().getNamespace()).withName(pod.getMetadata().getName()).getLog().split("\\r?\\n"));
|
||||||
}
|
}
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,13 +20,10 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class NamespaceResource
|
public class NamespaceResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Namespace> getNamespaces()
|
public List<Namespace> getNamespaces()
|
||||||
{
|
{
|
||||||
return clientProvider.getClient().namespaces().list().getItems();
|
return ClientProvider.getClient().namespaces().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,9 +24,6 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class NodeResource
|
public class NodeResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<NodeStats> getMonitoring() throws IOException, InterruptedException
|
public List<NodeStats> getMonitoring() throws IOException, InterruptedException
|
||||||
@ -40,7 +37,7 @@ public class NodeResource
|
|||||||
if(parts.length == 5)
|
if(parts.length == 5)
|
||||||
{
|
{
|
||||||
String name = parts[0];
|
String name = parts[0];
|
||||||
Node node = clientProvider.getClient().nodes().withName(name).get();
|
Node node = ClientProvider.getClient().nodes().withName(name).get();
|
||||||
Integer absoluteCpu = extractInteger(parts[1]);
|
Integer absoluteCpu = extractInteger(parts[1]);
|
||||||
Integer relativeCpu = extractInteger(parts[2]);
|
Integer relativeCpu = extractInteger(parts[2]);
|
||||||
Integer absoluteMemory = extractMemory(parts[3]);
|
Integer absoluteMemory = extractMemory(parts[3]);
|
||||||
|
|||||||
@ -24,9 +24,6 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class PodResource
|
public class PodResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@ -52,7 +49,7 @@ public class PodResource
|
|||||||
if(podOptional.isPresent())
|
if(podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
clientProvider.getClient()
|
ClientProvider.getClient()
|
||||||
.pods()
|
.pods()
|
||||||
.inNamespace(pod.getMetadata().getNamespace())
|
.inNamespace(pod.getMetadata().getNamespace())
|
||||||
.withName(pod.getMetadata().getName())
|
.withName(pod.getMetadata().getName())
|
||||||
|
|||||||
@ -25,17 +25,14 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class ServiceResource
|
public class ServiceResource
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Service> getServices(@QueryParam("namespace") Optional<String> namespace)
|
public List<Service> getServices(@QueryParam("namespace") Optional<String> namespace)
|
||||||
{
|
{
|
||||||
if(namespace.isPresent())
|
if(namespace.isPresent())
|
||||||
{
|
{
|
||||||
return clientProvider.getClient().services().inNamespace(namespace.get()).list().getItems();
|
return ClientProvider.getClient().services().inNamespace(namespace.get()).list().getItems();
|
||||||
}
|
}
|
||||||
return clientProvider.getClient().services().list().getItems();
|
return ClientProvider.getClient().services().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,22 +14,19 @@ import java.util.Optional;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class PodService
|
public class PodService
|
||||||
{
|
{
|
||||||
@Inject
|
|
||||||
ClientProvider clientProvider;
|
|
||||||
|
|
||||||
public List<Pod> findByNamespace(String namespace)
|
public List<Pod> findByNamespace(String namespace)
|
||||||
{
|
{
|
||||||
return clientProvider.getClient().pods().inNamespace(namespace).list().getItems();
|
return ClientProvider.getClient().pods().inNamespace(namespace).list().getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pod> findAll()
|
public List<Pod> findAll()
|
||||||
{
|
{
|
||||||
return clientProvider.getClient().pods().list().getItems();
|
return ClientProvider.getClient().pods().list().getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Pod> findPodById(String id)
|
public Optional<Pod> findPodById(String id)
|
||||||
{
|
{
|
||||||
for(Pod pod : clientProvider.getClient().pods().list().getItems())
|
for(Pod pod : ClientProvider.getClient().pods().list().getItems())
|
||||||
{
|
{
|
||||||
if(pod.getMetadata().getUid().equals(id))
|
if(pod.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package dev.dinauer.service;
|
package dev.dinauer.service;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Service;
|
import io.fabric8.kubernetes.api.model.Service;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||||
@ -11,17 +12,9 @@ import java.util.Optional;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class ServiceService
|
public class ServiceService
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Service> findById(String id)
|
public Optional<Service> findById(String id)
|
||||||
{
|
{
|
||||||
for(Service service : client.services().list().getItems())
|
for(Service service : ClientProvider.getClient().services().list().getItems())
|
||||||
{
|
{
|
||||||
if(service.getMetadata().getUid().equals(id))
|
if(service.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,28 +3,20 @@ package dev.dinauer.utils;
|
|||||||
import io.fabric8.kubernetes.client.Config;
|
import io.fabric8.kubernetes.client.Config;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||||
|
import io.vertx.mutiny.core.Vertx;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import org.eclipse.microprofile.config.ConfigProvider;
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ApplicationScoped
|
|
||||||
public class ClientProvider
|
public class ClientProvider
|
||||||
{
|
{
|
||||||
@ConfigProperty(name = "dev.dinauer.kobooboo.kubeconfigs.dir")
|
public static KubernetesClient getClient()
|
||||||
String configFilePath;
|
|
||||||
|
|
||||||
private KubernetesClient client;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
{
|
||||||
client = new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(new File(configFilePath))).build();
|
String configFilePath = ConfigProvider.getConfig().getValue("dev.dinauer.kobooboo.kubeconfigs.dir", String.class);
|
||||||
}
|
return new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(new File(configFilePath))).build();
|
||||||
|
|
||||||
public KubernetesClient getClient()
|
|
||||||
{
|
|
||||||
return client;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package dev.dinauer.utils;
|
|||||||
import dev.dinauer.login.User;
|
import dev.dinauer.login.User;
|
||||||
import dev.dinauer.login.UserRepo;
|
import dev.dinauer.login.UserRepo;
|
||||||
import io.quarkus.elytron.security.common.BcryptUtil;
|
import io.quarkus.elytron.security.common.BcryptUtil;
|
||||||
import io.quarkus.runtime.Startup;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user