Skip to content

Commit 3bbf160

Browse files
committed
feat(sync-windows): add sync overrun option
Signed-off-by: Vilius Puškunalis <[email protected]>
1 parent e81872f commit 3bbf160

File tree

27 files changed

+809
-44
lines changed

27 files changed

+809
-44
lines changed

assets/swagger.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/argocd/commands/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ func printAppSummaryTable(app *argoappv1.Application, appURL string, windows *ar
692692
}
693693

694694
if deny || !deny && !allow && inactiveAllows {
695-
s, err := windows.CanSync(true)
695+
s, err := windows.CanSync(true, nil)
696696
if err == nil && s {
697697
status = "Manual Allowed"
698698
} else {

cmd/argocd/commands/projectwindows.go

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ argocd proj windows list <project-name>`,
4242
}
4343
roleCommand.AddCommand(NewProjectWindowsDisableManualSyncCommand(clientOpts))
4444
roleCommand.AddCommand(NewProjectWindowsEnableManualSyncCommand(clientOpts))
45+
roleCommand.AddCommand(NewProjectWindowsDisableSyncOverrunCommand(clientOpts))
46+
roleCommand.AddCommand(NewProjectWindowsEnableSyncOverrunCommand(clientOpts))
4547
roleCommand.AddCommand(NewProjectWindowsAddWindowCommand(clientOpts))
4648
roleCommand.AddCommand(NewProjectWindowsDeleteCommand(clientOpts))
4749
roleCommand.AddCommand(NewProjectWindowsListCommand(clientOpts))
@@ -138,6 +140,92 @@ argocd proj windows enable-manual-sync my-app-project --message "Manual sync ini
138140
return command
139141
}
140142

143+
// NewProjectWindowsDisableSyncOverrunCommand returns a new instance of an `argocd proj windows disable-sync-overrun` command
144+
func NewProjectWindowsDisableSyncOverrunCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
145+
command := &cobra.Command{
146+
Use: "disable-sync-overrun PROJECT ID",
147+
Short: "Disable sync overrun for a sync window",
148+
Long: "Disable sync overrun for a sync window. Requires ID which can be found by running \"argocd proj windows list PROJECT\"",
149+
Example: `
150+
#Disable sync overrun for a sync window for the Project
151+
argocd proj windows disable-sync-overrun PROJECT ID
152+
153+
#Disabling sync overrun for a window set on the default project with Id 0
154+
argocd proj windows disable-sync-overrun default 0`,
155+
Run: func(c *cobra.Command, args []string) {
156+
ctx := c.Context()
157+
158+
if len(args) != 2 {
159+
c.HelpFunc()(c, args)
160+
os.Exit(1)
161+
}
162+
163+
projName := args[0]
164+
id, err := strconv.Atoi(args[1])
165+
errors.CheckError(err)
166+
167+
conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie()
168+
defer utilio.Close(conn)
169+
170+
proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName})
171+
errors.CheckError(err)
172+
173+
for i, window := range proj.Spec.SyncWindows {
174+
if id == i {
175+
window.SyncOverrun = false
176+
}
177+
}
178+
179+
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
180+
errors.CheckError(err)
181+
},
182+
}
183+
return command
184+
}
185+
186+
// NewProjectWindowsEnableSyncOverrunCommand returns a new instance of an `argocd proj windows enable-sync-overrun` command
187+
func NewProjectWindowsEnableSyncOverrunCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
188+
command := &cobra.Command{
189+
Use: "enable-sync-overrun PROJECT ID",
190+
Short: "Enable sync overrun for a sync window",
191+
Long: "Enable sync overrun for a sync window. When enabled, syncs that started before a deny window will be allowed to continue. Requires ID which can be found by running \"argocd proj windows list PROJECT\"",
192+
Example: `
193+
#Enable sync overrun for a sync window
194+
argocd proj windows enable-sync-overrun PROJECT ID
195+
196+
#Enabling sync overrun for a window set on the default project with Id 2
197+
argocd proj windows enable-sync-overrun default 2`,
198+
Run: func(c *cobra.Command, args []string) {
199+
ctx := c.Context()
200+
201+
if len(args) != 2 {
202+
c.HelpFunc()(c, args)
203+
os.Exit(1)
204+
}
205+
206+
projName := args[0]
207+
id, err := strconv.Atoi(args[1])
208+
errors.CheckError(err)
209+
210+
conn, projIf := headless.NewClientOrDie(clientOpts, c).NewProjectClientOrDie()
211+
defer utilio.Close(conn)
212+
213+
proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName})
214+
errors.CheckError(err)
215+
216+
for i, window := range proj.Spec.SyncWindows {
217+
if id == i {
218+
window.SyncOverrun = true
219+
}
220+
}
221+
222+
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
223+
errors.CheckError(err)
224+
},
225+
}
226+
return command
227+
}
228+
141229
// NewProjectWindowsAddWindowCommand returns a new instance of an `argocd proj windows add` command
142230
func NewProjectWindowsAddWindowCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
143231
var (
@@ -148,6 +236,7 @@ func NewProjectWindowsAddWindowCommand(clientOpts *argocdclient.ClientOptions) *
148236
namespaces []string
149237
clusters []string
150238
manualSync bool
239+
syncOverrun bool
151240
timeZone string
152241
andOperator bool
153242
description string
@@ -189,7 +278,7 @@ argocd proj windows add PROJECT \
189278
proj, err := projIf.Get(ctx, &projectpkg.ProjectQuery{Name: projName})
190279
errors.CheckError(err)
191280

192-
err = proj.Spec.AddWindow(kind, schedule, duration, applications, namespaces, clusters, manualSync, timeZone, andOperator, description)
281+
err = proj.Spec.AddWindow(kind, schedule, duration, applications, namespaces, clusters, manualSync, timeZone, andOperator, description, syncOverrun)
193282
errors.CheckError(err)
194283

195284
_, err = projIf.Update(ctx, &projectpkg.ProjectUpdateRequest{Project: proj})
@@ -203,6 +292,7 @@ argocd proj windows add PROJECT \
203292
command.Flags().StringSliceVar(&namespaces, "namespaces", []string{}, "Namespaces that the schedule will be applied to. Comma separated, wildcards supported (e.g. --namespaces default,\\*-prod)")
204293
command.Flags().StringSliceVar(&clusters, "clusters", []string{}, "Clusters that the schedule will be applied to. Comma separated, wildcards supported (e.g. --clusters prod,staging)")
205294
command.Flags().BoolVar(&manualSync, "manual-sync", false, "Allow manual syncs for both deny and allow windows")
295+
command.Flags().BoolVar(&syncOverrun, "sync-overrun", false, "Allow syncs that started before a deny window to continue running")
206296
command.Flags().StringVar(&timeZone, "time-zone", "UTC", "Time zone of the sync window")
207297
command.Flags().BoolVar(&andOperator, "use-and-operator", false, "Use AND operator for matching applications, namespaces and clusters instead of the default OR operator")
208298
command.Flags().StringVar(&description, "description", "", `Sync window description`)
@@ -362,7 +452,7 @@ argocd proj windows list test-project`,
362452
func printSyncWindows(proj *v1alpha1.AppProject) {
363453
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
364454
var fmtStr string
365-
headers := []any{"ID", "STATUS", "KIND", "SCHEDULE", "DURATION", "APPLICATIONS", "NAMESPACES", "CLUSTERS", "MANUALSYNC", "TIMEZONE"}
455+
headers := []any{"ID", "STATUS", "KIND", "SCHEDULE", "DURATION", "APPLICATIONS", "NAMESPACES", "CLUSTERS", "MANUALSYNC", "SYNCOVERRUN", "TIMEZONE", "USEANDOPERATOR"}
366456
fmtStr = strings.Repeat("%s\t", len(headers)) + "\n"
367457
fmt.Fprintf(w, fmtStr, headers...)
368458
if proj.Spec.SyncWindows.HasWindows() {
@@ -378,6 +468,7 @@ func printSyncWindows(proj *v1alpha1.AppProject) {
378468
formatListOutput(window.Namespaces),
379469
formatListOutput(window.Clusters),
380470
formatBoolEnabledOutput(window.ManualSync),
471+
formatBoolEnabledOutput(window.SyncOverrun),
381472
window.TimeZone,
382473
formatBoolEnabledOutput(window.UseAndOperator),
383474
}

0 commit comments

Comments
 (0)