From 78adaa58b3341bc8c04091bb066dfbc855cd2631 Mon Sep 17 00:00:00 2001 From: Brad Wadsworth Date: Thu, 30 Jan 2025 16:09:38 -0600 Subject: [PATCH] updated docs and cli Signed-off-by: Brad Wadsworth --- cmd/argocd/commands/app.go | 8 +++++ cmd/argocd/commands/app_test.go | 16 +++++++-- cmd/util/app.go | 34 ++++++++++++------- cmd/util/app_test.go | 6 ++++ .../argocd_admin_app_generate-spec.md | 1 + .../commands/argocd_app_add-source.md | 1 + docs/user-guide/commands/argocd_app_create.md | 1 + docs/user-guide/commands/argocd_app_set.md | 1 + docs/user-guide/commands/argocd_app_unset.md | 1 + pkg/apis/application/v1alpha1/types.go | 3 +- 10 files changed, 55 insertions(+), 17 deletions(-) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 3ce81351b33a1..9cf50e1aa9289 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -887,6 +887,7 @@ type unsetOpts struct { kustomizeNamespace bool kustomizeImages []string kustomizeReplicas []string + ignoreMissingComponents bool parameters []string valuesFiles []string valuesLiteral bool @@ -903,6 +904,7 @@ func (o *unsetOpts) KustomizeIsZero() bool { !o.nameSuffix && !o.kustomizeVersion && !o.kustomizeNamespace && + !o.ignoreMissingComponents && len(o.kustomizeImages) == 0 && len(o.kustomizeReplicas) == 0 } @@ -1008,6 +1010,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C command.Flags().BoolVar(&opts.kustomizeNamespace, "kustomize-namespace", false, "Kustomize namespace") command.Flags().StringArrayVar(&opts.kustomizeImages, "kustomize-image", []string{}, "Kustomize images name (e.g. --kustomize-image node --kustomize-image mysql)") command.Flags().StringArrayVar(&opts.kustomizeReplicas, "kustomize-replica", []string{}, "Kustomize replicas name (e.g. --kustomize-replica my-deployment --kustomize-replica my-statefulset)") + command.Flags().BoolVar(&opts.ignoreMissingComponents, "ignore-missing-components", false, "Unset the kustomize ignore-missing-components option (revert to false)") command.Flags().StringArrayVar(&opts.pluginEnvs, "plugin-env", []string{}, "Unset plugin env variables (e.g --plugin-env name)") command.Flags().BoolVar(&opts.passCredentials, "pass-credentials", false, "Unset passCredentials") command.Flags().BoolVar(&opts.ref, "ref", false, "Unset ref on the source") @@ -1048,6 +1051,11 @@ func unset(source *argoappv1.ApplicationSource, opts unsetOpts) (updated bool, n source.Kustomize.Namespace = "" } + if opts.ignoreMissingComponents && source.Kustomize.IgnoreMissingComponents { + source.Kustomize.IgnoreMissingComponents = false + updated = true + } + for _, kustomizeImage := range opts.kustomizeImages { for i, item := range source.Kustomize.Images { if argoappv1.KustomizeImage(kustomizeImage).Match(item) { diff --git a/cmd/argocd/commands/app_test.go b/cmd/argocd/commands/app_test.go index 37b688f5cdfcd..b40dbf8fb1822 100644 --- a/cmd/argocd/commands/app_test.go +++ b/cmd/argocd/commands/app_test.go @@ -1053,9 +1053,10 @@ func TestPrintApplicationNames(t *testing.T) { func Test_unset(t *testing.T) { kustomizeSource := &v1alpha1.ApplicationSource{ Kustomize: &v1alpha1.ApplicationSourceKustomize{ - NamePrefix: "some-prefix", - NameSuffix: "some-suffix", - Version: "123", + IgnoreMissingComponents: true, + NamePrefix: "some-prefix", + NameSuffix: "some-suffix", + Version: "123", Images: v1alpha1.KustomizeImages{ "old1=new:tag", "old2=new:tag", @@ -1155,6 +1156,15 @@ func Test_unset(t *testing.T) { assert.False(t, updated) assert.False(t, nothingToUnset) + assert.True(t, kustomizeSource.Kustomize.IgnoreMissingComponents) + updated, nothingToUnset = unset(kustomizeSource, unsetOpts{ignoreMissingComponents: true}) + assert.False(t, kustomizeSource.Kustomize.IgnoreMissingComponents) + assert.True(t, updated) + assert.False(t, nothingToUnset) + updated, nothingToUnset = unset(kustomizeSource, unsetOpts{ignoreMissingComponents: true}) + assert.False(t, updated) + assert.False(t, nothingToUnset) + assert.Len(t, helmSource.Helm.Parameters, 2) updated, nothingToUnset = unset(helmSource, unsetOpts{parameters: []string{"name-1"}}) assert.Len(t, helmSource.Helm.Parameters, 1) diff --git a/cmd/util/app.go b/cmd/util/app.go index 6e748f716977c..932334621738f 100644 --- a/cmd/util/app.go +++ b/cmd/util/app.go @@ -82,6 +82,7 @@ type AppOptions struct { kustomizeNamespace string kustomizeKubeVersion string kustomizeApiVersions []string + ignoreMissingComponents bool pluginEnvs []string Validate bool directoryExclude string @@ -163,6 +164,7 @@ func AddAppFlags(command *cobra.Command, opts *AppOptions) { command.Flags().StringArrayVar(&opts.jsonnetLibs, "jsonnet-libs", []string{}, "Additional jsonnet libs (prefixed by repoRoot)") command.Flags().StringArrayVar(&opts.kustomizeImages, "kustomize-image", []string{}, "Kustomize images (e.g. --kustomize-image node:8.15.0 --kustomize-image mysql=mariadb,alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d)") command.Flags().StringArrayVar(&opts.kustomizeReplicas, "kustomize-replica", []string{}, "Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)") + command.Flags().BoolVar(&opts.ignoreMissingComponents, "ignore-missing-components", false, "Ignore locally missing component directories when setting Kustomize components") command.Flags().StringArrayVar(&opts.pluginEnvs, "plugin-env", []string{}, "Additional plugin envs") command.Flags().BoolVar(&opts.Validate, "validate", true, "Validation of repo and cluster") command.Flags().StringArrayVar(&opts.kustomizeCommonLabels, "kustomize-common-label", []string{}, "Set common labels in Kustomize") @@ -307,19 +309,20 @@ func SetAppSpecOptions(flags *pflag.FlagSet, spec *argoappv1.ApplicationSpec, ap } type kustomizeOpts struct { - namePrefix string - nameSuffix string - images []string - replicas []string - version string - commonLabels map[string]string - commonAnnotations map[string]string - labelWithoutSelector bool - forceCommonLabels bool - forceCommonAnnotations bool - namespace string - kubeVersion string - apiVersions []string + namePrefix string + nameSuffix string + images []string + replicas []string + version string + commonLabels map[string]string + commonAnnotations map[string]string + labelWithoutSelector bool + forceCommonLabels bool + forceCommonAnnotations bool + namespace string + kubeVersion string + apiVersions []string + ignoreMissingComponents bool } func setKustomizeOpt(src *argoappv1.ApplicationSource, opts kustomizeOpts) { @@ -359,6 +362,9 @@ func setKustomizeOpt(src *argoappv1.ApplicationSource, opts kustomizeOpts) { if opts.forceCommonAnnotations { src.Kustomize.ForceCommonAnnotations = opts.forceCommonAnnotations } + if opts.ignoreMissingComponents { + src.Kustomize.IgnoreMissingComponents = opts.ignoreMissingComponents + } for _, image := range opts.images { src.Kustomize.MergeImage(argoappv1.KustomizeImage(image)) } @@ -766,6 +772,8 @@ func ConstructSource(source *argoappv1.ApplicationSource, appOpts AppOptions, fl setKustomizeOpt(source, kustomizeOpts{forceCommonLabels: appOpts.kustomizeForceCommonLabels}) case "kustomize-force-common-annotation": setKustomizeOpt(source, kustomizeOpts{forceCommonAnnotations: appOpts.kustomizeForceCommonAnnotations}) + case "ignore-missing-components": + setKustomizeOpt(source, kustomizeOpts{ignoreMissingComponents: appOpts.ignoreMissingComponents}) case "jsonnet-tla-str": setJsonnetOpt(source, appOpts.jsonnetTlaStr, false) case "jsonnet-tla-code": diff --git a/cmd/util/app_test.go b/cmd/util/app_test.go index feca32ff17c98..e90e2ac89bf78 100644 --- a/cmd/util/app_test.go +++ b/cmd/util/app_test.go @@ -165,6 +165,12 @@ func Test_setKustomizeOpt(t *testing.T) { setKustomizeOpt(&src, kustomizeOpts{commonLabels: map[string]string{"foo1": "bar1", "foo2": "bar2"}, labelWithoutSelector: true}) assert.Equal(t, &v1alpha1.ApplicationSourceKustomize{CommonLabels: map[string]string{"foo1": "bar1", "foo2": "bar2"}, LabelWithoutSelector: true}, src.Kustomize) }) + t.Run("IgnoreMissingComponents", func(t *testing.T) { + src := v1alpha1.ApplicationSource{} + setKustomizeOpt(&src, kustomizeOpts{ignoreMissingComponents: true}) + t.Logf("HERE IS THE SOURCE\n %+v\n", src) + assert.True(t, src.Kustomize.IgnoreMissingComponents) + }) } func Test_setJsonnetOpt(t *testing.T) { diff --git a/docs/user-guide/commands/argocd_admin_app_generate-spec.md b/docs/user-guide/commands/argocd_admin_app_generate-spec.md index c5e4ee3ac433b..bb5658edeabe6 100644 --- a/docs/user-guide/commands/argocd_admin_app_generate-spec.md +++ b/docs/user-guide/commands/argocd_admin_app_generate-spec.md @@ -64,6 +64,7 @@ argocd admin app generate-spec APPNAME [flags] --helm-version string Helm version -h, --help help for generate-spec --hydrate-to-branch string The branch to hydrate the app to + --ignore-missing-components Ignore locally missing component directories when setting Kustomize components --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 diff --git a/docs/user-guide/commands/argocd_app_add-source.md b/docs/user-guide/commands/argocd_app_add-source.md index 72f2f98cf0616..5ae0dc1a33614 100644 --- a/docs/user-guide/commands/argocd_app_add-source.md +++ b/docs/user-guide/commands/argocd_app_add-source.md @@ -46,6 +46,7 @@ argocd app add-source APPNAME [flags] --helm-version string Helm version -h, --help help for add-source --hydrate-to-branch string The branch to hydrate the app to + --ignore-missing-components Ignore locally missing component directories when setting Kustomize components --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 diff --git a/docs/user-guide/commands/argocd_app_create.md b/docs/user-guide/commands/argocd_app_create.md index 0dc043f83febb..c59f6da4313ce 100644 --- a/docs/user-guide/commands/argocd_app_create.md +++ b/docs/user-guide/commands/argocd_app_create.md @@ -66,6 +66,7 @@ argocd app create APPNAME [flags] --helm-version string Helm version -h, --help help for create --hydrate-to-branch string The branch to hydrate the app to + --ignore-missing-components Ignore locally missing component directories when setting Kustomize components --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 diff --git a/docs/user-guide/commands/argocd_app_set.md b/docs/user-guide/commands/argocd_app_set.md index f877155d3ea7e..bcbac8ca5b4d4 100644 --- a/docs/user-guide/commands/argocd_app_set.md +++ b/docs/user-guide/commands/argocd_app_set.md @@ -58,6 +58,7 @@ argocd app set APPNAME [flags] --helm-version string Helm version -h, --help help for set --hydrate-to-branch string The branch to hydrate the app to + --ignore-missing-components Ignore locally missing component directories when setting Kustomize components --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 diff --git a/docs/user-guide/commands/argocd_app_unset.md b/docs/user-guide/commands/argocd_app_unset.md index a4ff76356539c..f953d858d7ff9 100644 --- a/docs/user-guide/commands/argocd_app_unset.md +++ b/docs/user-guide/commands/argocd_app_unset.md @@ -32,6 +32,7 @@ argocd app unset APPNAME parameters [flags] ``` -N, --app-namespace string Unset application parameters in namespace -h, --help help for unset + --ignore-missing-components Unset the kustomize ignore-missing-components option (revert to false) --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-namespace Kustomize namespace diff --git a/pkg/apis/application/v1alpha1/types.go b/pkg/apis/application/v1alpha1/types.go index f9f301d7f57a3..a8167742508e5 100644 --- a/pkg/apis/application/v1alpha1/types.go +++ b/pkg/apis/application/v1alpha1/types.go @@ -769,7 +769,8 @@ func (k *ApplicationSourceKustomize) IsZero() bool { len(k.Patches) == 0 && len(k.Components) == 0 && k.KubeVersion == "" && - len(k.APIVersions) == 0 + len(k.APIVersions) == 0 && + !k.IgnoreMissingComponents } // MergeImage merges a new Kustomize image identifier in to a list of images