Skip to content

Commit

Permalink
feat: Allow configuring system wide ignore differences for all resour…
Browse files Browse the repository at this point in the history
…ces (argoproj#8224)

* feat: Allow configuring system wide ignore differences for all resources

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* Add example config to argocd-cm.yaml

Signed-off-by: Leonardo Luz Almeida <[email protected]>
  • Loading branch information
leoluz authored Jan 19, 2022
1 parent 9155d14 commit 1547b44
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
12 changes: 9 additions & 3 deletions controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,13 @@ func normalizeTargetResources(cr *comparisonResult) ([]*unstructured.Unstructure
patchedTargets = append(patchedTargets, nil)
continue
}
// calculate targetPatch between normalized and target resources
targetPatch, err := getMergePatch(normalizedTarget, cr.reconciliationResult.Target[idx])
originalTarget := cr.reconciliationResult.Target[idx]
if live == nil {
patchedTargets = append(patchedTargets, originalTarget)
continue
}
// calculate targetPatch between normalized and target resource
targetPatch, err := getMergePatch(normalizedTarget, originalTarget)
if err != nil {
return nil, err
}
Expand All @@ -314,7 +319,8 @@ func normalizeTargetResources(cr *comparisonResult) ([]*unstructured.Unstructure
return nil, err
}
} else {
normalizedTarget = cr.reconciliationResult.Target[idx]
// if there is no patch just use the original target
normalizedTarget = originalTarget
}
patchedTargets = append(patchedTargets, normalizedTarget)
}
Expand Down
8 changes: 8 additions & 0 deletions docs/operator-manual/argocd-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ data:
managedFieldsManagers:
- kube-controller-manager
# Configuration to define customizations ignoring differences between live and desired states for
# all resources (GK).
resource.customizations.ignoreDifferences.all: |
managedFieldsManagers:
- kube-controller-manager
jsonPointers:
- /spec/replicas
resource.customizations.health.certmanager.k8s.io-Certificate: |
hs = {}
if obj.status ~= nil then
Expand Down
11 changes: 11 additions & 0 deletions docs/user-guide/diffing.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ data:
- kube-controller-manager
```

It is possible to configure ignoreDifferences to be applied to all resources in every Application managed by an ArgoCD instance. In order to do so, resource customizations can be configured like in the example bellow:

```yaml
data:
resource.customizations.ignoreDifferences.all: |
managedFieldsManagers:
- kube-controller-manager
jsonPointers:
- /spec/replicas
```

The `status` field of `CustomResourceDefinitions` is often stored in Git/Helm manifest and should be ignored during diffing. The `ignoreResourceStatusField` setting simplifies
handling that edge case:

Expand Down
16 changes: 10 additions & 6 deletions util/argo/diff/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ func Normalize(lives, configs []*unstructured.Unstructured, diffConfig DiffConfi
}

for _, live := range result.Lives {
err = diffNormalizer.Normalize(live)
if err != nil {
return nil, err
if live != nil {
err = diffNormalizer.Normalize(live)
if err != nil {
return nil, err
}
}
}
for _, target := range result.Targets {
err = diffNormalizer.Normalize(target)
if err != nil {
return nil, err
if target != nil {
err = diffNormalizer.Normalize(target)
if err != nil {
return nil, err
}
}
}
return result, nil
Expand Down
4 changes: 4 additions & 0 deletions util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ func (mgr *SettingsManager) appendResourceOverridesFromSplitKeys(cmData map[stri
return err
}

if overrideKey == "all" {
overrideKey = "*/*"
}

overrideVal, ok := resourceOverrides[overrideKey]
if !ok {
overrideVal = v1alpha1.ResourceOverride{}
Expand Down
8 changes: 7 additions & 1 deletion util/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,17 @@ func TestGetResourceOverrides_with_splitted_keys(t *testing.T) {
- bar`,
"resource.customizations.ignoreDifferences.apps_Deployment": `jqPathExpressions:
- bar`,
"resource.customizations.ignoreDifferences.all": `managedFieldsManagers:
- kube-controller-manager
- argo-rollouts`,
}
crdGK := "apiextensions.k8s.io/CustomResourceDefinition"

_, settingsManager := fixtures(mergemaps(data, newData))

overrides, err := settingsManager.GetResourceOverrides()
assert.NoError(t, err)
assert.Equal(t, 8, len(overrides))
assert.Equal(t, 9, len(overrides))
assert.Equal(t, 2, len(overrides[crdGK].IgnoreDifferences.JSONPointers))
assert.Equal(t, "/status", overrides[crdGK].IgnoreDifferences.JSONPointers[0])
assert.Equal(t, "/spec/preserveUnknownFields", overrides[crdGK].IgnoreDifferences.JSONPointers[1])
Expand All @@ -332,6 +335,9 @@ func TestGetResourceOverrides_with_splitted_keys(t *testing.T) {
assert.Equal(t, 1, len(overrides["iam-manager.k8s.io/Iamrole"].IgnoreDifferences.JSONPointers))
assert.Equal(t, 1, len(overrides["apps/Deployment"].IgnoreDifferences.JQPathExpressions))
assert.Equal(t, "bar", overrides["apps/Deployment"].IgnoreDifferences.JQPathExpressions[0])
assert.Equal(t, 2, len(overrides["*/*"].IgnoreDifferences.ManagedFieldsManagers))
assert.Equal(t, "kube-controller-manager", overrides["*/*"].IgnoreDifferences.ManagedFieldsManagers[0])
assert.Equal(t, "argo-rollouts", overrides["*/*"].IgnoreDifferences.ManagedFieldsManagers[1])
})

t.Run("SplitKeysCompareOptionsAll", func(t *testing.T) {
Expand Down

0 comments on commit 1547b44

Please sign in to comment.