Skip to content
Snippets Groups Projects
Commit b345a06d authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Resolve "Move application availability checks from Janitor to Platform"

parent 44c91d73
Branches
No related tags found
2 merge requests!273Release 1.8.0 update,!260Resolve "Move application availability checks from Janitor to Platform"
...@@ -3,8 +3,12 @@ package net.geant.nmaas.kubernetes; ...@@ -3,8 +3,12 @@ package net.geant.nmaas.kubernetes;
import io.fabric8.kubernetes.api.model.Namespace; import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder; import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentList;
import io.fabric8.kubernetes.api.model.apps.StatefulSet; import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSetList;
import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.geant.nmaas.kubernetes.remote.entities.KCluster; import net.geant.nmaas.kubernetes.remote.entities.KCluster;
...@@ -47,9 +51,13 @@ public class KubernetesApiClientService { ...@@ -47,9 +51,13 @@ public class KubernetesApiClientService {
public Deployment getDeployment(KCluster kCluster, String namespace, String deploymentName) { public Deployment getDeployment(KCluster kCluster, String namespace, String deploymentName) {
try (KubernetesClient client = initClient(kCluster)) { try (KubernetesClient client = initClient(kCluster)) {
return client.apps() NonNamespaceOperation<Deployment, DeploymentList, RollableScalableResource<Deployment>> deploymentsInNamespace = client.apps()
.deployments() .deployments()
.inNamespace(namespace) .inNamespace(namespace);
log.debug("Found the following deployments in namespace {} -> {}",
namespace,
deploymentsInNamespace.list().getItems().stream().map(d -> d.getMetadata().getName()).toList());
return deploymentsInNamespace
.withName(deploymentName) .withName(deploymentName)
.get(); .get();
} }
...@@ -57,9 +65,13 @@ public class KubernetesApiClientService { ...@@ -57,9 +65,13 @@ public class KubernetesApiClientService {
public StatefulSet getStatefulSet(KCluster kCluster, String statefulSetName, String namespace) { public StatefulSet getStatefulSet(KCluster kCluster, String statefulSetName, String namespace) {
try (KubernetesClient client = initClient(kCluster)) { try (KubernetesClient client = initClient(kCluster)) {
return client.apps() NonNamespaceOperation<StatefulSet, StatefulSetList, RollableScalableResource<StatefulSet>> statefulSetsInNamespace = client.apps()
.statefulSets() .statefulSets()
.inNamespace(namespace) .inNamespace(namespace);
log.debug("Found the following statefulsets in namespace {} -> {}",
namespace,
statefulSetsInNamespace.list().getItems().stream().map(d -> d.getMetadata().getName()).toList());
return statefulSetsInNamespace
.withName(statefulSetName) .withName(statefulSetName)
.get(); .get();
} }
......
...@@ -54,7 +54,10 @@ public class KubernetesApiJanitorService { ...@@ -54,7 +54,10 @@ public class KubernetesApiJanitorService {
if (Objects.nonNull(statefulSet)) { if (Objects.nonNull(statefulSet)) {
return Objects.equals(statefulSet.getSpec().getReplicas(), statefulSet.getStatus().getReadyReplicas()); return Objects.equals(statefulSet.getSpec().getReplicas(), statefulSet.getStatus().getReadyReplicas());
} }
throw new JanitorResponseException(""); log.info("StatefulSet not found as well");
throw new JanitorResponseException(
String.format("Not able to check application state. No deployment/statefulset with name %s found in namespace %s", deploymentId.value(), namespace)
);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment