...
1
2
3
4 package builtins
5
6 import (
7 "sigs.k8s.io/kustomize/api/filters/labels"
8 "sigs.k8s.io/kustomize/api/resmap"
9 "sigs.k8s.io/kustomize/api/types"
10 "sigs.k8s.io/yaml"
11 )
12
13
14 type LabelTransformerPlugin struct {
15 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
16 FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
17 }
18
19 func (p *LabelTransformerPlugin) Config(
20 _ *resmap.PluginHelpers, c []byte) (err error) {
21 p.Labels = nil
22 p.FieldSpecs = nil
23 return yaml.Unmarshal(c, p)
24 }
25
26 func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
27 if len(p.Labels) == 0 {
28 return nil
29 }
30 return m.ApplyFilter(labels.Filter{
31 Labels: p.Labels,
32 FsSlice: p.FieldSpecs,
33 })
34 }
35
36 func NewLabelTransformerPlugin() resmap.TransformerPlugin {
37 return &LabelTransformerPlugin{}
38 }
39
View as plain text