feat: Allow --local with automatic sync for --dry-run (#3675)

* feat: Allow --local with automatic sync for --dry-run

Signed-off-by: darshanime <deathbullet@gmail.com>

* feat: add e2e test for local sync with dry run

Signed-off-by: darshanime <deathbullet@gmail.com>
This commit is contained in:
Darshan Chaudhary 2020-06-10 17:35:37 +05:30 committed by GitHub
parent 460f6653dc
commit e102ec11ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View file

@ -1483,8 +1483,8 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
if local != "" {
app, err := appIf.Get(context.Background(), &applicationpkg.ApplicationQuery{Name: &appName})
errors.CheckError(err)
if app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.Automated != nil {
log.Fatal("Cannot use local sync when Automatic Sync Policy is enabled")
if app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.Automated != nil && !dryRun {
log.Fatal("Cannot use local sync when Automatic Sync Policy is enabled except with --dry-run")
}
errors.CheckError(err)

View file

@ -1055,8 +1055,8 @@ func (s *Server) Sync(ctx context.Context, syncReq *application.ApplicationSyncR
if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionOverride, appRBACName(*a)); err != nil {
return nil, err
}
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.Automated != nil {
return nil, status.Error(codes.FailedPrecondition, "Cannot use local sync when Automatic Sync Policy is enabled")
if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.Automated != nil && !syncReq.DryRun {
return nil, status.Error(codes.FailedPrecondition, "Cannot use local sync when Automatic Sync Policy is enabled unless for dry run")
}
}
if a.DeletionTimestamp != nil {

View file

@ -6,6 +6,7 @@ import (
"math/rand"
"os"
"path"
"reflect"
"regexp"
"strings"
"testing"
@ -687,6 +688,26 @@ func TestNoLocalSyncWithAutosyncEnabled(t *testing.T) {
})
}
func TestLocalSyncDryRunWithAutosyncEnabled(t *testing.T) {
Given(t).
Path(guestbookPath).
When().
Create().
Sync().
Then().
And(func(app *Application) {
_, err := RunCli("app", "set", app.Name, "--sync-policy", "automated")
assert.NoError(t, err)
appBefore := app.DeepCopy()
_, err = RunCli("app", "sync", app.Name, "--dry-run", "--local", guestbookPathLocal)
assert.NoError(t, err)
appAfter := app.DeepCopy()
assert.True(t, reflect.DeepEqual(appBefore, appAfter))
})
}
func TestSyncAsync(t *testing.T) {
Given(t).
Path(guestbookPath).