mirror of
https://github.com/argoproj/argo-cd
synced 2026-05-23 17:28:44 +00:00
fix: app create with -f should not ignore other options (#4322)
This commit is contained in:
parent
4e6d8cc1d2
commit
cfb925c0d4
3 changed files with 55 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue