Skip to content

Commit 1c1e990

Browse files
authored
fix pdbMinAvailableGreaterThanHPAMinReplicas check when minAvailable is not present (#1062)
1 parent 952b6ae commit 1c1e990

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

pkg/validator/pdb_hpa_validator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func init() {
2121

2222
func pdbMinAvailableGreaterThanHPAMinReplicas(test schemaTestCase) (bool, []jsonschema.ValError, error) {
2323
if test.ResourceProvider == nil {
24-
logrus.Debug("ResourceProvider is nil")
2524
return true, nil, nil
2625
}
2726

@@ -47,6 +46,10 @@ func pdbMinAvailableGreaterThanHPAMinReplicas(test schemaTestCase) (bool, []json
4746
if attachedPDB != nil && attachedHPA != nil {
4847
logrus.Debugf("both PDB and HPA are attached to deployment %s", deployment.Name)
4948

49+
if attachedPDB.Spec.MinAvailable == nil {
50+
return true, nil, nil
51+
}
52+
5053
pdbMinAvailable, isPercent, err := getIntOrPercentValueSafely(attachedPDB.Spec.MinAvailable)
5154
if err != nil {
5255
logrus.Warnf("error getting getIntOrPercentValueSafely: %v", err)
@@ -56,7 +59,6 @@ func pdbMinAvailableGreaterThanHPAMinReplicas(test schemaTestCase) (bool, []json
5659
if isPercent {
5760
// if the value is a percentage, we need to calculate the actual value
5861
if attachedHPA.Spec.MinReplicas == nil {
59-
logrus.Debug("attachedHPA.Spec.MinReplicas is nil")
6062
return true, nil, nil
6163
}
6264

@@ -90,7 +92,6 @@ func hasPDBAttached(deployment appsv1.Deployment, pdbs []kube.GenericResource) (
9092
}
9193

9294
if pdb.Spec.Selector == nil {
93-
logrus.Debug("pdb.Spec.Selector is nil")
9495
continue
9596
}
9697

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: zookeeper
5+
spec:
6+
template:
7+
metadata:
8+
labels:
9+
app.kubernetes.io/name: zookeeper
10+
foo: bar
11+
spec:
12+
containers:
13+
- name: zookeeper
14+
image: zookeeper
15+
---
16+
apiVersion: policy/v1
17+
kind: PodDisruptionBudget
18+
metadata:
19+
name: zookeeper-pdb
20+
spec:
21+
maxUnavailable: 5
22+
selector:
23+
matchLabels:
24+
app.kubernetes.io/name: zookeeper
25+
---
26+
apiVersion: autoscaling/v2
27+
kind: HorizontalPodAutoscaler
28+
metadata:
29+
name: zookeeper-hpa
30+
spec:
31+
scaleTargetRef:
32+
apiVersion: apps/v1
33+
kind: Deployment
34+
name: zookeeper
35+
minReplicas: 5
36+
maxReplicas: 7
37+
metrics:
38+
- type: Resource
39+
resource:
40+
name: cpu
41+
target:
42+
type: Utilization
43+
averageUtilization: 50

0 commit comments

Comments
 (0)