Skip to content

Commit

Permalink
move kapp.k14s.io/disable-label-scoping into config
Browse files Browse the repository at this point in the history
  • Loading branch information
cppforlife committed Aug 5, 2020
1 parent 88c952d commit aa8d632
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 28 additions & 3 deletions pkg/kapp/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 4 additions & 17 deletions pkg/kapp/resources/labeled_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit aa8d632

Please sign in to comment.