From f61c0b31580dbedae1669aa2c597ef949746c822 Mon Sep 17 00:00:00 2001 From: Olivier Levitt Date: Tue, 8 Oct 2024 14:31:43 +0200 Subject: [PATCH] Fix errors ready replicas (#505) --- .../impl/HelmReleaseHealthResolver.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmReleaseHealthResolver.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmReleaseHealthResolver.java index 184a98c6..57207281 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmReleaseHealthResolver.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/HelmReleaseHealthResolver.java @@ -53,8 +53,14 @@ private static List checkHealth( .inNamespace(namespace) .withName(name) .get(); + if (deployment == null) continue; details.setDesired(deployment.getSpec().getReplicas()); - details.setReady(deployment.getStatus().getReadyReplicas()); + // If replicas is 0 then readyReplicas is not defined (and can't be + // different from 0 anyway) + if (deployment.getStatus().getReplicas() > 0 + && deployment.getStatus().getReadyReplicas() != null) { + details.setReady(deployment.getStatus().getReadyReplicas()); + } break; case "StatefulSet": StatefulSet statefulset = @@ -64,8 +70,14 @@ private static List checkHealth( .inNamespace(namespace) .withName(name) .get(); + if (statefulset == null) continue; details.setDesired(statefulset.getSpec().getReplicas()); - details.setReady(statefulset.getStatus().getReadyReplicas()); + // If replicas is 0 then readyReplicas is not defined (and can't be + // different from 0 anyway) + if (statefulset.getStatus().getReplicas() > 0 + && statefulset.getStatus().getReadyReplicas() != null) { + details.setReady(statefulset.getStatus().getReadyReplicas()); + } break; case "DaemonSet": DaemonSet daemonSet = @@ -75,8 +87,14 @@ private static List checkHealth( .inNamespace(namespace) .withName(name) .get(); + if (daemonSet == null) continue; details.setDesired(daemonSet.getStatus().getDesiredNumberScheduled()); - details.setReady(daemonSet.getStatus().getNumberReady()); + // If replicas is 0 then readyReplicas is not defined (and can't be + // different from 0 anyway) + if (daemonSet.getStatus().getNumberAvailable() > 0 + && daemonSet.getStatus().getNumberReady() != null) { + details.setReady(daemonSet.getStatus().getNumberReady()); + } break; default: continue;