From 28a25937861ae92769ca15e22b0d1d0a239b87a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Cvitanovi=C4=87?= <72022639+petar-cvit@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:34:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=BF=20sts=20progressing=20status=20(#5?= =?UTF-8?q?81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * sts progressing status * ready replicas --- cyclops-ctrl/pkg/cluster/k8sclient/modules.go | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/cyclops-ctrl/pkg/cluster/k8sclient/modules.go b/cyclops-ctrl/pkg/cluster/k8sclient/modules.go index a788d7a9..aa8d3521 100644 --- a/cyclops-ctrl/pkg/cluster/k8sclient/modules.go +++ b/cyclops-ctrl/pkg/cluster/k8sclient/modules.go @@ -242,7 +242,7 @@ func (k *KubernetesClient) GetModuleResourcesHealth(name string) (string, error) resourcesWithHealth += len(deployments.Items) for _, item := range deployments.Items { - if isProgressing(item.Status.Conditions) { + if isDeploymentProgressing(item.Status.Conditions) { return statusProgressing, nil } @@ -262,6 +262,10 @@ func (k *KubernetesClient) GetModuleResourcesHealth(name string) (string, error) resourcesWithHealth += len(statefulsets.Items) for _, item := range statefulsets.Items { + if isStatefulSetProgressing(item.Status, item.Spec.Replicas, item.Generation) { + return statusProgressing, nil + } + if item.Generation != item.Status.ObservedGeneration || item.Status.Replicas != item.Status.UpdatedReplicas || item.Status.Replicas != item.Status.AvailableReplicas { @@ -757,7 +761,7 @@ func containerStatus(status apiv1.ContainerStatus) dto.ContainerStatus { } func getDeploymentStatus(deployment *appsv1.Deployment) string { - if isProgressing(deployment.Status.Conditions) { + if isDeploymentProgressing(deployment.Status.Conditions) { return statusProgressing } @@ -777,6 +781,10 @@ func getStatefulSetStatus(statefulset *appsv1.StatefulSet) string { return statusHealthy } + if isStatefulSetProgressing(statefulset.Status, statefulset.Spec.Replicas, statefulset.Generation) { + return statusProgressing + } + return statusUnhealthy } @@ -800,7 +808,7 @@ func getPodStatus(containers []dto.Container) bool { return true } -func isProgressing(conditions []appsv1.DeploymentCondition) bool { +func isDeploymentProgressing(conditions []appsv1.DeploymentCondition) bool { progressingReason := "" availableReason := "" @@ -823,3 +831,19 @@ func isProgressing(conditions []appsv1.DeploymentCondition) bool { progressingReason == "FoundNewReplicaSet" || progressingReason == "ReplicaSetUpdated") } + +func isStatefulSetProgressing(status appsv1.StatefulSetStatus, desiredReplicas *int32, generation int64) bool { + if status.ObservedGeneration == 0 || generation > status.ObservedGeneration { + return true + } + + if status.CurrentRevision != status.UpdateRevision { + return true + } + + if desiredReplicas == nil { + return false + } + + return status.ReadyReplicas < *desiredReplicas || status.UpdatedReplicas < *desiredReplicas +}