Skip to content

Commit

Permalink
feat: add AND operator opt-in option for sync windows matches (#16846)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Aneci <[email protected]>
  • Loading branch information
adriananeci authored Feb 3, 2025
1 parent 9a3cfcb commit c9c4068
Show file tree
Hide file tree
Showing 19 changed files with 1,098 additions and 785 deletions.
4 changes: 4 additions & 0 deletions assets/swagger.json

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

9 changes: 6 additions & 3 deletions cmd/argocd/commands/projectwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func NewProjectWindowsAddWindowCommand(clientOpts *argocdclient.ClientOptions) *
clusters []string
manualSync bool
timeZone string
andOperator bool
)
command := &cobra.Command{
Use: "add PROJECT",
Expand Down Expand Up @@ -185,7 +186,7 @@ argocd proj windows add PROJECT \
proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName})
errors.CheckError(err)

err = proj.Spec.AddWindow(kind, schedule, duration, applications, namespaces, clusters, manualSync, timeZone)
err = proj.Spec.AddWindow(kind, schedule, duration, applications, namespaces, clusters, manualSync, timeZone, andOperator)
errors.CheckError(err)

_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
Expand All @@ -200,6 +201,7 @@ argocd proj windows add PROJECT \
command.Flags().StringSliceVar(&clusters, "clusters", []string{}, "Clusters that the schedule will be applied to. Comma separated, wildcards supported (e.g. --clusters prod,staging)")
command.Flags().BoolVar(&manualSync, "manual-sync", false, "Allow manual syncs for both deny and allow windows")
command.Flags().StringVar(&timeZone, "time-zone", "UTC", "Time zone of the sync window")
command.Flags().BoolVar(&andOperator, "use-and-operator", false, "Use AND operator for matching applications, namespaces and clusters instead of the default OR operator")

return command
}
Expand Down Expand Up @@ -369,8 +371,9 @@ func printSyncWindows(proj *v1alpha1.AppProject) {
formatListOutput(window.Applications),
formatListOutput(window.Namespaces),
formatListOutput(window.Clusters),
formatManualOutput(window.ManualSync),
formatBoolEnabledOutput(window.ManualSync),
window.TimeZone,
formatBoolEnabledOutput(window.UseAndOperator),
}
fmt.Fprintf(w, fmtStr, vals...)
}
Expand Down Expand Up @@ -398,7 +401,7 @@ func formatBoolOutput(active bool) string {
return o
}

func formatManualOutput(active bool) string {
func formatBoolEnabledOutput(active bool) string {
var o string
if active {
o = "Enabled"
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_proj_windows_add.md

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

10 changes: 6 additions & 4 deletions docs/user-guide/sync_windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Sync windows are configurable windows of time where syncs will either be blocked or allowed. These are defined
by a kind, which can be either `allow` or `deny`, a `schedule` in cron format and a duration along with one or
more of either `applications`, `namespaces` and `clusters`. Wildcards are supported.
more of either `applications`, `namespaces` and `clusters`. If more than one option is specified, by default, the enabled options will
be OR-ed. If you want to AND the options, you can tick the `Use AND operator` option.
Wildcards are supported.

## Relationship between Sync Windows and Applications

Expand All @@ -26,9 +28,9 @@ then the Application is affected by the Sync Window.

## Effect of Sync Windows

These windows affect the running
of both manual and automated syncs but allow an override for manual syncs which is useful if you are only interested
in preventing automated syncs or if you need to temporarily override a window to perform a sync.
These windows affect the running of both manual and automated syncs but allow an override
for manual syncs which is useful if you are only interested in preventing automated syncs or if you need to temporarily
override a window to perform a sync.

The windows work in the following way. If there are no windows matching an application then all syncs are allowed. If there
are any `allow` windows matching an application then syncs will only be allowed when there is an active `allow` window. If there
Expand Down
4 changes: 4 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.

4 changes: 4 additions & 0 deletions manifests/core-install.yaml

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

4 changes: 4 additions & 0 deletions manifests/crds/appproject-crd.yaml

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

4 changes: 4 additions & 0 deletions manifests/ha/install-with-hydrator.yaml

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

4 changes: 4 additions & 0 deletions manifests/ha/install.yaml

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

4 changes: 4 additions & 0 deletions manifests/install-with-hydrator.yaml

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

4 changes: 4 additions & 0 deletions manifests/install.yaml

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

Loading

0 comments on commit c9c4068

Please sign in to comment.