Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Implement jqPaths field using delpaths() instead of del()
Signed-off-by: puretension <[email protected]>
  • Loading branch information
puretension committed Sep 19, 2025
commit 310bf14e3e53c7610e8952f80861c8d73a619f81
14 changes: 14 additions & 0 deletions assets/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions debug_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"encoding/json"
"fmt"
"log"

"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v3/test"
"github.com/argoproj/argo-cd/v3/util/argo/normalizers"
)

func main() {
// Create normalizer with JQPaths
normalizer, err := normalizers.NewIgnoreNormalizer([]v1alpha1.ResourceIgnoreDifferences{{
Group: "apps",
Kind: "Deployment",
JQPaths: []string{`.metadata.annotations // {} | [keys[] | select(startswith("customprefix.")) | ["metadata", "annotations", .]]`},
}}, make(map[string]v1alpha1.ResourceOverride), normalizers.IgnoreNormalizerOpts{})

if err != nil {
log.Fatal(err)
}

deployment := test.NewDeployment()
deployment.SetAnnotations(map[string]string{
"customprefix.annotation1": "value1",
"customprefix.annotation2": "value2",
"other.annotation": "keep-this",
})

fmt.Println("Before normalization:")
data, _ := json.MarshalIndent(deployment.Object, "", " ")
fmt.Println(string(data))

// Apply normalization
err = normalizer.Normalize(deployment)
if err != nil {
log.Fatal(err)
}

fmt.Println("\nAfter normalization:")
data, _ = json.MarshalIndent(deployment.Object, "", " ")
fmt.Println(string(data))

fmt.Println("\nAnnotations:")
fmt.Printf("%+v\n", deployment.GetAnnotations())
}
13 changes: 13 additions & 0 deletions docs/user-guide/diffing.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ spec:
- .spec.template.spec.initContainers[] | select(.name == "injected-init-container")
```

For more complex scenarios where you need to delete multiple paths based on JQ queries, use `jqPaths`. This field expects JQ queries that produce arrays of paths for use with `delpaths()`:

```yaml
spec:
ignoreDifferences:
- group: apps
kind: Deployment
jqPaths:
- '.metadata.annotations // {} | [keys[] | select(startswith("customprefix.")) | ["metadata", "annotations", .]]'
```

The above example will ignore all annotations that start with "customprefix." by generating the appropriate paths and using `delpaths()` to remove them.

To ignore fields owned by specific managers defined in your live resources:

```yaml
Expand Down
108 changes: 108 additions & 0 deletions manifests/core-install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading