From aa8d632b2e75d056e4e796bed0d09c11780fa643 Mon Sep 17 00:00:00 2001 From: Dmitriy Kalinin Date: Wed, 5 Aug 2020 16:55:38 -0400 Subject: [PATCH] move kapp.k14s.io/disable-label-scoping into config --- docs/config.md | 2 +- pkg/kapp/config/default.go | 31 ++++++++++++++++++++++--- pkg/kapp/resources/labeled_resources.go | 21 ++++------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/docs/config.md b/docs/config.md index 3620da14a..37d4292ab 100644 --- a/docs/config.md +++ b/docs/config.md @@ -96,7 +96,7 @@ rebaseRules: #### labelScopingRules -`labelScopingRules` specify locations for inserting kapp generated labels that scope resources to resources within current application. `kapp.k14s.io/disable-label-scoping: ""` (value must be empty) annotation can be used to exclude an individual resource from label scoping. +`labelScopingRules` specify locations for inserting kapp generated labels that scope resources to resources within current application. `kapp.k14s.io/disable-default-label-scoping-rules: ""` (as of v0.33.0+, or use `kapp.k14s.io/disable-label-scoping: ""` in earlier versions) annotation can be used to exclude an individual resource from label scoping. #### waitRules diff --git a/pkg/kapp/config/default.go b/pkg/kapp/config/default.go index 5ed3400fa..df3c2856b 100644 --- a/pkg/kapp/config/default.go +++ b/pkg/kapp/config/default.go @@ -211,14 +211,39 @@ ownershipLabelRules: labelScopingRules: - path: [spec, selector] resourceMatchers: - - apiVersionKindMatcher: {apiVersion: v1, kind: Service} + - andMatcher: + matchers: + - notMatcher: + # Keep older annotation for backwards compatibility + matcher: &disableLabelScopingAnnMatcher + hasAnnotationMatcher: + keys: [kapp.k14s.io/disable-label-scoping] + - notMatcher: + matcher: &disableDefaultLabelScopingRulesAnnMatcher + hasAnnotationMatcher: + keys: [kapp.k14s.io/disable-default-label-scoping-rules] + - apiVersionKindMatcher: {apiVersion: v1, kind: Service} - path: [spec, selector, matchLabels] - resourceMatchers: *withPodTemplate + resourceMatchers: + - andMatcher: + matchers: + - notMatcher: + matcher: *disableLabelScopingAnnMatcher + - notMatcher: + matcher: *disableDefaultLabelScopingRulesAnnMatcher + - anyMatcher: + matchers: *withPodTemplate - path: [spec, selector, matchLabels] resourceMatchers: - - apiVersionKindMatcher: {apiVersion: policy/v1beta1, kind: PodDisruptionBudget} + - andMatcher: + matchers: + - notMatcher: + matcher: *disableLabelScopingAnnMatcher + - notMatcher: + matcher: *disableDefaultLabelScopingRulesAnnMatcher + - apiVersionKindMatcher: {apiVersion: policy/v1beta1, kind: PodDisruptionBudget} templateRules: - resourceMatchers: diff --git a/pkg/kapp/resources/labeled_resources.go b/pkg/kapp/resources/labeled_resources.go index b76475509..14804575d 100644 --- a/pkg/kapp/resources/labeled_resources.go +++ b/pkg/kapp/resources/labeled_resources.go @@ -9,10 +9,6 @@ import ( "k8s.io/apimachinery/pkg/labels" ) -const ( - disableLabelScopingAnnKey = "kapp.k14s.io/disable-label-scoping" // valid value is '' -) - type OwnershipLabelModsFunc func(kvs map[string]string) []StringMapAppendMod type LabelScopingModsFunc func(kvs map[string]string) []StringMapAppendMod @@ -57,19 +53,10 @@ func (a *LabeledResources) Prepare(resources []Resource, olmFunc OwnershipLabelM } } - // Scope labels on all resources except ones that explicitly opt out - disableLSVal, disableLabelScoping := res.Annotations()[disableLabelScopingAnnKey] - if disableLabelScoping { - if disableLSVal != "" { - return fmt.Errorf("Expected annotation '%s' on resource '%s' to have value ''", - disableLabelScopingAnnKey, res.Description()) - } - } else { - for _, t := range lsmFunc(map[string]string{labelKey: labelVal}) { - err := t.Apply(res) - if err != nil { - return err - } + for _, t := range lsmFunc(map[string]string{labelKey: labelVal}) { + err := t.Apply(res) + if err != nil { + return err } } }