mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 05:35:47 +00:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// +build plugin
|
|
|
|
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//go:generate go run sigs.k8s.io/kustomize/cmd/pluginator
|
|
package main
|
|
|
|
import (
|
|
"sigs.k8s.io/kustomize/pkg/ifc"
|
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
|
"sigs.k8s.io/kustomize/pkg/transformers"
|
|
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
// Add the given prefix and suffix to the resource name.
|
|
type plugin struct {
|
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
|
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
|
|
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
|
}
|
|
|
|
var KustomizePlugin plugin
|
|
|
|
func (p *plugin) Config(
|
|
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
|
|
p.Prefix = ""
|
|
p.Suffix = ""
|
|
p.FieldSpecs = nil
|
|
return yaml.Unmarshal(c, p)
|
|
}
|
|
|
|
func (p *plugin) Transform(m resmap.ResMap) error {
|
|
t, err := transformers.NewNamePrefixSuffixTransformer(
|
|
p.Prefix,
|
|
p.Suffix,
|
|
p.FieldSpecs,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return t.Transform(m)
|
|
}
|