Application Selection
Rendering the manifests generated by all applications in the repository on each pull request can be slow. Limiting the number of applications rendered can speed up the rendering process significantly. By default, argocd-diff-preview
will render all applications in the repository.
Here are 4 ways to limit which applications are rendered:
Rendering only changed applications
You can configure the tool to render only the applications affected by changes in a pull request. This optimizes the rendering process by focusing on the applications directly impacted by the modified files.
To achieve this, you need to add the annotation: argocd-diff-preview/watch-pattern
to all your Applications/ApplicationSets, and provide the tool with a list of changed files. If no list is provided, the annotation will be ignored. The watch-pattern
annotation takes a comma-separated list of file paths or regex patterns. The tool will render the application if any of the patterns match the changed files.
Example:
By adding the annotation argocd-diff-preview/watch-pattern: "examples/helm/charts/myApp/.*, examples/helm/values/filtered.yaml"
to the Application manifest, the my-app
application will only be rendered if the filtered.yaml
file or a file in the examples/helm/charts/myApp/
folder is modified in the PR. However, the my-app
application will also be rendered if its own Application
manifest is changed, so there's no need to include the application's file path in the watch-pattern annotation.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
annotations:
argocd-diff-preview/watch-pattern: "examples/helm/charts/myApp/.*, examples/helm/values/filtered.yaml"
spec:
sources:
- repoURL: https://github.com/dag-andersen/argocd-diff-preview
ref: local-files
- path: examples/helm/charts/myApp
repoURL: https://github.com/dag-andersen/argocd-diff-preview
helm:
valueFiles:
- $local-files/examples/helm/values/filtered.yaml
...
How to use it in a GitHub Actions Workflow
You can use the tj-actions/changed-files
action in your workflow and pass the output to the argocd-diff-preview
tool. Providing the tool with a list of changed files will ensure you only render applications that watch those file paths. Any application without the argocd-diff-preview/watch-pattern
annotation will be ignored.
Ignoring individual applications
You can exclude specific applications from rendering by adding the annotation argocd-diff-preview/ignore: "true"
to their manifest. This is useful for skipping applications that don’t require a diff preview.
Examples:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
annotations:
argocd-diff-preview/ignore: "true"
spec:
...
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: my-app
annotations:
argocd-diff-preview/ignore: "true"
spec:
...
Label Selectors
Run the tool with the --selector
option to filter applications based on labels. The option supports =
, ==
, and !=
.
Example:
This command :arrow_up: will target the following application :arrow_down: and ignore all applications that do not have the labelteam: a
.
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
labels:
team: a
spec:
...
Application File Path Regex
Alternatively, use the --file-regex
option to limit rendering to Applications whose file paths match a regular expression. This is helpful when rendering changes from specific teams or directories.
Example:
If someone in your organization from Team A changes one of their applications, the tool can be run with:
This ensures only applications in folders matching*/Team-A/*
are rendered.