| 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/annotations" |
| 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 annotations to the given field specifications. |
| 15 |
type plugin struct { |
| 16 |
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,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.Annotations = 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.Annotations) == 0 { |
| 31 |
return nil |
| 32 |
} |
| 33 |
return m.ApplyFilter(annotations.Filter{ |
| 34 |
Annotations: p.Annotations, |
| 35 |
FsSlice: p.FieldSpecs, |
| 36 |
}) |
| 37 |
} |