Skip to content

Commit

Permalink
updated docs and cli
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Wadsworth <[email protected]>
  • Loading branch information
bradkwadsworth committed Jan 30, 2025
1 parent ee1d1b4 commit 78adaa5
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 17 deletions.
8 changes: 8 additions & 0 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ type unsetOpts struct {
kustomizeNamespace bool
kustomizeImages []string
kustomizeReplicas []string
ignoreMissingComponents bool
parameters []string
valuesFiles []string
valuesLiteral bool
Expand All @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions cmd/argocd/commands/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 21 additions & 13 deletions cmd/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type AppOptions struct {
kustomizeNamespace string
kustomizeKubeVersion string
kustomizeApiVersions []string
ignoreMissingComponents bool
pluginEnvs []string
Validate bool
directoryExclude string
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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":
Expand Down
6 changes: 6 additions & 0 deletions cmd/util/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_admin_app_generate-spec.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_add-source.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_create.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_set.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_unset.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78adaa5

Please sign in to comment.