48 lines
1.3 KiB
Java
48 lines
1.3 KiB
Java
package dev.dinauer;
|
|
|
|
import java.util.List;
|
|
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
|
|
import io.fabric8.kubernetes.api.model.Pod;
|
|
import io.quarkus.security.Authenticated;
|
|
|
|
import dev.dinauer.service.DeploymentService;
|
|
import dev.dinauer.service.PodService;
|
|
|
|
@Path("/resources/deployments")
|
|
@Authenticated
|
|
public class DeploymentResource
|
|
{
|
|
@Inject
|
|
DeploymentService deploymentService;
|
|
|
|
@Inject
|
|
PodService podService;
|
|
|
|
@PATCH
|
|
@Path("/{namespace}/{name}")
|
|
@Consumes(MediaType.TEXT_PLAIN)
|
|
@Produces
|
|
public void rescaleDeployment(@PathParam("namespace") String namespace, @PathParam("name") String name, Integer replicaCount)
|
|
{
|
|
if (namespace != null && !namespace.isBlank() && name != null && !name.isBlank() && replicaCount != null && replicaCount > 0)
|
|
{
|
|
deploymentService.rescale(namespace, name, replicaCount);
|
|
}
|
|
else
|
|
{
|
|
throw new RuntimeException("Namespace or name cannot be null or empty. Replica count cannot be null and must be greater than 0.");
|
|
}
|
|
}
|
|
|
|
@GET
|
|
@Path("/{namespace}/{name}/pods")
|
|
public List<Pod> getPodsByDeployment(String namespace, String name)
|
|
{
|
|
return podService.findByDeployment(namespace, name);
|
|
}
|
|
}
|