Debian Codegraph @

plugin/builtin/labeltransformer/LabelTransformer.go

raw
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 //go:generate pluginator
5 package main
6
7 import (
8 "sigs.k8s.io/kustomize/api/filters/labels"
9 "sigs.k8s.io/kustomize/api/resmap"
10 "sigs.k8s.io/kustomize/api/types"
11 "sigs.k8s.io/yaml"
12 )
13
14 // Add the given labels to the given field specifications.
15 type plugin struct {
16 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
17 FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
18 }
19
20 var KustomizePlugin plugin //nolint:gochecknoglobals
21
22 func (p *plugin) Config(
23 _ *resmap.PluginHelpers, c []byte) (err error) {
24 p.Labels = nil
25 p.FieldSpecs = nil
26 return yaml.Unmarshal(c, p)
27 }
28
29 func (p *plugin) Transform(m resmap.ResMap) error {
30 if len(p.Labels) == 0 {
31 return nil
32 }
33 return m.ApplyFilter(labels.Filter{
34 Labels: p.Labels,
35 FsSlice: p.FieldSpecs,
36 })
37 }