Skip to content

Commit

Permalink
feat: added a new Helm option ignoreMissingValueFiles (#7767) (#8003)
Browse files Browse the repository at this point in the history
so as to allow operators to prevent Argo CD from passing valueFiles
to helm template if they don't exist in the source under the specified path.

Signed-off-by: Oscar Craviotto <craviotto@avellaneda.com>
  • Loading branch information
ocraviotto authored Jan 3, 2022
1 parent 8e6fcde commit 99d1dca
Show file tree
Hide file tree
Showing 19 changed files with 710 additions and 445 deletions.
4 changes: 4 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4899,6 +4899,10 @@
"$ref": "#/definitions/v1alpha1HelmFileParameter"
}
},
"ignoreMissingValueFiles": {
"type": "boolean",
"title": "IgnoreMissingValueFiles prevents helm template from failing when valueFiles do not exist locally by not appending them to helm template --values"
},
"parameters": {
"type": "array",
"title": "Parameters is a list of Helm parameters which are passed to the helm template command upon manifest generation",
Expand Down
26 changes: 16 additions & 10 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,16 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
// NewApplicationUnsetCommand returns a new instance of an `argocd app unset` command
func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var (
parameters []string
valuesLiteral bool
valuesFiles []string
nameSuffix bool
namePrefix bool
kustomizeVersion bool
kustomizeImages []string
pluginEnvs []string
appOpts cmdutil.AppOptions
parameters []string
valuesLiteral bool
valuesFiles []string
ignoreMissingValueFiles bool
nameSuffix bool
namePrefix bool
kustomizeVersion bool
kustomizeImages []string
pluginEnvs []string
appOpts cmdutil.AppOptions
)
var command = &cobra.Command{
Use: "unset APPNAME parameters",
Expand Down Expand Up @@ -643,7 +644,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
}
}
if app.Spec.Source.Helm != nil {
if len(parameters) == 0 && len(valuesFiles) == 0 && !valuesLiteral {
if len(parameters) == 0 && len(valuesFiles) == 0 && !valuesLiteral && !ignoreMissingValueFiles {
c.HelpFunc()(c, args)
os.Exit(1)
}
Expand Down Expand Up @@ -671,6 +672,10 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
}
}
}
if ignoreMissingValueFiles {
app.Spec.Source.Helm.IgnoreMissingValueFiles = false
updated = true
}
if app.Spec.Source.Helm.PassCredentials {
app.Spec.Source.Helm.PassCredentials = false
updated = true
Expand Down Expand Up @@ -706,6 +711,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
command.Flags().StringArrayVarP(&parameters, "parameter", "p", []string{}, "Unset a parameter override (e.g. -p guestbook=image)")
command.Flags().StringArrayVar(&valuesFiles, "values", []string{}, "Unset one or more Helm values files")
command.Flags().BoolVar(&valuesLiteral, "values-literal", false, "Unset literal Helm values block")
command.Flags().BoolVar(&ignoreMissingValueFiles, "ignore-missing-value-files", false, "Unset the helm ignore-missing-value-files option (revert to false)")
command.Flags().BoolVar(&nameSuffix, "namesuffix", false, "Kustomize namesuffix")
command.Flags().BoolVar(&namePrefix, "nameprefix", false, "Kustomize nameprefix")
command.Flags().BoolVar(&kustomizeVersion, "kustomize-version", false, "Kustomize version")
Expand Down
24 changes: 16 additions & 8 deletions cmd/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type AppOptions struct {
destNamespace string
Parameters []string
valuesFiles []string
ignoreMissingValueFiles bool
values string
releaseName string
helmSets []string
Expand Down Expand Up @@ -86,6 +87,7 @@ func AddAppFlags(command *cobra.Command, opts *AppOptions) {
command.Flags().StringVar(&opts.destNamespace, "dest-namespace", "", "K8s target namespace (overrides the namespace specified in the ksonnet app.yaml)")
command.Flags().StringArrayVarP(&opts.Parameters, "parameter", "p", []string{}, "set a parameter override (e.g. -p guestbook=image=example/guestbook:latest)")
command.Flags().StringArrayVar(&opts.valuesFiles, "values", []string{}, "Helm values file(s) to use")
command.Flags().BoolVar(&opts.ignoreMissingValueFiles, "ignore-missing-value-files", false, "Ignore locally missing valueFiles when setting helm template --values")
command.Flags().StringVar(&opts.values, "values-literal-file", "", "Filename or URL to import as a literal Helm values block")
command.Flags().StringVar(&opts.releaseName, "release-name", "", "Helm release-name")
command.Flags().StringVar(&opts.helmVersion, "helm-version", "", "Helm version")
Expand Down Expand Up @@ -147,6 +149,8 @@ func SetAppSpecOptions(flags *pflag.FlagSet, spec *argoappv1.ApplicationSpec, ap
spec.RevisionHistoryLimit = &i
case "values":
setHelmOpt(&spec.Source, helmOpts{valueFiles: appOpts.valuesFiles})
case "ignore-missing-value-files":
setHelmOpt(&spec.Source, helmOpts{ignoreMissingValueFiles: appOpts.ignoreMissingValueFiles})
case "values-literal-file":
var data []byte

Expand Down Expand Up @@ -381,14 +385,15 @@ func setPluginOptEnvs(src *argoappv1.ApplicationSource, envs []string) {
}

type helmOpts struct {
valueFiles []string
values string
releaseName string
version string
helmSets []string
helmSetStrings []string
helmSetFiles []string
passCredentials bool
valueFiles []string
ignoreMissingValueFiles bool
values string
releaseName string
version string
helmSets []string
helmSetStrings []string
helmSetFiles []string
passCredentials bool
}

func setHelmOpt(src *argoappv1.ApplicationSource, opts helmOpts) {
Expand All @@ -398,6 +403,9 @@ func setHelmOpt(src *argoappv1.ApplicationSource, opts helmOpts) {
if len(opts.valueFiles) > 0 {
src.Helm.ValueFiles = opts.valueFiles
}
if opts.ignoreMissingValueFiles {
src.Helm.IgnoreMissingValueFiles = opts.ignoreMissingValueFiles
}
if len(opts.values) > 0 {
src.Helm.Values = opts.values
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/util/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func Test_setHelmOpt(t *testing.T) {
setHelmOpt(&src, helmOpts{valueFiles: []string{"foo"}})
assert.Equal(t, []string{"foo"}, src.Helm.ValueFiles)
})
t.Run("IgnoreMissingValueFiles", func(t *testing.T) {
src := v1alpha1.ApplicationSource{}
setHelmOpt(&src, helmOpts{ignoreMissingValueFiles: true})
assert.Equal(t, true, src.Helm.IgnoreMissingValueFiles)
})
t.Run("ReleaseName", func(t *testing.T) {
src := v1alpha1.ApplicationSource{}
setHelmOpt(&src, helmOpts{releaseName: "foo"})
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_admin_app_generate-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ argocd admin app generate-spec APPNAME [flags]
--helm-set-string stringArray Helm set STRING values on the command line (can be repeated to set several values: --helm-set-string key1=val1 --helm-set-string key2=val2)
--helm-version string Helm version
-h, --help help for generate-spec
--ignore-missing-value-files Ignore locally missing valueFiles when setting helm template --values
-i, --inline If set then generated resource is written back to the file specified in --file flag
--jsonnet-ext-var-code stringArray Jsonnet ext var
--jsonnet-ext-var-str stringArray Jsonnet string ext var
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ argocd app create APPNAME [flags]
--helm-set-string stringArray Helm set STRING values on the command line (can be repeated to set several values: --helm-set-string key1=val1 --helm-set-string key2=val2)
--helm-version string Helm version
-h, --help help for create
--ignore-missing-value-files Ignore locally missing valueFiles when setting helm template --values
--jsonnet-ext-var-code stringArray Jsonnet ext var
--jsonnet-ext-var-str stringArray Jsonnet string ext var
--jsonnet-libs stringArray Additional jsonnet libs (prefixed by repoRoot)
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ argocd app set APPNAME [flags]
--helm-set-string stringArray Helm set STRING values on the command line (can be repeated to set several values: --helm-set-string key1=val1 --helm-set-string key2=val2)
--helm-version string Helm version
-h, --help help for set
--ignore-missing-value-files Ignore locally missing valueFiles when setting helm template --values
--jsonnet-ext-var-code stringArray Jsonnet ext var
--jsonnet-ext-var-str stringArray Jsonnet string ext var
--jsonnet-libs stringArray Additional jsonnet libs (prefixed by repoRoot)
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ argocd app unset APPNAME parameters [flags]

```
-h, --help help for unset
--ignore-missing-value-files Unset the helm ignore-missing-value-files option (revert to false)
--kustomize-image stringArray Kustomize images name (e.g. --kustomize-image node --kustomize-image mysql)
--kustomize-version Kustomize version
--nameprefix Kustomize nameprefix
Expand Down
31 changes: 31 additions & 0 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally by
not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters which
are passed to the helm template command upon manifest
Expand Down Expand Up @@ -599,6 +604,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally by not
appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters which
are passed to the helm template command upon manifest generation
Expand Down Expand Up @@ -967,6 +977,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally
by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down Expand Up @@ -1350,6 +1365,12 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents
helm template from failing when valueFiles do
not exist locally by not appending them to helm
template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command
Expand Down Expand Up @@ -1715,6 +1736,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm
template from failing when valueFiles do not exist
locally by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down Expand Up @@ -2066,6 +2092,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm
template from failing when valueFiles do not exist
locally by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down
31 changes: 31 additions & 0 deletions manifests/crds/application-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally by
not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters which
are passed to the helm template command upon manifest
Expand Down Expand Up @@ -598,6 +603,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally by not
appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters which
are passed to the helm template command upon manifest generation
Expand Down Expand Up @@ -966,6 +976,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm template
from failing when valueFiles do not exist locally
by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down Expand Up @@ -1349,6 +1364,12 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents
helm template from failing when valueFiles do
not exist locally by not appending them to helm
template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command
Expand Down Expand Up @@ -1714,6 +1735,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm
template from failing when valueFiles do not exist
locally by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down Expand Up @@ -2065,6 +2091,11 @@ spec:
type: string
type: object
type: array
ignoreMissingValueFiles:
description: IgnoreMissingValueFiles prevents helm
template from failing when valueFiles do not exist
locally by not appending them to helm template --values
type: boolean
parameters:
description: Parameters is a list of Helm parameters
which are passed to the helm template command upon
Expand Down
Loading

0 comments on commit 99d1dca

Please sign in to comment.