Skip to content

Commit

Permalink
feat: Allow Kustomize common labels to not apply to selectors (#17329)
Browse files Browse the repository at this point in the history
* modify crds

Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>

* cmd opts and test

Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>

* kustomize build and test

Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>

* fix option order and add ancestry to users

Signed-off-by: lets-call-n-walk <[email protected]>

* fix users format

Signed-off-by: lets-call-n-walk <[email protected]>

* generated files

Signed-off-by: lets-call-n-walk <[email protected]>

* set flag value

Signed-off-by: lets-call-n-walk <[email protected]>

* modify crds

Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>

* chore(deps): bump library/registry in /test/container (#17317)

Bumps library/registry from `b209a41` to `f4e1b87`.

---
updated-dependencies:
- dependency-name: library/registry
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>

* generated files

Signed-off-by: lets-call-n-walk <[email protected]>

* add docs

Signed-off-by: lets-call-n-walk <[email protected]>

* fix doc

Signed-off-by: lets-call-n-walk <[email protected]>

* remove debug prints

Signed-off-by: lets-call-n-walk <[email protected]>

* fix autogen docs

Signed-off-by: lets-call-n-walk <[email protected]>

---------

Signed-off-by: Collin <[email protected]>
Signed-off-by: lets-call-n-walk <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Collin Walker <[email protected]>
Co-authored-by: Collin <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 7eda6e0 commit 839526e
Show file tree
Hide file tree
Showing 22 changed files with 1,463 additions and 686 deletions.
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [Allianz Direct](https://www.allianzdirect.de/)
1. [Amadeus IT Group](https://amadeus.com/)
1. [Ambassador Labs](https://www.getambassador.io/)
1. [Ancestry](https://www.ancestry.com/)
1. [ANSTO - Australian Synchrotron](https://www.synchrotron.org.au/)
1. [Ant Group](https://www.antgroup.com/)
1. [AppDirect](https://www.appdirect.com)
Expand Down
4 changes: 4 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6424,6 +6424,10 @@
"type": "string"
}
},
"labelWithoutSelector": {
"type": "boolean",
"title": "LabelWithoutSelector specifies whether to apply common labels to resource selectors or not"
},
"namePrefix": {
"type": "string",
"title": "NamePrefix is a prefix appended to resources for Kustomize apps"
Expand Down
8 changes: 8 additions & 0 deletions cmd/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type AppOptions struct {
kustomizeVersion string
kustomizeCommonLabels []string
kustomizeCommonAnnotations []string
kustomizeLabelWithoutSelector bool
kustomizeForceCommonLabels bool
kustomizeForceCommonAnnotations bool
kustomizeNamespace string
Expand Down Expand Up @@ -125,6 +126,7 @@ func AddAppFlags(command *cobra.Command, opts *AppOptions) {
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")
command.Flags().StringArrayVar(&opts.kustomizeCommonAnnotations, "kustomize-common-annotation", []string{}, "Set common labels in Kustomize")
command.Flags().BoolVar(&opts.kustomizeLabelWithoutSelector, "kustomize-label-without-selector", false, "Do not apply common label to selectors or templates")
command.Flags().BoolVar(&opts.kustomizeForceCommonLabels, "kustomize-force-common-label", false, "Force common labels in Kustomize")
command.Flags().BoolVar(&opts.kustomizeForceCommonAnnotations, "kustomize-force-common-annotation", false, "Force common annotations in Kustomize")
command.Flags().StringVar(&opts.kustomizeNamespace, "kustomize-namespace", "", "Kustomize namespace")
Expand Down Expand Up @@ -250,6 +252,7 @@ type kustomizeOpts struct {
version string
commonLabels map[string]string
commonAnnotations map[string]string
labelWithoutSelector bool
forceCommonLabels bool
forceCommonAnnotations bool
namespace string
Expand Down Expand Up @@ -277,6 +280,9 @@ func setKustomizeOpt(src *argoappv1.ApplicationSource, opts kustomizeOpts) {
if opts.commonAnnotations != nil {
src.Kustomize.CommonAnnotations = opts.commonAnnotations
}
if opts.labelWithoutSelector {
src.Kustomize.LabelWithoutSelector = opts.labelWithoutSelector
}
if opts.forceCommonLabels {
src.Kustomize.ForceCommonLabels = opts.forceCommonLabels
}
Expand Down Expand Up @@ -651,6 +657,8 @@ func ConstructSource(source *argoappv1.ApplicationSource, appOpts AppOptions, fl
parsedAnnotations, err := label.Parse(appOpts.kustomizeCommonAnnotations)
errors.CheckError(err)
setKustomizeOpt(source, kustomizeOpts{commonAnnotations: parsedAnnotations})
case "kustomize-label-without-selector":
setKustomizeOpt(source, kustomizeOpts{labelWithoutSelector: appOpts.kustomizeLabelWithoutSelector})
case "kustomize-force-common-label":
setKustomizeOpt(source, kustomizeOpts{forceCommonLabels: appOpts.kustomizeForceCommonLabels})
case "kustomize-force-common-annotation":
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 @@ -123,6 +123,11 @@ func Test_setKustomizeOpt(t *testing.T) {
setKustomizeOpt(&src, kustomizeOpts{commonAnnotations: map[string]string{"foo1": "bar1", "foo2": "bar2"}})
assert.Equal(t, &v1alpha1.ApplicationSourceKustomize{CommonAnnotations: map[string]string{"foo1": "bar1", "foo2": "bar2"}}, src.Kustomize)
})
t.Run("Label Without Selector", func(t *testing.T) {
src := v1alpha1.ApplicationSource{}
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)
})
}

func Test_setJsonnetOpt(t *testing.T) {
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 @@ -67,6 +67,7 @@ argocd admin app generate-spec APPNAME [flags]
--kustomize-force-common-annotation Force common annotations in Kustomize
--kustomize-force-common-label Force common labels in Kustomize
--kustomize-image stringArray Kustomize images (e.g. --kustomize-image node:8.15.0 --kustomize-image mysql=mariadb,alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d)
--kustomize-label-without-selector Do not apply common label to selectors or templates
--kustomize-namespace string Kustomize namespace
--kustomize-replica stringArray Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)
--kustomize-version string Kustomize version
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/commands/argocd_app_add-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ argocd app add-source APPNAME [flags]
--kustomize-force-common-annotation Force common annotations in Kustomize
--kustomize-force-common-label Force common labels in Kustomize
--kustomize-image stringArray Kustomize images (e.g. --kustomize-image node:8.15.0 --kustomize-image mysql=mariadb,alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d)
--kustomize-label-without-selector Do not apply common label to selectors or templates
--kustomize-namespace string Kustomize namespace
--kustomize-replica stringArray Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)
--kustomize-version string Kustomize version
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 @@ -65,6 +65,7 @@ argocd app create APPNAME [flags]
--kustomize-force-common-annotation Force common annotations in Kustomize
--kustomize-force-common-label Force common labels in Kustomize
--kustomize-image stringArray Kustomize images (e.g. --kustomize-image node:8.15.0 --kustomize-image mysql=mariadb,alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d)
--kustomize-label-without-selector Do not apply common label to selectors or templates
--kustomize-namespace string Kustomize namespace
--kustomize-replica stringArray Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)
--kustomize-version string Kustomize version
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 @@ -59,6 +59,7 @@ argocd app set APPNAME [flags]
--kustomize-force-common-annotation Force common annotations in Kustomize
--kustomize-force-common-label Force common labels in Kustomize
--kustomize-image stringArray Kustomize images (e.g. --kustomize-image node:8.15.0 --kustomize-image mysql=mariadb,alpine@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d)
--kustomize-label-without-selector Do not apply common label to selectors or templates
--kustomize-namespace string Kustomize namespace
--kustomize-replica stringArray Kustomize replicas (e.g. --kustomize-replica my-development=2 --kustomize-replica my-statefulset=4)
--kustomize-version string Kustomize version
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/kustomize.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The following configuration options are available for Kustomize:
* `images` is a list of Kustomize image overrides
* `replicas` is a list of Kustomize replica overrides
* `commonLabels` is a string map of additional labels
* `labelWithoutSelector` is a boolean value which defines if the common label(s) should be applied to resource selectors and templates.
* `forceCommonLabels` is a boolean value which defines if it's allowed to override existing labels
* `commonAnnotations` is a string map of additional annotations
* `namespace` is a Kubernetes resources namespace
Expand Down
Loading

0 comments on commit 839526e

Please sign in to comment.