Skip to content

Commit

Permalink
fix: Regularize health status messages (#230)
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
  • Loading branch information
jsoref committed Feb 26, 2021
1 parent aae8ded commit f61845b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions pkg/health/health_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,45 @@ func getAppsv1StatefulSetHealth(sts *appsv1.StatefulSet) (*HealthStatus, error)
if sts.Status.ObservedGeneration == 0 || sts.Generation > sts.Status.ObservedGeneration {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for statefulset spec update to be observed...",
Message: "Waiting for statefulset spec update to be observed",
}, nil
}
if sts.Spec.Replicas != nil && sts.Status.ReadyReplicas < *sts.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for %d pods to be ready...", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Waiting for %d pods to be ready", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
if sts.Spec.Replicas != nil && sts.Spec.UpdateStrategy.RollingUpdate.Partition != nil {
if sts.Status.UpdatedReplicas < (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...",
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated",
sts.Status.UpdatedReplicas, (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition)),
}, nil
}
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...", sts.Status.UpdatedReplicas),
Message: fmt.Sprintf("Partitioned roll out complete: %d new pods have been updated", sts.Status.UpdatedReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1.OnDeleteStatefulSetStrategyType {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset has %d ready pods", sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Statefulset has %d ready pods", sts.Status.ReadyReplicas),
}, nil
}
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("waiting for statefulset rolling update to complete %d pods at revision %s...", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
Message: fmt.Sprintf("Waiting for statefulset rolling update to complete %d pods at revision %s", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset rolling update complete %d pods at revision %s...", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
Message: fmt.Sprintf("Statefulset rolling update complete %d pods at revision %s", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
}, nil
}

Expand All @@ -97,45 +97,45 @@ func getAppsv1beta1StatefulSetHealth(sts *appsv1beta1.StatefulSet) (*HealthStatu
if *observedGeneration == 0 || sts.Generation > *observedGeneration {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for statefulset spec update to be observed...",
Message: "Waiting for statefulset spec update to be observed",
}, nil
}
if sts.Spec.Replicas != nil && sts.Status.ReadyReplicas < *sts.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for %d pods to be ready...", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Waiting for %d pods to be ready", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1beta1.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
if sts.Spec.Replicas != nil && sts.Spec.UpdateStrategy.RollingUpdate.Partition != nil {
if sts.Status.UpdatedReplicas < (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...",
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated",
sts.Status.UpdatedReplicas, (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition)),
}, nil
}
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...", sts.Status.UpdatedReplicas),
Message: fmt.Sprintf("Partitioned roll out complete: %d new pods have been updated", sts.Status.UpdatedReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1beta1.OnDeleteStatefulSetStrategyType {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset has %d ready pods", sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Statefulset has %d ready pods", sts.Status.ReadyReplicas),
}, nil
}
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("waiting for statefulset rolling update to complete %d pods at revision %s...", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
Message: fmt.Sprintf("Waiting for statefulset rolling update to complete %d pods at revision %s", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset rolling update complete %d pods at revision %s...", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
Message: fmt.Sprintf("Statefulset rolling update complete %d pods at revision %s", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
}, nil
}

Expand All @@ -144,44 +144,44 @@ func getAppsv1beta2StatefulSetHealth(sts *appsv1beta2.StatefulSet) (*HealthStatu
if sts.Status.ObservedGeneration == 0 || sts.Generation > sts.Status.ObservedGeneration {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: "Waiting for statefulset spec update to be observed...",
Message: "Waiting for statefulset spec update to be observed",
}, nil
}
if sts.Spec.Replicas != nil && sts.Status.ReadyReplicas < *sts.Spec.Replicas {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for %d pods to be ready...", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Waiting for %d pods to be ready", *sts.Spec.Replicas-sts.Status.ReadyReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1beta2.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
if sts.Spec.Replicas != nil && sts.Spec.UpdateStrategy.RollingUpdate.Partition != nil {
if sts.Status.UpdatedReplicas < (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...",
Message: fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated",
sts.Status.UpdatedReplicas, (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition)),
}, nil
}
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...", sts.Status.UpdatedReplicas),
Message: fmt.Sprintf("Partitioned roll out complete: %d new pods have been updated", sts.Status.UpdatedReplicas),
}, nil
}
if sts.Spec.UpdateStrategy.Type == appsv1beta2.OnDeleteStatefulSetStrategyType {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset has %d ready pods", sts.Status.ReadyReplicas),
Message: fmt.Sprintf("Statefulset has %d ready pods", sts.Status.ReadyReplicas),
}, nil
}
if sts.Status.UpdateRevision != sts.Status.CurrentRevision {
return &HealthStatus{
Status: HealthStatusProgressing,
Message: fmt.Sprintf("waiting for statefulset rolling update to complete %d pods at revision %s...", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
Message: fmt.Sprintf("Waiting for statefulset rolling update to complete %d pods at revision %s", sts.Status.UpdatedReplicas, sts.Status.UpdateRevision),
}, nil
}
return &HealthStatus{
Status: HealthStatusHealthy,
Message: fmt.Sprintf("statefulset rolling update complete %d pods at revision %s...", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
Message: fmt.Sprintf("Statefulset rolling update complete %d pods at revision %s", sts.Status.CurrentReplicas, sts.Status.CurrentRevision),
}, nil
}

0 comments on commit f61845b

Please sign in to comment.