mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-22 15:41:47 +00:00
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 <soule@weave.works>
This commit is contained in:
parent
edf15894f8
commit
204a8fbbd7
8 changed files with 203 additions and 1 deletions
|
|
@ -79,6 +79,12 @@ func TestDiffKustomization(t *testing.T) {
|
||||||
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
|
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
|
||||||
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-value-sops-secret.golden"),
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-value-sops-secret.golden"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "diff with a drifted hpa object",
|
||||||
|
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
|
||||||
|
objectFile: "./testdata/diff-kustomization/hpa.yaml",
|
||||||
|
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-hpa.golden"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := map[string]string{
|
tmpl := map[string]string{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
|
||||||
metadata:
|
metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
spec:
|
spec:
|
||||||
|
behavior:
|
||||||
|
scaleDown:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 99
|
||||||
|
selectPolicy: Max
|
||||||
|
stabilizationWindowSeconds: 60
|
||||||
|
scaleUp:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Pods
|
||||||
|
value: 5
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 100
|
||||||
|
selectPolicy: Max
|
||||||
scaleTargetRef:
|
scaleTargetRef:
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|
@ -18,3 +35,10 @@ spec:
|
||||||
# scale up if usage is above
|
# scale up if usage is above
|
||||||
# 99% of the requested CPU (100m)
|
# 99% of the requested CPU (100m)
|
||||||
averageUtilization: 99
|
averageUtilization: 99
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
averageValue: "2"
|
||||||
|
type: AverageValue
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,23 @@ metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
|
behavior:
|
||||||
|
scaleDown:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 99
|
||||||
|
selectPolicy: Max
|
||||||
|
stabilizationWindowSeconds: 60
|
||||||
|
scaleUp:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Pods
|
||||||
|
value: 5
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 100
|
||||||
|
selectPolicy: Max
|
||||||
maxReplicas: 4
|
maxReplicas: 4
|
||||||
metrics:
|
metrics:
|
||||||
- resource:
|
- resource:
|
||||||
|
|
@ -94,6 +111,13 @@ spec:
|
||||||
averageUtilization: 99
|
averageUtilization: 99
|
||||||
type: Utilization
|
type: Utilization
|
||||||
type: Resource
|
type: Resource
|
||||||
|
- pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
averageValue: "2"
|
||||||
|
type: AverageValue
|
||||||
|
type: Pods
|
||||||
minReplicas: 2
|
minReplicas: 2
|
||||||
scaleTargetRef:
|
scaleTargetRef:
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,23 @@ metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
|
behavior:
|
||||||
|
scaleDown:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 99
|
||||||
|
selectPolicy: Max
|
||||||
|
stabilizationWindowSeconds: 60
|
||||||
|
scaleUp:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Pods
|
||||||
|
value: 5
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 100
|
||||||
|
selectPolicy: Max
|
||||||
maxReplicas: 4
|
maxReplicas: 4
|
||||||
metrics:
|
metrics:
|
||||||
- resource:
|
- resource:
|
||||||
|
|
@ -94,6 +111,13 @@ spec:
|
||||||
averageUtilization: 99
|
averageUtilization: 99
|
||||||
type: Utilization
|
type: Utilization
|
||||||
type: Resource
|
type: Resource
|
||||||
|
- pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
averageValue: "2"
|
||||||
|
type: AverageValue
|
||||||
|
type: Pods
|
||||||
minReplicas: 2
|
minReplicas: 2
|
||||||
scaleTargetRef:
|
scaleTargetRef:
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
|
||||||
metadata:
|
metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
spec:
|
spec:
|
||||||
|
behavior:
|
||||||
|
scaleDown:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 99
|
||||||
|
selectPolicy: Max
|
||||||
|
stabilizationWindowSeconds: 60
|
||||||
|
scaleUp:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Pods
|
||||||
|
value: 5
|
||||||
|
- periodSeconds: 15
|
||||||
|
type: Percent
|
||||||
|
value: 100
|
||||||
|
selectPolicy: Max
|
||||||
scaleTargetRef:
|
scaleTargetRef:
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|
@ -18,3 +35,10 @@ spec:
|
||||||
# scale up if usage is above
|
# scale up if usage is above
|
||||||
# 99% of the requested CPU (100m)
|
# 99% of the requested CPU (100m)
|
||||||
averageUtilization: 99
|
averageUtilization: 99
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
averageValue: "2"
|
||||||
|
type: AverageValue
|
||||||
|
|
|
||||||
52
cmd/flux/testdata/diff-kustomization/diff-with-drifted-hpa.golden
vendored
Normal file
52
cmd/flux/testdata/diff-kustomization/diff-with-drifted-hpa.golden
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
► Deployment/default/podinfo created
|
||||||
|
► HorizontalPodAutoscaler/default/podinfo drifted
|
||||||
|
|
||||||
|
spec.behavior.scaleDown.policies.0.periodSeconds
|
||||||
|
± value change
|
||||||
|
- 16
|
||||||
|
+ 15
|
||||||
|
|
||||||
|
spec.behavior.scaleUp.policies
|
||||||
|
- two list entries removed: + two list entries added:
|
||||||
|
- type: Pods - type: Pods
|
||||||
|
periodSeconds: 16 periodSeconds: 15
|
||||||
|
value: 5 value: 5
|
||||||
|
- type: Percent - type: Percent
|
||||||
|
periodSeconds: 16 periodSeconds: 15
|
||||||
|
value: 100 value: 100
|
||||||
|
|
||||||
|
spec.metrics
|
||||||
|
- two list entries removed:
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
type: AverageValue
|
||||||
|
averageValue: 3
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: 98
|
||||||
|
|
||||||
|
+ two list entries added:
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
type: AverageValue
|
||||||
|
averageValue: 2
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
averageUtilization: 99
|
||||||
|
|
||||||
|
|
||||||
|
► Service/default/podinfo created
|
||||||
|
► Secret/default/podinfo-token-77t89m9b67 created
|
||||||
|
► Secret/default/db-user-pass-bkbd782d2c created
|
||||||
48
cmd/flux/testdata/diff-kustomization/hpa.yaml
vendored
Normal file
48
cmd/flux/testdata/diff-kustomization/hpa.yaml
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
apiVersion: autoscaling/v2beta2
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
kustomize.toolkit.fluxcd.io/name: podinfo
|
||||||
|
kustomize.toolkit.fluxcd.io/namespace: {{ .fluxns }}
|
||||||
|
name: podinfo
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
behavior:
|
||||||
|
scaleDown:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 16
|
||||||
|
type: Percent
|
||||||
|
value: 99
|
||||||
|
selectPolicy: Max
|
||||||
|
stabilizationWindowSeconds: 60
|
||||||
|
scaleUp:
|
||||||
|
policies:
|
||||||
|
- periodSeconds: 16
|
||||||
|
type: Pods
|
||||||
|
value: 5
|
||||||
|
- periodSeconds: 16
|
||||||
|
type: Percent
|
||||||
|
value: 100
|
||||||
|
selectPolicy: Max
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: podinfo
|
||||||
|
minReplicas: 2
|
||||||
|
maxReplicas: 4
|
||||||
|
metrics:
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
target:
|
||||||
|
type: Utilization
|
||||||
|
# scale up if usage is above
|
||||||
|
# 99% of the requested CPU (100m)
|
||||||
|
averageUtilization: 98
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
metric:
|
||||||
|
name: podinfo_http_requests_total
|
||||||
|
target:
|
||||||
|
averageValue: "3"
|
||||||
|
type: AverageValue
|
||||||
|
|
@ -266,7 +266,7 @@ func trimSopsData(res *resource.Resource) error {
|
||||||
data, err := base64.StdEncoding.DecodeString(v)
|
data, err := base64.StdEncoding.DecodeString(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(base64.CorruptInputError); ok {
|
if _, ok := err.(base64.CorruptInputError); ok {
|
||||||
return fmt.Errorf("failed to decode secret data: %w", err)
|
return fmt.Errorf("failed to decode secret %s data: %w", res.GetName(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue