Skip to content

Commit 0973409

Browse files
feat: Kustomize ignore missing components (#18634) (#21674)
Signed-off-by: Brad Wadsworth <[email protected]>
1 parent 922dd77 commit 0973409

25 files changed

+1984
-766
lines changed

assets/swagger.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/argocd/commands/app.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ type unsetOpts struct {
887887
kustomizeNamespace bool
888888
kustomizeImages []string
889889
kustomizeReplicas []string
890+
ignoreMissingComponents bool
890891
parameters []string
891892
valuesFiles []string
892893
valuesLiteral bool
@@ -903,6 +904,7 @@ func (o *unsetOpts) KustomizeIsZero() bool {
903904
!o.nameSuffix &&
904905
!o.kustomizeVersion &&
905906
!o.kustomizeNamespace &&
907+
!o.ignoreMissingComponents &&
906908
len(o.kustomizeImages) == 0 &&
907909
len(o.kustomizeReplicas) == 0
908910
}
@@ -1008,6 +1010,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
10081010
command.Flags().BoolVar(&opts.kustomizeNamespace, "kustomize-namespace", false, "Kustomize namespace")
10091011
command.Flags().StringArrayVar(&opts.kustomizeImages, "kustomize-image", []string{}, "Kustomize images name (e.g. --kustomize-image node --kustomize-image mysql)")
10101012
command.Flags().StringArrayVar(&opts.kustomizeReplicas, "kustomize-replica", []string{}, "Kustomize replicas name (e.g. --kustomize-replica my-deployment --kustomize-replica my-statefulset)")
1013+
command.Flags().BoolVar(&opts.ignoreMissingComponents, "ignore-missing-components", false, "Unset the kustomize ignore-missing-components option (revert to false)")
10111014
command.Flags().StringArrayVar(&opts.pluginEnvs, "plugin-env", []string{}, "Unset plugin env variables (e.g --plugin-env name)")
10121015
command.Flags().BoolVar(&opts.passCredentials, "pass-credentials", false, "Unset passCredentials")
10131016
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
10481051
source.Kustomize.Namespace = ""
10491052
}
10501053

1054+
if opts.ignoreMissingComponents && source.Kustomize.IgnoreMissingComponents {
1055+
source.Kustomize.IgnoreMissingComponents = false
1056+
updated = true
1057+
}
1058+
10511059
for _, kustomizeImage := range opts.kustomizeImages {
10521060
for i, item := range source.Kustomize.Images {
10531061
if argoappv1.KustomizeImage(kustomizeImage).Match(item) {

cmd/argocd/commands/app_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,10 @@ func TestPrintApplicationNames(t *testing.T) {
10531053
func Test_unset(t *testing.T) {
10541054
kustomizeSource := &v1alpha1.ApplicationSource{
10551055
Kustomize: &v1alpha1.ApplicationSourceKustomize{
1056-
NamePrefix: "some-prefix",
1057-
NameSuffix: "some-suffix",
1058-
Version: "123",
1056+
IgnoreMissingComponents: true,
1057+
NamePrefix: "some-prefix",
1058+
NameSuffix: "some-suffix",
1059+
Version: "123",
10591060
Images: v1alpha1.KustomizeImages{
10601061
"old1=new:tag",
10611062
"old2=new:tag",
@@ -1155,6 +1156,15 @@ func Test_unset(t *testing.T) {
11551156
assert.False(t, updated)
11561157
assert.False(t, nothingToUnset)
11571158

1159+
assert.True(t, kustomizeSource.Kustomize.IgnoreMissingComponents)
1160+
updated, nothingToUnset = unset(kustomizeSource, unsetOpts{ignoreMissingComponents: true})
1161+
assert.False(t, kustomizeSource.Kustomize.IgnoreMissingComponents)
1162+
assert.True(t, updated)
1163+
assert.False(t, nothingToUnset)
1164+
updated, nothingToUnset = unset(kustomizeSource, unsetOpts{ignoreMissingComponents: true})
1165+
assert.False(t, updated)
1166+
assert.False(t, nothingToUnset)
1167+
11581168
assert.Len(t, helmSource.Helm.Parameters, 2)
11591169
updated, nothingToUnset = unset(helmSource, unsetOpts{parameters: []string{"name-1"}})
11601170
assert.Len(t, helmSource.Helm.Parameters, 1)

cmd/util/app.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type AppOptions struct {
8282
kustomizeNamespace string
8383
kustomizeKubeVersion string
8484
kustomizeApiVersions []string
85+
ignoreMissingComponents bool
8586
pluginEnvs []string
8687
Validate bool
8788
directoryExclude string
@@ -163,6 +164,7 @@ func AddAppFlags(command *cobra.Command, opts *AppOptions) {
163164
command.Flags().StringArrayVar(&opts.jsonnetLibs, "jsonnet-libs", []string{}, "Additional jsonnet libs (prefixed by repoRoot)")
164165
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)")
165166
command.Flags().StringArrayVar(&opts.kustomizeReplicas, "kustomize-replica", []string{}, "Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)")
167+
command.Flags().BoolVar(&opts.ignoreMissingComponents, "ignore-missing-components", false, "Ignore locally missing component directories when setting Kustomize components")
166168
command.Flags().StringArrayVar(&opts.pluginEnvs, "plugin-env", []string{}, "Additional plugin envs")
167169
command.Flags().BoolVar(&opts.Validate, "validate", true, "Validation of repo and cluster")
168170
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
307309
}
308310

309311
type kustomizeOpts struct {
310-
namePrefix string
311-
nameSuffix string
312-
images []string
313-
replicas []string
314-
version string
315-
commonLabels map[string]string
316-
commonAnnotations map[string]string
317-
labelWithoutSelector bool
318-
forceCommonLabels bool
319-
forceCommonAnnotations bool
320-
namespace string
321-
kubeVersion string
322-
apiVersions []string
312+
namePrefix string
313+
nameSuffix string
314+
images []string
315+
replicas []string
316+
version string
317+
commonLabels map[string]string
318+
commonAnnotations map[string]string
319+
labelWithoutSelector bool
320+
forceCommonLabels bool
321+
forceCommonAnnotations bool
322+
namespace string
323+
kubeVersion string
324+
apiVersions []string
325+
ignoreMissingComponents bool
323326
}
324327

325328
func setKustomizeOpt(src *argoappv1.ApplicationSource, opts kustomizeOpts) {
@@ -359,6 +362,9 @@ func setKustomizeOpt(src *argoappv1.ApplicationSource, opts kustomizeOpts) {
359362
if opts.forceCommonAnnotations {
360363
src.Kustomize.ForceCommonAnnotations = opts.forceCommonAnnotations
361364
}
365+
if opts.ignoreMissingComponents {
366+
src.Kustomize.IgnoreMissingComponents = opts.ignoreMissingComponents
367+
}
362368
for _, image := range opts.images {
363369
src.Kustomize.MergeImage(argoappv1.KustomizeImage(image))
364370
}
@@ -766,6 +772,8 @@ func ConstructSource(source *argoappv1.ApplicationSource, appOpts AppOptions, fl
766772
setKustomizeOpt(source, kustomizeOpts{forceCommonLabels: appOpts.kustomizeForceCommonLabels})
767773
case "kustomize-force-common-annotation":
768774
setKustomizeOpt(source, kustomizeOpts{forceCommonAnnotations: appOpts.kustomizeForceCommonAnnotations})
775+
case "ignore-missing-components":
776+
setKustomizeOpt(source, kustomizeOpts{ignoreMissingComponents: appOpts.ignoreMissingComponents})
769777
case "jsonnet-tla-str":
770778
setJsonnetOpt(source, appOpts.jsonnetTlaStr, false)
771779
case "jsonnet-tla-code":

cmd/util/app_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ func Test_setKustomizeOpt(t *testing.T) {
165165
setKustomizeOpt(&src, kustomizeOpts{commonLabels: map[string]string{"foo1": "bar1", "foo2": "bar2"}, labelWithoutSelector: true})
166166
assert.Equal(t, &v1alpha1.ApplicationSourceKustomize{CommonLabels: map[string]string{"foo1": "bar1", "foo2": "bar2"}, LabelWithoutSelector: true}, src.Kustomize)
167167
})
168+
t.Run("IgnoreMissingComponents", func(t *testing.T) {
169+
src := v1alpha1.ApplicationSource{}
170+
setKustomizeOpt(&src, kustomizeOpts{ignoreMissingComponents: true})
171+
t.Logf("HERE IS THE SOURCE\n %+v\n", src)
172+
assert.True(t, src.Kustomize.IgnoreMissingComponents)
173+
})
168174
}
169175

170176
func Test_setJsonnetOpt(t *testing.T) {

docs/operator-manual/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ spec:
130130
count: 4
131131
components:
132132
- ../component # relative to the kustomization.yaml (`source.path`).
133+
# Ignore locally missing component directories when using Kustomize Components. Defaults to false
134+
ignoreMissingComponents: true
133135
patches:
134136
- target:
135137
kind: Deployment

docs/user-guide/commands/argocd_admin_app_generate-spec.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/user-guide/commands/argocd_app_add-source.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/user-guide/commands/argocd_app_create.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/user-guide/commands/argocd_app_set.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)