mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
41 lines
1009 B
Go
41 lines
1009 B
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//go:generate pluginator
|
|
package main
|
|
|
|
import (
|
|
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
|
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
// Add the given annotations to the given field specifications.
|
|
type plugin struct {
|
|
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
|
|
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
|
}
|
|
|
|
//noinspection GoUnusedGlobalVariable
|
|
var KustomizePlugin plugin
|
|
|
|
func (p *plugin) Config(
|
|
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
|
|
p.Annotations = nil
|
|
p.FieldSpecs = nil
|
|
return yaml.Unmarshal(c, p)
|
|
}
|
|
|
|
func (p *plugin) Transform(m resmap.ResMap) error {
|
|
t, err := transformers.NewMapTransformer(
|
|
p.FieldSpecs,
|
|
p.Annotations,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return t.Transform(m)
|
|
}
|