⚗️ Using shared vertx
This commit is contained in:
parent
98668642f7
commit
f177e76aea
5
pom.xml
5
pom.xml
@ -60,6 +60,11 @@
|
|||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-smallrye-jwt-build</artifactId>
|
<artifactId>quarkus-smallrye-jwt-build</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.fabric8</groupId>
|
||||||
|
<artifactId>kubernetes-httpclient-vertx</artifactId>
|
||||||
|
<version>7.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -19,14 +19,17 @@ 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,6 +20,9 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class LogResource
|
public class LogResource
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@ -31,7 +34,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,10 +20,13 @@ 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,12 +24,30 @@ 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()
|
public List<NodeStats> getMonitoring() throws IOException, InterruptedException
|
||||||
{
|
{
|
||||||
List<NodeStats> result = new ArrayList<>();
|
List<NodeStats> result = new ArrayList<>();
|
||||||
|
|
||||||
|
List<String> stats = getTopNodes();
|
||||||
|
for(String nodeName : stats)
|
||||||
|
{
|
||||||
|
String[] parts = nodeName.split("\\s+");
|
||||||
|
if(parts.length == 5)
|
||||||
|
{
|
||||||
|
String name = parts[0];
|
||||||
|
Node node = clientProvider.getClient().nodes().withName(name).get();
|
||||||
|
Integer absoluteCpu = extractInteger(parts[1]);
|
||||||
|
Integer relativeCpu = extractInteger(parts[2]);
|
||||||
|
Integer absoluteMemory = extractMemory(parts[3]);
|
||||||
|
Integer relativeMemory = extractInteger(parts[4]);
|
||||||
|
result.add(new NodeStats(node, absoluteCpu, relativeCpu, Integer.parseInt(node.getStatus().getAllocatable().get("cpu").getAmount()) * 1000, absoluteMemory, relativeMemory, extractMemory(node.getStatus().getAllocatable().get("memory").getAmount())));
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,9 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class PodResource
|
public class PodResource
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@ -49,7 +52,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,14 +25,17 @@ 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,19 +14,22 @@ 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))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,15 +6,19 @@ import io.fabric8.kubernetes.client.KubernetesClient;
|
|||||||
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class ServiceService
|
public class ServiceService
|
||||||
{
|
{
|
||||||
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
|
|
||||||
public Optional<Service> findById(String id)
|
public Optional<Service> findById(String id)
|
||||||
{
|
{
|
||||||
for(Service service : ClientProvider.getClient().services().list().getItems())
|
for(Service service : clientProvider.getClient().services().list().getItems())
|
||||||
{
|
{
|
||||||
if(service.getMetadata().getUid().equals(id))
|
if(service.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,11 @@ import io.fabric8.kubernetes.client.Config;
|
|||||||
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
|
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
|
||||||
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 io.fabric8.kubernetes.client.extension.ExtensionAdapter;
|
||||||
|
import io.fabric8.kubernetes.client.http.HttpClient;
|
||||||
|
import io.fabric8.kubernetes.client.vertx.VertxHttpClientBuilder;
|
||||||
|
import io.fabric8.kubernetes.client.vertx.VertxHttpClientFactory;
|
||||||
|
import io.vertx.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 jakarta.inject.Inject;
|
||||||
@ -13,11 +17,15 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
public class ClientProvider
|
public class ClientProvider
|
||||||
{
|
{
|
||||||
public static KubernetesClient getClient()
|
@Inject
|
||||||
|
Vertx vertx;
|
||||||
|
|
||||||
|
public KubernetesClient getClient()
|
||||||
{
|
{
|
||||||
String configFilePath = ConfigProvider.getConfig().getValue("dev.dinauer.kobooboo.kubeconfigs.dir", String.class);
|
String configFilePath = ConfigProvider.getConfig().getValue("dev.dinauer.kobooboo.kubeconfigs.dir", String.class);
|
||||||
return new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(new File(configFilePath))).build();
|
return new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(new File(configFilePath))).withHttpClientFactory(new VertxHttpClientFactory(vertx)).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user