Skip to content

Commit

Permalink
💿 sts progressing status (#581)
Browse files Browse the repository at this point in the history
* sts progressing status

* ready replicas
  • Loading branch information
petar-cvit authored Sep 20, 2024
1 parent e057ec6 commit 28a2593
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cyclops-ctrl/pkg/cluster/k8sclient/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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 := ""

Expand All @@ -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
}

0 comments on commit 28a2593

Please sign in to comment.