Skip to content

Commit

Permalink
Added --async flag to argocd app sync (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored and alexec committed Jun 14, 2019
1 parent 40ca1e7 commit 770832b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
24 changes: 14 additions & 10 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
timeout uint
strategy string
force bool
async bool
)
var command = &cobra.Command{
Use: "sync APPNAME",
Expand Down Expand Up @@ -1163,18 +1164,20 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
_, err := appIf.Sync(ctx, &syncReq)
errors.CheckError(err)

app, err := waitOnApplicationStatus(acdClient, appName, timeout, false, false, true, false, selectedResources)
errors.CheckError(err)
if !async {
app, err := waitOnApplicationStatus(acdClient, appName, timeout, false, false, true, false, selectedResources)
errors.CheckError(err)

// Only get resources to be pruned if sync was application-wide
if len(selectedResources) == 0 {
pruningRequired := app.Status.OperationState.SyncResult.Resources.PruningRequired()
if pruningRequired > 0 {
log.Fatalf("%d resources require pruning", pruningRequired)
}
// Only get resources to be pruned if sync was application-wide
if len(selectedResources) == 0 {
pruningRequired := app.Status.OperationState.SyncResult.Resources.PruningRequired()
if pruningRequired > 0 {
log.Fatalf("%d resources require pruning", pruningRequired)
}

if !app.Status.OperationState.Phase.Successful() && !dryRun {
os.Exit(1)
if !app.Status.OperationState.Phase.Successful() && !dryRun {
os.Exit(1)
}
}
}
},
Expand All @@ -1187,6 +1190,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
command.Flags().UintVar(&timeout, "timeout", defaultCheckTimeoutSeconds, "Time out after this many seconds")
command.Flags().StringVar(&strategy, "strategy", "", "Sync strategy (one of: apply|hook)")
command.Flags().BoolVar(&force, "force", false, "Use a force apply")
command.Flags().BoolVar(&async, "async", false, "Do not wait for application to sync before continuing")
return command
}

Expand Down
22 changes: 18 additions & 4 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,28 @@ func TestSyncResourceByLabel(t *testing.T) {
Sync().
Then().
And(func(app *Application) {
res, _ := fixture.RunCli("app", "sync", app.Name, "--label", fmt.Sprintf("app.kubernetes.io/instance=%s", app.Name))
assert.Contains(t, res, "guestbook-ui Synced Healthy")

res, _ = fixture.RunCli("app", "sync", app.Name, "--label", "this-label=does-not-exist")
_, _ = fixture.RunCli("app", "sync", app.Name, "--label", fmt.Sprintf("app.kubernetes.io/instance=%s", app.Name))
}).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
And(func(app *Application) {
res, _ := fixture.RunCli("app", "sync", app.Name, "--label", "this-label=does-not-exist")
assert.Contains(t, res, "level=fatal")
})
}

func TestSyncAsync(t *testing.T) {
Given(t).
Path(guestbookPath).
Async(true).
When().
Create().
Sync().
Then().
Expect(Success("")).
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced))
}

func TestPermissions(t *testing.T) {
fixture.EnsureCleanState(t)
appName := fixture.Name()
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/fixture/app/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (a *Actions) PatchApp(patch string) *Actions {
func (a *Actions) Sync() *Actions {
args := []string{"app", "sync", a.context.name, "--timeout", "5"}

if a.context.async {
args = append(args, "--async")
}

if a.context.prune {
args = append(args, "--prune")
}
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/fixture/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Context struct {
resource string
prune bool
configManagementPlugin string
async bool
}

func Given(t *testing.T) *Context {
Expand Down Expand Up @@ -88,3 +89,8 @@ func (c *Context) Prune(prune bool) *Context {
c.prune = prune
return c
}

func (c *Context) Async(async bool) *Context {
c.async = async
return c
}

0 comments on commit 770832b

Please sign in to comment.