diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 79c4dfcb0e..aabb29e36e 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -153,8 +153,15 @@ func NewApplicationCreateCommand(clientOpts *argocdclient.ClientOptions) *cobra. log.Fatalf("app name '%s' does not match app spec metadata.name '%s'", args[0], app.Name) } if appName != "" && appName != app.Name { - log.Fatalf("--name argument '%s' does not match app spec metadata.name '%s'", appName, app.Name) + app.Name = appName } + if app.Name == "" { + log.Fatalf("app.Name is empty. --name argument can be used to provide app.Name") + } + setAppSpecOptions(c.Flags(), &app.Spec, &appOpts) + setParameterOverrides(&app, appOpts.parameters) + setLabels(&app, labels) + } else { // read arguments if len(args) == 1 { diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index b5196483f7..79d3789cac 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -1381,3 +1381,24 @@ func TestCreateDisableValidation(t *testing.T) { AppSet("--path", "baddir3", "--validate=false") } + +func TestCreateFromPartialFile(t *testing.T) { + partialApp := + `spec: + syncPolicy: + automated: {prune: true }` + + path := "helm-values" + Given(t). + When(). + // app should be auto-synced once created + CreateFromPartialFile(partialApp, "--path", path, "--helm-set", "foo=foo"). + Then(). + Expect(Success("")). + Expect(SyncStatusIs(SyncStatusCodeSynced)). + Expect(NoConditions()). + And(func(app *Application) { + assert.Equal(t, path, app.Spec.Source.Path) + assert.Equal(t, []HelmParameter{{Name: "foo", Value: "foo"}}, app.Spec.Source.Helm.Parameters) + }) +} diff --git a/test/e2e/fixture/app/actions.go b/test/e2e/fixture/app/actions.go index c660a1843f..b52f069647 100644 --- a/test/e2e/fixture/app/actions.go +++ b/test/e2e/fixture/app/actions.go @@ -58,7 +58,26 @@ func (a *Actions) AddSignedFile(fileName, fileContents string) *Actions { return a } -func (a *Actions) CreateFromFile(handler func(app *Application)) *Actions { +func (a *Actions) CreateFromPartialFile(data string, flags ...string) *Actions { + a.context.t.Helper() + tmpFile, err := ioutil.TempFile("", "") + errors.CheckError(err) + _, err = tmpFile.Write([]byte(data)) + errors.CheckError(err) + + args := append([]string{ + "app", "create", + "-f", tmpFile.Name(), + "--name", a.context.name, + "--repo", fixture.RepoURL(a.context.repoURLType), + "--dest-server", a.context.destServer, + "--dest-namespace", fixture.DeploymentNamespace(), + }, flags...) + + a.runCli(args...) + return a +} +func (a *Actions) CreateFromFile(handler func(app *Application), flags ...string) *Actions { a.context.t.Helper() app := &Application{ ObjectMeta: v1.ObjectMeta{ @@ -108,7 +127,12 @@ func (a *Actions) CreateFromFile(handler func(app *Application)) *Actions { _, err = tmpFile.Write(data) errors.CheckError(err) - a.runCli("app", "create", "-f", tmpFile.Name()) + args := append([]string{ + "app", "create", + "-f", tmpFile.Name(), + }, flags...) + + a.runCli(args...) return a }