45 lines
1.0 KiB
Java
45 lines
1.0 KiB
Java
package dev.dinauer.service;
|
|
|
|
import io.fabric8.kubernetes.api.model.Pod;
|
|
import io.fabric8.kubernetes.client.KubernetesClient;
|
|
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
|
|
import jakarta.annotation.PostConstruct;
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
@ApplicationScoped
|
|
public class PodService
|
|
{
|
|
private KubernetesClient client;
|
|
|
|
@PostConstruct
|
|
void init()
|
|
{
|
|
client = new KubernetesClientBuilder().build();
|
|
}
|
|
|
|
public List<Pod> findByNamespace(String namespace)
|
|
{
|
|
return client.pods().inNamespace(namespace).list().getItems();
|
|
}
|
|
|
|
public List<Pod> findAll()
|
|
{
|
|
return client.pods().list().getItems();
|
|
}
|
|
|
|
public Optional<Pod> findPodById(String id)
|
|
{
|
|
for(Pod pod : client.pods().list().getItems())
|
|
{
|
|
if(pod.getMetadata().getUid().equals(id))
|
|
{
|
|
return Optional.of(pod);
|
|
}
|
|
}
|
|
return Optional.empty();
|
|
}
|
|
}
|