✨ Add namespace, pvc, pv and stateful sets
This commit is contained in:
parent
33f95bad5a
commit
f52cba81d5
4
pom.xml
4
pom.xml
@ -73,6 +73,10 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-websockets</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-mutiny</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Hibernate ORM specific dependencies -->
|
||||
<dependency>
|
||||
|
||||
@ -45,21 +45,21 @@ public class ResourceResource
|
||||
ConfigMapService configMapService;
|
||||
|
||||
@GET
|
||||
public List<?> get(@PathParam("resource") String resourceType)
|
||||
public List<?> get(@PathParam("resource") ResourceType resourceType)
|
||||
{
|
||||
return getService(resourceType).findAll();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{namespace}")
|
||||
public List<?> getByNamespace(@PathParam("resource") String resourceType, @PathParam("namespace") String namespace)
|
||||
public List<?> getByNamespace(@PathParam("resource") ResourceType resourceType, @PathParam("namespace") String namespace)
|
||||
{
|
||||
return getService(resourceType).findByNamespace(namespace);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{namespace}/{name}")
|
||||
public Object getByNamespaceAndName(@PathParam("resource") String resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name)
|
||||
public Object getByNamespaceAndName(@PathParam("resource") ResourceType resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name)
|
||||
{
|
||||
Optional<?> resourceOptional = getService(resourceType).findOptionalByNameAndNamespace(name, namespace);
|
||||
if (resourceOptional.isPresent())
|
||||
@ -71,7 +71,7 @@ public class ResourceResource
|
||||
|
||||
@DELETE
|
||||
@Path("/{namespace}/{name}")
|
||||
public void deleteByNamespaceAndName(@PathParam("resource") String resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name)
|
||||
public void deleteByNamespaceAndName(@PathParam("resource") ResourceType resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name)
|
||||
{
|
||||
getService(resourceType).delete(name, namespace);
|
||||
}
|
||||
@ -81,7 +81,7 @@ public class ResourceResource
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
@Produces
|
||||
@RolesAllowed("admin")
|
||||
public void rescaleDeployment(@PathParam("resource") String resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name, Integer replicaCount)
|
||||
public void rescaleDeployment(@PathParam("resource") ResourceType resourceType, @PathParam("namespace") String namespace, @PathParam("name") String name, Integer replicaCount)
|
||||
{
|
||||
if (ResourceType.DEPLOYMENT.equals(resourceType))
|
||||
{
|
||||
@ -96,7 +96,7 @@ public class ResourceResource
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceService<?> getService(String resourceType)
|
||||
private ResourceService<?> getService(ResourceType resourceType)
|
||||
{
|
||||
switch (resourceType)
|
||||
{
|
||||
|
||||
@ -1,14 +1,46 @@
|
||||
package dev.dinauer;
|
||||
|
||||
public class ResourceType
|
||||
public enum ResourceType
|
||||
{
|
||||
public static final String STATEFUL_SET = "stateful-sets";
|
||||
public static final String DEPLOYMENT = "deployments";
|
||||
public static final String SERVICE = "services";
|
||||
public static final String INGRESS = "ingresses";
|
||||
public static final String POD = "pods";
|
||||
public static final String CUSTOM_RESOURCE_DEFINITION = "custom-resource-definitions";
|
||||
public static final String NODE = "nodes";
|
||||
public static final String SECRET = "secrets";
|
||||
public static final String CONFIG_MAP = "config-maps";
|
||||
// Cluster Resources
|
||||
NODE("nodes"),
|
||||
NAMESPACE("namespaces"),
|
||||
CUSTOM_RESOURCE_DEFINITION("custom-resource-definitions"),
|
||||
|
||||
// Workloads
|
||||
STATEFUL_SET("stateful-sets"),
|
||||
DEPLOYMENT("deployments"),
|
||||
POD("pods"),
|
||||
|
||||
// Networking
|
||||
SERVICE("services"),
|
||||
INGRESS("ingresses"),
|
||||
|
||||
// Config
|
||||
SECRET("secrets"),
|
||||
CONFIG_MAP("config-maps"),
|
||||
|
||||
// Storage
|
||||
PVC("pvcs"),
|
||||
PV("pvs");
|
||||
|
||||
private final String value;
|
||||
|
||||
ResourceType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ResourceType fromString(String text) {
|
||||
for (ResourceType type : ResourceType.values()) {
|
||||
if (type.value.equalsIgnoreCase(text)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown resource type: " + text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.dinauer.ResourceEvent;
|
||||
import dev.dinauer.ResourceType;
|
||||
import dev.dinauer.service.ResourceService;
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
@ -50,44 +51,23 @@ public class ResourceWebsocket
|
||||
@Inject
|
||||
JWTParser parser;
|
||||
|
||||
@Inject
|
||||
ServiceFactory serviceFactory;
|
||||
|
||||
private final Map<Session, Watch> sessions = new HashMap<>();
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("resource-type") String resourceType, @PathParam("namespace") String namespace) throws ParseException
|
||||
public void onOpen(Session session, @PathParam("resource-type") String rawResourceType, @PathParam("namespace") String namespace) throws ParseException
|
||||
{
|
||||
ResourceType resourceType = ResourceType.fromString(rawResourceType);
|
||||
JsonWebToken token = getToken(session.getQueryString());
|
||||
if (isValid(token))
|
||||
{
|
||||
executor.runAsync(() ->
|
||||
{
|
||||
if (ResourceType.POD.equals(resourceType))
|
||||
{
|
||||
String version = clientProvider.getClient().pods().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (isGlobal(namespace))
|
||||
{
|
||||
send(session, EventType.INIT, clientProvider.getClient().pods().inAnyNamespace().list().getItems());
|
||||
sessions.put(session, clientProvider.getClient().pods().inAnyNamespace().withResourceVersion(version).watch(getWatcher(session)));
|
||||
}
|
||||
else
|
||||
{
|
||||
send(session, EventType.INIT, clientProvider.getClient().pods().inNamespace(namespace).list().getItems());
|
||||
sessions.put(session, clientProvider.getClient().pods().inNamespace(namespace).withResourceVersion(version).watch(getWatcher(session)));
|
||||
}
|
||||
}
|
||||
if (ResourceType.CONFIG_MAP.equals(resourceType))
|
||||
{
|
||||
String version = clientProvider.getClient().configMaps().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (isGlobal(namespace))
|
||||
{
|
||||
send(session, EventType.INIT, clientProvider.getClient().configMaps().inAnyNamespace().list().getItems());
|
||||
sessions.put(session, clientProvider.getClient().configMaps().inAnyNamespace().withResourceVersion(version).watch(getWatcher(session)));
|
||||
}
|
||||
else
|
||||
{
|
||||
send(session, EventType.INIT, clientProvider.getClient().configMaps().inNamespace(namespace).list().getItems());
|
||||
sessions.put(session, clientProvider.getClient().configMaps().inNamespace(namespace).withResourceVersion(version).watch(getWatcher(session)));
|
||||
}
|
||||
}
|
||||
ResourceService<?> service = serviceFactory.getService(resourceType);
|
||||
send(session, EventType.INIT, service.findByNamespace(namespace));
|
||||
sessions.put(session, service.watch(namespace, getWatcher(session)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
111
src/main/java/dev/dinauer/inspect/websocket/ServiceFactory.java
Normal file
111
src/main/java/dev/dinauer/inspect/websocket/ServiceFactory.java
Normal file
@ -0,0 +1,111 @@
|
||||
package dev.dinauer.inspect.websocket;
|
||||
|
||||
import dev.dinauer.ResourceType;
|
||||
import dev.dinauer.service.*;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ServiceFactory
|
||||
{
|
||||
@Inject
|
||||
Logger LOG;
|
||||
|
||||
@Inject
|
||||
StatefulSetService statefulSetService;
|
||||
|
||||
@Inject
|
||||
DeploymentService deploymentService;
|
||||
|
||||
@Inject
|
||||
PodService podService;
|
||||
|
||||
@Inject
|
||||
CustomResourceDefinitionService customResourceDefinitionService;
|
||||
|
||||
@Inject
|
||||
IngressService ingressService;
|
||||
|
||||
@Inject
|
||||
ServiceService serviceService;
|
||||
|
||||
@Inject
|
||||
NodeService nodeService;
|
||||
|
||||
@Inject
|
||||
SecretService secretService;
|
||||
|
||||
@Inject
|
||||
ConfigMapService configMapService;
|
||||
|
||||
@Inject
|
||||
PvcService pvcService;
|
||||
|
||||
@Inject
|
||||
PvService pvService;
|
||||
|
||||
@Inject
|
||||
NamespaceService namespaceService;
|
||||
|
||||
public ResourceService<?> getService(ResourceType resourceType)
|
||||
{
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.STATEFUL_SET ->
|
||||
{
|
||||
return statefulSetService;
|
||||
}
|
||||
case ResourceType.DEPLOYMENT ->
|
||||
{
|
||||
return deploymentService;
|
||||
}
|
||||
case ResourceType.SERVICE ->
|
||||
{
|
||||
return serviceService;
|
||||
}
|
||||
case ResourceType.INGRESS ->
|
||||
{
|
||||
return ingressService;
|
||||
}
|
||||
case ResourceType.POD ->
|
||||
{
|
||||
return podService;
|
||||
}
|
||||
case ResourceType.CUSTOM_RESOURCE_DEFINITION ->
|
||||
{
|
||||
return customResourceDefinitionService;
|
||||
}
|
||||
case ResourceType.NODE ->
|
||||
{
|
||||
return nodeService;
|
||||
}
|
||||
case ResourceType.SECRET ->
|
||||
{
|
||||
return secretService;
|
||||
}
|
||||
case ResourceType.CONFIG_MAP ->
|
||||
{
|
||||
return configMapService;
|
||||
}
|
||||
case ResourceType.PVC ->
|
||||
{
|
||||
return pvcService;
|
||||
}
|
||||
case ResourceType.PV ->
|
||||
{
|
||||
return pvService;
|
||||
}
|
||||
case ResourceType.NAMESPACE ->
|
||||
{
|
||||
return namespaceService;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
LOG.errorf("Invalid resource type %s.", resourceType);
|
||||
throw new BadRequestException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,8 +20,6 @@ import java.util.Optional;
|
||||
@ApplicationScoped
|
||||
public class LoginResource
|
||||
{
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Inject
|
||||
Logger LOG;
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.ConfigMap;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.resteasy.reactive.common.NotImplementedYet;
|
||||
@ -30,6 +32,10 @@ public class ConfigMapService implements ResourceService<ConfigMap>
|
||||
@Override
|
||||
public List<ConfigMap> findByNamespace(String namespace)
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().configMaps().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return clientProvider.getClient().configMaps().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
|
||||
@ -44,4 +50,15 @@ public class ConfigMapService implements ResourceService<ConfigMap>
|
||||
{
|
||||
throw new NotImplementedYet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<ConfigMap> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().configMaps().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().configMaps().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return clientProvider.getClient().configMaps().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import io.fabric8.kubernetes.client.dsl.ApiextensionsAPIGroupDSL;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@ -48,4 +50,10 @@ public class CustomResourceDefinitionService implements ResourceService<CustomRe
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<CustomResourceDefinition> watcher)
|
||||
{
|
||||
throw new NotImplementedYet();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.apps.Deployment;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@ -33,6 +35,10 @@ public class DeploymentService implements ResourceService<Deployment>
|
||||
{
|
||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.deployments().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return dsl.deployments().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
}
|
||||
@ -51,6 +57,19 @@ public class DeploymentService implements ResourceService<Deployment>
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Deployment> watcher)
|
||||
{
|
||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
||||
String version = dsl.deployments().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.deployments().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return dsl.deployments().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
|
||||
public void rescale(String namespace, String name, int replicaCount)
|
||||
{
|
||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||
|
||||
@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.ObjectMeta;
|
||||
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import io.fabric8.kubernetes.client.dsl.NetworkAPIGroupDSL;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@ -47,6 +49,10 @@ public class IngressService implements ResourceService<Ingress>
|
||||
{
|
||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.v1().ingresses().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return dsl.v1().ingresses().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
}
|
||||
@ -64,4 +70,18 @@ public class IngressService implements ResourceService<Ingress>
|
||||
{
|
||||
return Optional.ofNullable(findByNameAndNamespace(name, namespace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Ingress> watcher)
|
||||
{
|
||||
try(NetworkAPIGroupDSL dsl = clientProvider.getClient().network())
|
||||
{
|
||||
String version = dsl.v1().ingresses().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.v1().ingresses().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return dsl.v1().ingresses().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
src/main/java/dev/dinauer/service/NamespaceService.java
Normal file
55
src/main/java/dev/dinauer/service/NamespaceService.java
Normal file
@ -0,0 +1,55 @@
|
||||
package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.Namespace;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class NamespaceService implements ResourceService<Namespace>
|
||||
{
|
||||
@Inject
|
||||
ClientProvider clientProvider;
|
||||
|
||||
@Override
|
||||
public void delete(String name, String namespace)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Namespace findByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Namespace> findByNamespace(String namespace)
|
||||
{
|
||||
return clientProvider.getClient().namespaces().list().getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Namespace> findAll()
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Namespace> findOptionalByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Namespace> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().namespaces().list().getMetadata().getResourceVersion();
|
||||
return clientProvider.getClient().namespaces().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,9 @@ package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.monitoring.TopNodesService;
|
||||
import dev.dinauer.monitoring.nodes.MonitoredNode;
|
||||
import io.fabric8.kubernetes.api.model.Node;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.resteasy.reactive.common.NotImplementedYet;
|
||||
@ -42,4 +45,10 @@ public class NodeService implements ResourceService<MonitoredNode>
|
||||
{
|
||||
throw new NotImplementedYet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<MonitoredNode> watcher)
|
||||
{
|
||||
throw new NotImplementedYet();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,9 +3,12 @@ package dev.dinauer.service;
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.resteasy.reactive.common.NotImplementedYet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,6 +43,10 @@ public class PodService implements ResourceService<Pod>
|
||||
|
||||
public List<Pod> findByNamespace(String namespace)
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().pods().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return clientProvider.getClient().pods().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
|
||||
@ -72,6 +79,17 @@ public class PodService implements ResourceService<Pod>
|
||||
return Optional.ofNullable(findByNameAndNamespace(name, namespace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Pod> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().pods().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().pods().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return clientProvider.getClient().pods().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
|
||||
public Optional<Pod> findPodById(String id)
|
||||
{
|
||||
for(Pod pod : clientProvider.getClient().pods().inAnyNamespace().list().getItems())
|
||||
|
||||
55
src/main/java/dev/dinauer/service/PvService.java
Normal file
55
src/main/java/dev/dinauer/service/PvService.java
Normal file
@ -0,0 +1,55 @@
|
||||
package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.PersistentVolume;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PvService implements ResourceService<PersistentVolume>
|
||||
{
|
||||
@Inject
|
||||
ClientProvider clientProvider;
|
||||
|
||||
@Override
|
||||
public void delete(String name, String namespace)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentVolume findByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersistentVolume> findByNamespace(String namespace)
|
||||
{
|
||||
return clientProvider.getClient().persistentVolumes().list().getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersistentVolume> findAll()
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PersistentVolume> findOptionalByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<PersistentVolume> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().persistentVolumes().list().getMetadata().getResourceVersion();
|
||||
return clientProvider.getClient().persistentVolumes().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
63
src/main/java/dev/dinauer/service/PvcService.java
Normal file
63
src/main/java/dev/dinauer/service/PvcService.java
Normal file
@ -0,0 +1,63 @@
|
||||
package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PvcService implements ResourceService<PersistentVolumeClaim>
|
||||
{
|
||||
@Inject
|
||||
ClientProvider clientProvider;
|
||||
|
||||
@Override
|
||||
public void delete(String name, String namespace)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentVolumeClaim findByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersistentVolumeClaim> findByNamespace(String namespace)
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().persistentVolumeClaims().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return clientProvider.getClient().persistentVolumeClaims().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PersistentVolumeClaim> findAll()
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PersistentVolumeClaim> findOptionalByNameAndNamespace(String name, String namespace)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<PersistentVolumeClaim> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().persistentVolumeClaims().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().persistentVolumeClaims().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return clientProvider.getClient().persistentVolumeClaims().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package dev.dinauer.service;
|
||||
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -10,4 +13,5 @@ public interface ResourceService<T>
|
||||
List<T> findByNamespace(String namespace);
|
||||
List<T> findAll();
|
||||
Optional<T> findOptionalByNameAndNamespace(String name, String namespace);
|
||||
Watch watch(String namespace, Watcher<T> watcher);
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.Secret;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.resteasy.reactive.common.NotImplementedYet;
|
||||
@ -30,6 +32,10 @@ public class SecretService implements ResourceService<Secret>
|
||||
@Override
|
||||
public List<Secret> findByNamespace(String namespace)
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().secrets().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return clientProvider.getClient().secrets().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
|
||||
@ -44,4 +50,15 @@ public class SecretService implements ResourceService<Secret>
|
||||
{
|
||||
throw new NotImplementedYet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Secret> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().secrets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().secrets().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return clientProvider.getClient().secrets().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@ import io.fabric8.kubernetes.api.model.Pod;
|
||||
import io.fabric8.kubernetes.api.model.Service;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@ -33,6 +35,10 @@ public class ServiceService implements ResourceService<Service>
|
||||
|
||||
public List<Service> findByNamespace(String namespace)
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().services().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return clientProvider.getClient().services().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
|
||||
@ -47,6 +53,17 @@ public class ServiceService implements ResourceService<Service>
|
||||
return Optional.ofNullable(findByNameAndNamespace(name, namespace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<Service> watcher)
|
||||
{
|
||||
String version = clientProvider.getClient().services().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return clientProvider.getClient().services().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return clientProvider.getClient().services().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
|
||||
public Optional<Service> findById(String id)
|
||||
{
|
||||
for(Service service : clientProvider.getClient().services().list().getItems())
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
package dev.dinauer.service;
|
||||
|
||||
import dev.dinauer.utils.ClientProvider;
|
||||
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
|
||||
import io.fabric8.kubernetes.client.Watch;
|
||||
import io.fabric8.kubernetes.client.Watcher;
|
||||
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.resteasy.reactive.common.NotImplementedYet;
|
||||
|
||||
import java.util.List;
|
||||
@ -11,6 +16,9 @@ import java.util.Optional;
|
||||
public class StatefulSetService implements ResourceService<StatefulSet>
|
||||
{
|
||||
|
||||
@Inject
|
||||
ClientProvider clientProvider;
|
||||
|
||||
@Override
|
||||
public void delete(String name, String namespace)
|
||||
{
|
||||
@ -26,7 +34,14 @@ public class StatefulSetService implements ResourceService<StatefulSet>
|
||||
@Override
|
||||
public List<StatefulSet> findByNamespace(String namespace)
|
||||
{
|
||||
return List.of();
|
||||
try(AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||
{
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.statefulSets().inAnyNamespace().list().getItems();
|
||||
}
|
||||
return dsl.statefulSets().inNamespace(namespace).list().getItems();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,4 +55,17 @@ public class StatefulSetService implements ResourceService<StatefulSet>
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Watch watch(String namespace, Watcher<StatefulSet> watcher)
|
||||
{
|
||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
||||
String version = dsl.statefulSets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||
if (namespace.equals("_all"))
|
||||
{
|
||||
return dsl.statefulSets().inAnyNamespace().withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
return dsl.statefulSets().inNamespace(namespace).withResourceVersion(version).watch(watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,4 +23,7 @@ quarkus.datasource.db-kind = postgresql
|
||||
%prod.quarkus.datasource.username=${DB_USER}
|
||||
%prod.quarkus.datasource.password=${DB_PASSWORD}
|
||||
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_DATABASE}?currentSchema=${DB_SCHEMA}
|
||||
%prod.quarkus.hibernate-orm.schema-management.strategy=drop-and-create
|
||||
%prod.quarkus.hibernate-orm.schema-management.strategy=drop-and-create
|
||||
|
||||
# Banner
|
||||
quarkus.banner.path=banner.txt
|
||||
5
src/main/resources/banner.txt
Normal file
5
src/main/resources/banner.txt
Normal file
@ -0,0 +1,5 @@
|
||||
__ __ __ __
|
||||
/ //_/_ __/ /_ ____ ____ / /_ ____ ____
|
||||
/ ,< / / / / __ \/ __ \/ __ \/ __ \/ __ \/ __ \
|
||||
/ /| / /_/ / /_/ / /_/ / /_/ / /_/ / /_/ / /_/ /
|
||||
/_/ |_\__,_/_.___/\____/\____/_.___/\____/\____/
|
||||
@ -1,11 +1,11 @@
|
||||
INSERT INTO monitoring_config (id, config_name, type, interval)
|
||||
VALUES ('5da234f4-3a34-4b1c-b72a-7330ca3b1dcf', 'Postgres Cluster', 'VOLUME', '30s');
|
||||
VALUES ('5da234f4-3a34-4b1c-b72a-7330ca3b1dcf', 'Postgres Cluster', 'VOLUME', '10m');
|
||||
INSERT INTO target_config (id, type, namespace, labels, deployment_name, stateful_set_name, config_id)
|
||||
VALUES ('4bd2f449-ed11-4f3f-830a-e4dc39cb21f5', 'LABELS', 'tavolio-prod', '{"cnpg.io/cluster":"postgres-cluster"}', null, null, '5da234f4-3a34-4b1c-b72a-7330ca3b1dcf');
|
||||
INSERT INTO volume_config (id, container_name, mount_path, config_id)
|
||||
VALUES ('4090a60c-4517-4d76-b460-a0454014f30d', 'postgres', '/var/lib/postgresql/data', '5da234f4-3a34-4b1c-b72a-7330ca3b1dcf');
|
||||
|
||||
INSERT INTO monitoring_config (id, config_name, type, interval)
|
||||
VALUES ('2da234f4-3a34-4b1c-b72a-7330ca3b1dcf', 'Postgres Cluster', 'MEMORY', '40s');
|
||||
VALUES ('2da234f4-3a34-4b1c-b72a-7330ca3b1dcf', 'Postgres Cluster', 'MEMORY', '10m');
|
||||
INSERT INTO target_config (id, type, namespace, labels, deployment_name, stateful_set_name, config_id)
|
||||
VALUES ('2bd2f449-ed11-4f3f-830a-e4dc39cb21f5', 'LABELS', 'tavolio-prod', '{"cnpg.io/cluster":"postgres-cluster"}', null, null, '2da234f4-3a34-4b1c-b72a-7330ca3b1dcf');
|
||||
Loading…
x
Reference in New Issue
Block a user