Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: health hpa when only second conditions is False #624

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/health/health_hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package health
import (
"encoding/json"
"fmt"
"strings"

autoscalingv1 "k8s.io/api/autoscaling/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
Expand Down Expand Up @@ -132,6 +133,7 @@ func getAutoScalingV1HPAHealth(hpa *autoscalingv1.HorizontalPodAutoscaler) (*Hea
}

func checkConditions(conditions []hpaCondition, progressingStatus *HealthStatus) (*HealthStatus, error) {
healthyMessages := []string{}
for _, condition := range conditions {
if isDegraded(&condition) {
return &HealthStatus{
Expand All @@ -141,13 +143,14 @@ func checkConditions(conditions []hpaCondition, progressingStatus *HealthStatus)
}

if isHealthy(&condition) {
return &HealthStatus{
Status: HealthStatusHealthy,
Message: condition.Message,
}, nil
healthyMessages = append(healthyMessages, condition.Message)
}
}

if len(healthyMessages) > 0 {
return &HealthStatus{Status: HealthStatusHealthy, Message: strings.Join(healthyMessages, ",")}, nil
}

return progressingStatus, nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ func TestJob(t *testing.T) {
func TestHPA(t *testing.T) {
assertAppHealth(t, "./testdata/hpa-v2-healthy.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v2-degraded.yaml", HealthStatusDegraded)
assertAppHealth(t, "./testdata/hpa-v2-degraded-partially.yaml", HealthStatusDegraded)
assertAppHealth(t, "./testdata/hpa-v2-progressing.yaml", HealthStatusProgressing)
assertAppHealth(t, "./testdata/hpa-v2beta2-healthy.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v2beta1-healthy-disabled.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v2beta1-healthy.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v1-degraded.yaml", HealthStatusDegraded)
assertAppHealth(t, "./testdata/hpa-v1-healthy.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v1-degraded-partially.yaml", HealthStatusDegraded)
assertAppHealth(t, "./testdata/hpa-v1-healthy-toofew.yaml", HealthStatusHealthy)
assertAppHealth(t, "./testdata/hpa-v1-progressing.yaml", HealthStatusProgressing)
assertAppHealth(t, "./testdata/hpa-v1-progressing-with-no-annotations.yaml", HealthStatusProgressing)
Expand Down
40 changes: 40 additions & 0 deletions pkg/health/testdata/hpa-v2-degraded-partially.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
creationTimestamp: "2022-01-17T14:22:27Z"
name: sample
uid: 0e6d855e-83ed-4ed5-b80a-461a750f14db
spec:
maxReplicas: 2
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: argocd-server
targetCPUUtilizationPercentage: 80
status:
conditions:
- lastTransitionTime: '2024-09-05T20:20:41Z'
message: the HPA controller was able to get the target's current scale
reason: SucceededGetScale
status: 'True'
type: AbleToScale
- lastTransitionTime: '2024-09-05T20:20:56Z'
message: |
the HPA was unable to compute the replica count: failed to get memory
utilization: unable to get metrics for resource memory: unable to fetch
metrics from resource metrics API: the server could not find the
requested resource (get pods.metrics.k8s.io)
reason: FailedGetResourceMetric
status: 'False'
type: ScalingActive
type: ScalingLimited
currentMetrics:
- resource:
current:
averageUtilization: 6
averageValue: 12m
name: cpu
type: Resource
currentReplicas: 1
desiredReplicas: 1
Loading