mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
fix: resolve HPA v2/v1 conversion error in structured merge diff (#27809)
Signed-off-by: Bisman-Singh <[email protected]>
This commit is contained in:
@@ -2208,3 +2208,151 @@ spec:
|
||||
assert.Contains(t, normalizedLiveStr, "sessionAffinity", "sessionAffinity should still appear in output (no output normalization)")
|
||||
})
|
||||
}
|
||||
|
||||
func TestStructuredMergeDiff_HPAv2ToV1Conversion(t *testing.T) {
|
||||
// Reproduces https://github.com/argoproj/argo-cd/issues/17795
|
||||
gvkParser := buildGVKParser(t)
|
||||
|
||||
config := StrToUnstructured(`
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: test-hpa
|
||||
namespace: default
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: test-deploy
|
||||
minReplicas: 1
|
||||
maxReplicas: 10
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 50
|
||||
`)
|
||||
|
||||
live := StrToUnstructured(`
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: test-hpa
|
||||
namespace: default
|
||||
managedFields:
|
||||
- apiVersion: autoscaling/v1
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:spec:
|
||||
f:maxReplicas: {}
|
||||
f:minReplicas: {}
|
||||
f:scaleTargetRef: {}
|
||||
manager: helm
|
||||
operation: Apply
|
||||
time: "2024-01-01T00:00:00Z"
|
||||
- apiVersion: autoscaling/v2
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:spec:
|
||||
f:metrics: {}
|
||||
manager: argocd-controller
|
||||
operation: Apply
|
||||
time: "2024-01-02T00:00:00Z"
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: test-deploy
|
||||
minReplicas: 1
|
||||
maxReplicas: 10
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 50
|
||||
`)
|
||||
|
||||
// Identical config and live should not be modified
|
||||
result, err := StructuredMergeDiff(config, live, gvkParser, "argocd-controller")
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.False(t, result.Modified, "identical config and live should not show as modified")
|
||||
}
|
||||
|
||||
func TestStructuredMergeDiff_HPAv2ToV1Conversion_Modified(t *testing.T) {
|
||||
// Verifies that a real change is detected when config differs from live
|
||||
// with cross-version managed fields
|
||||
gvkParser := buildGVKParser(t)
|
||||
|
||||
config := StrToUnstructured(`
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: test-hpa
|
||||
namespace: default
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: test-deploy
|
||||
minReplicas: 2
|
||||
maxReplicas: 20
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 80
|
||||
`)
|
||||
|
||||
live := StrToUnstructured(`
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: test-hpa
|
||||
namespace: default
|
||||
managedFields:
|
||||
- apiVersion: autoscaling/v1
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:spec:
|
||||
f:maxReplicas: {}
|
||||
f:minReplicas: {}
|
||||
f:scaleTargetRef: {}
|
||||
manager: helm
|
||||
operation: Apply
|
||||
time: "2024-01-01T00:00:00Z"
|
||||
- apiVersion: autoscaling/v2
|
||||
fieldsType: FieldsV1
|
||||
fieldsV1:
|
||||
f:spec:
|
||||
f:metrics: {}
|
||||
manager: argocd-controller
|
||||
operation: Apply
|
||||
time: "2024-01-02T00:00:00Z"
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: test-deploy
|
||||
minReplicas: 1
|
||||
maxReplicas: 10
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 50
|
||||
`)
|
||||
|
||||
result, err := StructuredMergeDiff(config, live, gvkParser, "argocd-controller")
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.True(t, result.Modified, "different config and live should show as modified")
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ import (
|
||||
// borrowed private function from k8s apiserver handler.
|
||||
func NewVersionConverter(gvkParser *managedfields.GvkParser, o runtime.ObjectConvertor, h schema.GroupVersion) merge.Converter {
|
||||
tc := &typeConverter{parser: gvkParser}
|
||||
return newVersionConverter(tc, o, h)
|
||||
hub := schema.GroupVersion{Group: h.Group, Version: runtime.APIVersionInternal}
|
||||
return newVersionConverter(tc, o, hub)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user