Skip to content

Commit 204a8fb

Browse files
committed
Add test case on hpa metrics for flux build/diff
If implemented will detect any change on how ssa dry-run return diffs on hpa metrics Signed-off-by: Soule BA <[email protected]>
1 parent edf1589 commit 204a8fb

File tree

8 files changed

+203
-1
lines changed

8 files changed

+203
-1
lines changed

cmd/flux/diff_kustomization_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func TestDiffKustomization(t *testing.T) {
7979
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
8080
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-value-sops-secret.golden"),
8181
},
82+
{
83+
name: "diff with a drifted hpa object",
84+
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
85+
objectFile: "./testdata/diff-kustomization/hpa.yaml",
86+
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-hpa.golden"),
87+
},
8288
}
8389

8490
tmpl := map[string]string{

cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
33
metadata:
44
name: podinfo
55
spec:
6+
behavior:
7+
scaleDown:
8+
policies:
9+
- periodSeconds: 15
10+
type: Percent
11+
value: 99
12+
selectPolicy: Max
13+
stabilizationWindowSeconds: 60
14+
scaleUp:
15+
policies:
16+
- periodSeconds: 15
17+
type: Pods
18+
value: 5
19+
- periodSeconds: 15
20+
type: Percent
21+
value: 100
22+
selectPolicy: Max
623
scaleTargetRef:
724
apiVersion: apps/v1
825
kind: Deployment
@@ -18,3 +35,10 @@ spec:
1835
# scale up if usage is above
1936
# 99% of the requested CPU (100m)
2037
averageUtilization: 99
38+
- type: Pods
39+
pods:
40+
metric:
41+
name: podinfo_http_requests_total
42+
target:
43+
averageValue: "2"
44+
type: AverageValue

cmd/flux/testdata/build-kustomization/podinfo-result.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ metadata:
8686
name: podinfo
8787
namespace: default
8888
spec:
89+
behavior:
90+
scaleDown:
91+
policies:
92+
- periodSeconds: 15
93+
type: Percent
94+
value: 99
95+
selectPolicy: Max
96+
stabilizationWindowSeconds: 60
97+
scaleUp:
98+
policies:
99+
- periodSeconds: 15
100+
type: Pods
101+
value: 5
102+
- periodSeconds: 15
103+
type: Percent
104+
value: 100
105+
selectPolicy: Max
89106
maxReplicas: 4
90107
metrics:
91108
- resource:
@@ -94,6 +111,13 @@ spec:
94111
averageUtilization: 99
95112
type: Utilization
96113
type: Resource
114+
- pods:
115+
metric:
116+
name: podinfo_http_requests_total
117+
target:
118+
averageValue: "2"
119+
type: AverageValue
120+
type: Pods
97121
minReplicas: 2
98122
scaleTargetRef:
99123
apiVersion: apps/v1

cmd/flux/testdata/build-kustomization/podinfo-without-service-result.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ metadata:
8686
name: podinfo
8787
namespace: default
8888
spec:
89+
behavior:
90+
scaleDown:
91+
policies:
92+
- periodSeconds: 15
93+
type: Percent
94+
value: 99
95+
selectPolicy: Max
96+
stabilizationWindowSeconds: 60
97+
scaleUp:
98+
policies:
99+
- periodSeconds: 15
100+
type: Pods
101+
value: 5
102+
- periodSeconds: 15
103+
type: Percent
104+
value: 100
105+
selectPolicy: Max
89106
maxReplicas: 4
90107
metrics:
91108
- resource:
@@ -94,6 +111,13 @@ spec:
94111
averageUtilization: 99
95112
type: Utilization
96113
type: Resource
114+
- pods:
115+
metric:
116+
name: podinfo_http_requests_total
117+
target:
118+
averageValue: "2"
119+
type: AverageValue
120+
type: Pods
97121
minReplicas: 2
98122
scaleTargetRef:
99123
apiVersion: apps/v1

cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
33
metadata:
44
name: podinfo
55
spec:
6+
behavior:
7+
scaleDown:
8+
policies:
9+
- periodSeconds: 15
10+
type: Percent
11+
value: 99
12+
selectPolicy: Max
13+
stabilizationWindowSeconds: 60
14+
scaleUp:
15+
policies:
16+
- periodSeconds: 15
17+
type: Pods
18+
value: 5
19+
- periodSeconds: 15
20+
type: Percent
21+
value: 100
22+
selectPolicy: Max
623
scaleTargetRef:
724
apiVersion: apps/v1
825
kind: Deployment
@@ -18,3 +35,10 @@ spec:
1835
# scale up if usage is above
1936
# 99% of the requested CPU (100m)
2037
averageUtilization: 99
38+
- type: Pods
39+
pods:
40+
metric:
41+
name: podinfo_http_requests_total
42+
target:
43+
averageValue: "2"
44+
type: AverageValue
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
► Deployment/default/podinfo created
2+
► HorizontalPodAutoscaler/default/podinfo drifted
3+
4+
spec.behavior.scaleDown.policies.0.periodSeconds
5+
± value change
6+
- 16
7+
+ 15
8+
9+
spec.behavior.scaleUp.policies
10+
- two list entries removed: + two list entries added:
11+
- type: Pods - type: Pods
12+
periodSeconds: 16 periodSeconds: 15
13+
value: 5 value: 5
14+
- type: Percent - type: Percent
15+
periodSeconds: 16 periodSeconds: 15
16+
value: 100 value: 100
17+
18+
spec.metrics
19+
- two list entries removed:
20+
- type: Pods
21+
pods:
22+
metric:
23+
name: podinfo_http_requests_total
24+
target:
25+
type: AverageValue
26+
averageValue: 3
27+
- type: Resource
28+
resource:
29+
name: cpu
30+
target:
31+
type: Utilization
32+
averageUtilization: 98
33+
34+
+ two list entries added:
35+
- type: Pods
36+
pods:
37+
metric:
38+
name: podinfo_http_requests_total
39+
target:
40+
type: AverageValue
41+
averageValue: 2
42+
- type: Resource
43+
resource:
44+
name: cpu
45+
target:
46+
type: Utilization
47+
averageUtilization: 99
48+
49+
50+
► Service/default/podinfo created
51+
► Secret/default/podinfo-token-77t89m9b67 created
52+
► Secret/default/db-user-pass-bkbd782d2c created
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: autoscaling/v2beta2
2+
kind: HorizontalPodAutoscaler
3+
metadata:
4+
labels:
5+
kustomize.toolkit.fluxcd.io/name: podinfo
6+
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
7+
name: podinfo
8+
namespace: default
9+
spec:
10+
behavior:
11+
scaleDown:
12+
policies:
13+
- periodSeconds: 16
14+
type: Percent
15+
value: 99
16+
selectPolicy: Max
17+
stabilizationWindowSeconds: 60
18+
scaleUp:
19+
policies:
20+
- periodSeconds: 16
21+
type: Pods
22+
value: 5
23+
- periodSeconds: 16
24+
type: Percent
25+
value: 100
26+
selectPolicy: Max
27+
scaleTargetRef:
28+
apiVersion: apps/v1
29+
kind: Deployment
30+
name: podinfo
31+
minReplicas: 2
32+
maxReplicas: 4
33+
metrics:
34+
- type: Resource
35+
resource:
36+
name: cpu
37+
target:
38+
type: Utilization
39+
# scale up if usage is above
40+
# 99% of the requested CPU (100m)
41+
averageUtilization: 98
42+
- type: Pods
43+
pods:
44+
metric:
45+
name: podinfo_http_requests_total
46+
target:
47+
averageValue: "3"
48+
type: AverageValue

internal/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func trimSopsData(res *resource.Resource) error {
266266
data, err := base64.StdEncoding.DecodeString(v)
267267
if err != nil {
268268
if _, ok := err.(base64.CorruptInputError); ok {
269-
return fmt.Errorf("failed to decode secret data: %w", err)
269+
return fmt.Errorf("failed to decode secret %s data: %w", res.GetName(), err)
270270
}
271271
}
272272

0 commit comments

Comments
 (0)