mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 08:57:17 +00:00
fix: remove resourceVersion from ssd (#27406)
Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
This commit is contained in:
parent
032d9e1e80
commit
b74c08ec5c
2 changed files with 50 additions and 0 deletions
|
|
@ -188,6 +188,7 @@ func serverSideDiff(config, live *unstructured.Unstructured, opts ...Option) (*D
|
||||||
|
|
||||||
Normalize(predictedLive, opts...)
|
Normalize(predictedLive, opts...)
|
||||||
unstructured.RemoveNestedField(predictedLive.Object, "metadata", "managedFields")
|
unstructured.RemoveNestedField(predictedLive.Object, "metadata", "managedFields")
|
||||||
|
unstructured.RemoveNestedField(predictedLive.Object, "metadata", "resourceVersion")
|
||||||
|
|
||||||
predictedLiveBytes, err := json.Marshal(predictedLive)
|
predictedLiveBytes, err := json.Marshal(predictedLive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -196,6 +197,7 @@ func serverSideDiff(config, live *unstructured.Unstructured, opts ...Option) (*D
|
||||||
|
|
||||||
Normalize(live, opts...)
|
Normalize(live, opts...)
|
||||||
unstructured.RemoveNestedField(live.Object, "metadata", "managedFields")
|
unstructured.RemoveNestedField(live.Object, "metadata", "managedFields")
|
||||||
|
unstructured.RemoveNestedField(live.Object, "metadata", "resourceVersion")
|
||||||
liveBytes, err := json.Marshal(live)
|
liveBytes, err := json.Marshal(live)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error marshaling live resource %s/%s: %w", config.GetKind(), config.GetName(), err)
|
return nil, fmt.Errorf("error marshaling live resource %s/%s: %w", config.GetKind(), config.GetName(), err)
|
||||||
|
|
|
||||||
|
|
@ -1165,6 +1165,54 @@ func TestServerSideDiff(t *testing.T) {
|
||||||
assert.Empty(t, liveDeploy.Annotations[AnnotationLastAppliedConfig])
|
assert.Empty(t, liveDeploy.Annotations[AnnotationLastAppliedConfig])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("will not report diff for mismatched resourceVersion", func(t *testing.T) {
|
||||||
|
// given
|
||||||
|
t.Parallel()
|
||||||
|
predictedLiveJSON := `{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"kind": "Deployment",
|
||||||
|
"metadata": {
|
||||||
|
"name": "my-deploy",
|
||||||
|
"namespace": "default",
|
||||||
|
"resourceVersion": "99999",
|
||||||
|
"managedFields": [{"manager":"argocd-controller","operation":"Apply","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{"f:replicas":{}}}}]
|
||||||
|
},
|
||||||
|
"spec": {"replicas": 1}
|
||||||
|
}`
|
||||||
|
liveState := StrToUnstructured(`{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"kind": "Deployment",
|
||||||
|
"metadata": {
|
||||||
|
"name": "my-deploy",
|
||||||
|
"namespace": "default",
|
||||||
|
"resourceVersion": "12345",
|
||||||
|
"managedFields": [{"manager":"argocd-controller","operation":"Apply","fieldsType":"FieldsV1","fieldsV1":{"f:spec":{"f:replicas":{}}}}]
|
||||||
|
},
|
||||||
|
"spec": {"replicas": 1}
|
||||||
|
}`)
|
||||||
|
desiredState := StrToUnstructured(`{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"kind": "Deployment",
|
||||||
|
"metadata": {
|
||||||
|
"name": "my-deploy",
|
||||||
|
"namespace": "default"
|
||||||
|
},
|
||||||
|
"spec": {"replicas": 1}
|
||||||
|
}`)
|
||||||
|
opts := buildOpts(predictedLiveJSON)
|
||||||
|
opts = append(opts, WithIgnoreMutationWebhook(false))
|
||||||
|
|
||||||
|
// when
|
||||||
|
result, err := serverSideDiff(desiredState, liveState, opts...)
|
||||||
|
|
||||||
|
// then
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotNil(t, result)
|
||||||
|
assert.False(t, result.Modified, "mismatched resourceVersion should not cause a diff")
|
||||||
|
assert.NotContains(t, string(result.PredictedLive), "resourceVersion")
|
||||||
|
assert.NotContains(t, string(result.NormalizedLive), "resourceVersion")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("will detect ConfigMap data key removal", func(t *testing.T) {
|
t.Run("will detect ConfigMap data key removal", func(t *testing.T) {
|
||||||
// given
|
// given
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue