Skip to content

Commit e460207

Browse files
committed
fix: health hpa when only second conditions is False
Signed-off-by: Arnaud Farbos <[email protected]>
1 parent bd7681a commit e460207

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

pkg/health/health_hpa.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package health
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67

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

134135
func checkConditions(conditions []hpaCondition, progressingStatus *HealthStatus) (*HealthStatus, error) {
136+
healthyMessages := []string{}
135137
for _, condition := range conditions {
136138
if isDegraded(&condition) {
137139
return &HealthStatus{
@@ -141,13 +143,14 @@ func checkConditions(conditions []hpaCondition, progressingStatus *HealthStatus)
141143
}
142144

143145
if isHealthy(&condition) {
144-
return &HealthStatus{
145-
Status: HealthStatusHealthy,
146-
Message: condition.Message,
147-
}, nil
146+
healthyMessages = append(healthyMessages, condition.Message)
148147
}
149148
}
150149

150+
if len(conditions) == len(healthyMessages) {
151+
return &HealthStatus{Status: HealthStatusHealthy, Message: strings.Join(healthyMessages, ",")}, nil
152+
}
153+
151154
return progressingStatus, nil
152155
}
153156

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: autoscaling/v2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
creationTimestamp: "2022-01-17T14:22:27Z"
5+
name: sample
6+
uid: 0e6d855e-83ed-4ed5-b80a-461a750f14db
7+
spec:
8+
maxReplicas: 2
9+
minReplicas: 1
10+
scaleTargetRef:
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
name: argocd-server
14+
targetCPUUtilizationPercentage: 80
15+
status:
16+
conditions:
17+
- lastTransitionTime: '2024-09-05T20:20:41Z'
18+
message: the HPA controller was able to get the target's current scale
19+
reason: SucceededGetScale
20+
status: 'True'
21+
type: AbleToScale
22+
- lastTransitionTime: '2024-09-05T20:20:56Z'
23+
message: >-
24+
the HPA was unable to compute the replica count: failed to get memory
25+
utilization: unable to get metrics for resource memory: unable to fetch
26+
metrics from resource metrics API: the server could not find the
27+
requested resource (get pods.metrics.k8s.io)
28+
reason: FailedGetResourceMetric
29+
status: 'False'
30+
type: ScalingActive
31+
type: ScalingLimited
32+
currentMetrics:
33+
- resource:
34+
current:
35+
averageUtilization: 6
36+
averageValue: 12m
37+
name: cpu
38+
type: Resource
39+
currentReplicas: 1
40+
desiredReplicas: 1

0 commit comments

Comments
 (0)