mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-23 09:18:26 +00:00
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:
parent
460f6653dc
commit
e102ec11ac
3 changed files with 25 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
Loading…
Reference in a new issue