Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --async flag to argocd app sync #1738

Merged
merged 5 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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().
alexec marked this conversation as resolved.
Show resolved Hide resolved
Then().
Expect(Success("")).
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced))
alexec marked this conversation as resolved.
Show resolved Hide resolved
}

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")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!


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
}