Skip to content
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
6 changes: 6 additions & 0 deletions cmd/flux/diff_kustomization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func TestDiffKustomization(t *testing.T) {
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
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{
Expand Down
24 changes: 24 additions & 0 deletions cmd/flux/testdata/build-kustomization/delete-service/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
metadata:
name: podinfo
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:
apiVersion: apps/v1
kind: Deployment
Expand All @@ -18,3 +35,10 @@ spec:
# scale up if usage is above
# 99% of the requested CPU (100m)
averageUtilization: 99
- type: Pods
pods:
metric:
name: podinfo_http_requests_total
target:
averageValue: "2"
type: AverageValue
24 changes: 24 additions & 0 deletions cmd/flux/testdata/build-kustomization/podinfo-result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ metadata:
name: podinfo
namespace: default
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
metrics:
- resource:
Expand All @@ -94,6 +111,13 @@ spec:
averageUtilization: 99
type: Utilization
type: Resource
- pods:
metric:
name: podinfo_http_requests_total
target:
averageValue: "2"
type: AverageValue
type: Pods
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ metadata:
name: podinfo
namespace: default
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
metrics:
- resource:
Expand All @@ -94,6 +111,13 @@ spec:
averageUtilization: 99
type: Utilization
type: Resource
- pods:
metric:
name: podinfo_http_requests_total
target:
averageValue: "2"
type: AverageValue
type: Pods
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
Expand Down
24 changes: 24 additions & 0 deletions cmd/flux/testdata/build-kustomization/podinfo/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ kind: HorizontalPodAutoscaler
metadata:
name: podinfo
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:
apiVersion: apps/v1
kind: Deployment
Expand All @@ -18,3 +35,10 @@ spec:
# scale up if usage is above
# 99% of the requested CPU (100m)
averageUtilization: 99
- type: Pods
pods:
metric:
name: podinfo_http_requests_total
target:
averageValue: "2"
type: AverageValue
52 changes: 52 additions & 0 deletions cmd/flux/testdata/diff-kustomization/diff-with-drifted-hpa.golden
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this shouldn't happen.

- 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 changes: 48 additions & 0 deletions cmd/flux/testdata/diff-kustomization/hpa.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func trimSopsData(res *resource.Resource) error {
data, err := base64.StdEncoding.DecodeString(v)
if err != nil {
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)
}
}

Expand Down