Skip to content

Commit

Permalink
TransformerConfig: Update label and annotation transformer (6/6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrette committed Sep 6, 2019
1 parent d781feb commit e8d0435
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/transformers/labelsandannotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"

"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
)
Expand Down Expand Up @@ -60,10 +61,10 @@ func NewMapTransformer(
// fields specified in mapTransformer.
func (o *mapTransformer) Transform(m resmap.ResMap) error {
for _, r := range m.Resources() {
for _, path := range o.fieldSpecs {
if !r.OrgId().IsSelected(&path.Gvk) {
continue
}
id := r.OrgId()
applicableFs := o.applicableFieldSpecs(id)

for _, path := range applicableFs {
err := MutateField(
r.Map(), path.PathSlice(),
path.CreateIfNotPresent, o.addMap)
Expand All @@ -75,6 +76,12 @@ func (o *mapTransformer) Transform(m resmap.ResMap) error {
return nil
}

func (o *mapTransformer) applicableFieldSpecs(id resid.ResId) config.FieldSpecs {
res := config.NewFieldSpecsFromSlice(o.fieldSpecs)
res = res.ApplicableFieldSpecs(id.Gvk)
return res
}

func (o *mapTransformer) addMap(in interface{}) (interface{}, error) {
m, ok := in.(map[string]interface{})
if in == nil {
Expand Down

0 comments on commit e8d0435

Please sign in to comment.