💥 Switch to building client by config path
This commit is contained in:
parent
32e7e4905d
commit
d55e367424
@ -1,10 +1,12 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
|
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
|
||||||
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.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@ -17,13 +19,8 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class IngressResource
|
public class IngressResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ -31,8 +28,8 @@ public class IngressResource
|
|||||||
{
|
{
|
||||||
if(namespace != null)
|
if(namespace != null)
|
||||||
{
|
{
|
||||||
return client.network().v1().ingresses().inNamespace(namespace).list().getItems();
|
return clientProvider.getClient().network().v1().ingresses().inNamespace(namespace).list().getItems();
|
||||||
}
|
}
|
||||||
return client.network().v1().ingresses().list().getItems();
|
return clientProvider.getClient().network().v1().ingresses().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
import dev.dinauer.service.PodService;
|
import dev.dinauer.service.PodService;
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Pod;
|
import io.fabric8.kubernetes.api.model.Pod;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||||
@ -19,17 +20,12 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class LogResource
|
public class LogResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<String> getLogs(@PathParam("pod-id") String podId)
|
public List<String> getLogs(@PathParam("pod-id") String podId)
|
||||||
@ -38,7 +34,7 @@ public class LogResource
|
|||||||
if(podOptional.isPresent())
|
if(podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
return List.of(client.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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Namespace;
|
import io.fabric8.kubernetes.api.model.Namespace;
|
||||||
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.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@ -18,18 +20,13 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class NamespaceResource
|
public class NamespaceResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Namespace> getNamespaces()
|
public List<Namespace> getNamespaces()
|
||||||
{
|
{
|
||||||
return client.namespaces().list().getItems();
|
return clientProvider.getClient().namespaces().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Node;
|
import io.fabric8.kubernetes.api.model.Node;
|
||||||
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.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@ -22,13 +24,8 @@ import java.util.List;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class NodeResource
|
public class NodeResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ -43,7 +40,7 @@ public class NodeResource
|
|||||||
if(parts.length == 5)
|
if(parts.length == 5)
|
||||||
{
|
{
|
||||||
String name = parts[0];
|
String name = parts[0];
|
||||||
Node node = client.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]);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
import dev.dinauer.service.PodService;
|
import dev.dinauer.service.PodService;
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Pod;
|
import io.fabric8.kubernetes.api.model.Pod;
|
||||||
import io.fabric8.kubernetes.client.ConfigBuilder;
|
import io.fabric8.kubernetes.client.ConfigBuilder;
|
||||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
@ -23,17 +24,12 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class PodResource
|
public class PodResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PodService podService;
|
PodService podService;
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public List<Pod> getPods(@QueryParam("namespace") String namespace)
|
public List<Pod> getPods(@QueryParam("namespace") String namespace)
|
||||||
@ -56,7 +52,8 @@ public class PodResource
|
|||||||
if(podOptional.isPresent())
|
if(podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
client.pods()
|
clientProvider.getClient()
|
||||||
|
.pods()
|
||||||
.inNamespace(pod.getMetadata().getNamespace())
|
.inNamespace(pod.getMetadata().getNamespace())
|
||||||
.withName(pod.getMetadata().getName())
|
.withName(pod.getMetadata().getName())
|
||||||
.delete();
|
.delete();
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package dev.dinauer;
|
package dev.dinauer;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Pod;
|
import io.fabric8.kubernetes.api.model.Pod;
|
||||||
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;
|
||||||
@ -8,6 +9,7 @@ import io.quarkus.runtime.Startup;
|
|||||||
import io.quarkus.security.Authenticated;
|
import io.quarkus.security.Authenticated;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.Produces;
|
import jakarta.ws.rs.Produces;
|
||||||
@ -23,13 +25,8 @@ import java.util.Optional;
|
|||||||
@Authenticated
|
@Authenticated
|
||||||
public class ServiceResource
|
public class ServiceResource
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ -37,8 +34,8 @@ public class ServiceResource
|
|||||||
{
|
{
|
||||||
if(namespace.isPresent())
|
if(namespace.isPresent())
|
||||||
{
|
{
|
||||||
return client.services().inNamespace(namespace.get()).list().getItems();
|
return clientProvider.getClient().services().inNamespace(namespace.get()).list().getItems();
|
||||||
}
|
}
|
||||||
return client.services().list().getItems();
|
return clientProvider.getClient().services().list().getItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package dev.dinauer.service;
|
package dev.dinauer.service;
|
||||||
|
|
||||||
|
import dev.dinauer.utils.ClientProvider;
|
||||||
import io.fabric8.kubernetes.api.model.Pod;
|
import io.fabric8.kubernetes.api.model.Pod;
|
||||||
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 jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -12,27 +14,22 @@ import java.util.Optional;
|
|||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class PodService
|
public class PodService
|
||||||
{
|
{
|
||||||
private KubernetesClient client;
|
@Inject
|
||||||
|
ClientProvider clientProvider;
|
||||||
@PostConstruct
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
client = new KubernetesClientBuilder().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Pod> findByNamespace(String namespace)
|
public List<Pod> findByNamespace(String namespace)
|
||||||
{
|
{
|
||||||
return client.pods().inNamespace(namespace).list().getItems();
|
return clientProvider.getClient().pods().inNamespace(namespace).list().getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pod> findAll()
|
public List<Pod> findAll()
|
||||||
{
|
{
|
||||||
return client.pods().list().getItems();
|
return clientProvider.getClient().pods().list().getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Pod> findPodById(String id)
|
public Optional<Pod> findPodById(String id)
|
||||||
{
|
{
|
||||||
for(Pod pod : client.pods().list().getItems())
|
for(Pod pod : clientProvider.getClient().pods().list().getItems())
|
||||||
{
|
{
|
||||||
if(pod.getMetadata().getUid().equals(id))
|
if(pod.getMetadata().getUid().equals(id))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,18 +1,21 @@
|
|||||||
package dev.dinauer.utils;
|
package dev.dinauer.utils;
|
||||||
|
|
||||||
|
import io.fabric8.kubernetes.client.Config;
|
||||||
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||||
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.File;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class ClientProvider
|
public class ClientProvider
|
||||||
{
|
{
|
||||||
@ConfigProperty(name = "dev.dinauer.kobooboo.kubeconfigs.dir")
|
@ConfigProperty(name = "dev.dinauer.kobooboo.kubeconfigs.dir")
|
||||||
String configDir;
|
String configFilePath;
|
||||||
|
|
||||||
public void getClient()
|
public KubernetesClient getClient()
|
||||||
{
|
{
|
||||||
|
return new KubernetesClientBuilder().withConfig(Config.fromKubeconfig(new File(configFilePath))).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,9 @@ quarkus.http.root-path=/api
|
|||||||
%dev.quarkus.http.cors.origins=/.*/
|
%dev.quarkus.http.cors.origins=/.*/
|
||||||
%dev.quarkus.http.port=9090
|
%dev.quarkus.http.port=9090
|
||||||
|
|
||||||
dev.dinauer.kobooboo.kubeconfigs.dir=/var/lib/kubooboo/configs
|
dev.dinauer.kobooboo.kubeconfigs.dir=/var/lib/kubooboo/config
|
||||||
dev.dinauer.kubooboo.work.dir=/var/lib/kubooboo/work
|
dev.dinauer.kubooboo.work.dir=/var/lib/kubooboo/work
|
||||||
|
%dev.dev.dinauer.kobooboo.kubeconfigs.dir=C:\\Users\\andre\\.kube\\config
|
||||||
%dev.dev.dinauer.kubooboo.work.dir=C:\\Users\\andre\\Documents\\dev\\kubeman\\backend\\src\\main\\resources\\dev
|
%dev.dev.dinauer.kubooboo.work.dir=C:\\Users\\andre\\Documents\\dev\\kubeman\\backend\\src\\main\\resources\\dev
|
||||||
|
|
||||||
# Keys
|
# Keys
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user