From 110c455ace22e7cc8c17faa70c10f7a7f2256d97 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Thu, 23 Feb 2023 15:10:01 +0000 Subject: Adding KubernetesClient tests Change-Id: Icf6b8b265dc432fe97a6fbb8d9c6cd9e0f1a2e95 Issue-ID: SO-4052 Signed-off-by: waqas.ikram --- .../kubernetes/KubernetesClientImpl.java | 50 +++++++++++----------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org') diff --git a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java index 06f0add..5018091 100644 --- a/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java +++ b/so-cnfm/so-cnfm-lcm/so-cnfm-lcm-bpmn-flows/src/main/java/org/onap/so/cnfm/lcm/bpmn/flows/extclients/kubernetes/KubernetesClientImpl.java @@ -752,19 +752,13 @@ public class KubernetesClientImpl implements KubernetesClient { final Optional optional = getPodReadyCondition(pod); if (optional.isPresent()) { final V1PodCondition condition = optional.get(); - if (TRUE_STRING.equalsIgnoreCase(condition.getStatus())) { - logger.debug("Pod is Ready..."); - return true; - } - + return TRUE_STRING.equalsIgnoreCase(condition.getStatus()); } - logger.debug("Pod is not ready ..."); return false; } private boolean isServiceReady(final V1Service service) { - logger.debug("V1Service is Ready ..."); return true; } @@ -772,32 +766,35 @@ public class KubernetesClientImpl implements KubernetesClient { final V1DeploymentSpec spec = deployment.getSpec(); final V1DeploymentStatus status = deployment.getStatus(); - if (status != null && status.getReplicas() != null && status.getAvailableReplicas() != null && spec != null - && spec.getReplicas() != null) { - if (spec.getReplicas().intValue() == status.getReplicas().intValue() - && status.getAvailableReplicas().intValue() <= spec.getReplicas().intValue()) { - logger.debug("Deployment is Ready..."); - return true; - } + if (status == null || status.getReplicas() == null || status.getAvailableReplicas() == null) { + logger.debug("AvailableReplicas is null in status"); + return false; } - logger.debug("Deployment is not ready ..."); - return false; + if (spec == null || spec.getReplicas() == null) { + logger.debug("Replicas is null in spec"); + return false; + } + + return spec.getReplicas().intValue() == status.getReplicas().intValue() + && status.getAvailableReplicas().intValue() <= spec.getReplicas().intValue(); } private boolean isReplicaSetReady(final V1ReplicaSet replicaSet) { final V1ReplicaSetSpec spec = replicaSet.getSpec(); final V1ReplicaSetStatus status = replicaSet.getStatus(); - if (status != null && status.getReadyReplicas() != null && spec != null && spec.getReplicas() != null) { - if (spec.getReplicas().intValue() == status.getReadyReplicas().intValue()) { - logger.debug("ReplicaSet is Ready..."); - return true; - } + if (status == null || status.getReadyReplicas() == null) { + logger.debug("ReadyReplicas is null in status"); + return false; } - logger.debug("ReplicaSet is not ready ..."); - return false; + if (spec == null || spec.getReplicas() == null) { + logger.debug("Replicas is null in spec"); + return false; + } + + return spec.getReplicas().intValue() == status.getReadyReplicas().intValue(); } private boolean isDaemonSetReady(final V1DaemonSet daemonSet) { @@ -839,13 +836,11 @@ public class KubernetesClientImpl implements KubernetesClient { return false; } logger.debug("DaemonSet is ready {} out of {} expected pods are ready", numberReady, expectedReady); - logger.debug("DaemonSet is Ready..."); return true; } } - logger.debug("DaemonSet is not ready ..."); return false; } @@ -1030,7 +1025,10 @@ public class KubernetesClientImpl implements KubernetesClient { switch (eventType) { case EVENT_TYPE_ADDED: case EVENT_TYPE_MODIFIED: - return predicate.test(object); + final boolean isReady = predicate.test(object); + logger.debug("{} is {} ...", object != null ? object.getClass().getSimpleName() : object, + isReady ? "ready" : " not ready"); + return isReady; case EVENT_TYPE_DELETED: logger.debug("{} event received marking it as successfully", EVENT_TYPE_DELETED); return true; -- cgit 1.2.3-korg