mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
remove hard coded pathconfig
This commit is contained in:
@@ -21,29 +21,30 @@ import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformerconfig"
|
||||
)
|
||||
|
||||
// mapTransformer contains a map string->string and path configs
|
||||
// The map will be applied to the fields specified in path configs.
|
||||
type mapTransformer struct {
|
||||
m map[string]string
|
||||
pathConfigs []PathConfig
|
||||
pathConfigs []transformerconfig.PathConfig
|
||||
}
|
||||
|
||||
var _ Transformer = &mapTransformer{}
|
||||
|
||||
// NewDefaultingLabelsMapTransformer construct a mapTransformer with defaultLabelsPathConfigs.
|
||||
func NewDefaultingLabelsMapTransformer(m map[string]string) (Transformer, error) {
|
||||
return NewMapTransformer(defaultLabelsPathConfigs, m)
|
||||
// NewLabelsMapTransformer construct a mapTransformer with a given pathConfig slice
|
||||
func NewLabelsMapTransformer(m map[string]string, p []transformerconfig.PathConfig) (Transformer, error) {
|
||||
return NewMapTransformer(p, m)
|
||||
}
|
||||
|
||||
// NewDefaultingAnnotationsMapTransformer construct a mapTransformer with defaultAnnotationsPathConfigs.
|
||||
func NewDefaultingAnnotationsMapTransformer(m map[string]string) (Transformer, error) {
|
||||
return NewMapTransformer(defaultAnnotationsPathConfigs, m)
|
||||
// NewAnnotationsMapTransformer construct a mapTransformer with a given pathConfig slice
|
||||
func NewAnnotationsMapTransformer(m map[string]string, p []transformerconfig.PathConfig) (Transformer, error) {
|
||||
return NewMapTransformer(p, m)
|
||||
}
|
||||
|
||||
// NewMapTransformer construct a mapTransformer.
|
||||
func NewMapTransformer(pc []PathConfig, m map[string]string) (Transformer, error) {
|
||||
func NewMapTransformer(pc []transformerconfig.PathConfig, m map[string]string) (Transformer, error) {
|
||||
if m == nil {
|
||||
return NewNoOpTransformer(), nil
|
||||
}
|
||||
@@ -59,10 +60,10 @@ func (o *mapTransformer) Transform(m resmap.ResMap) error {
|
||||
for id := range m {
|
||||
objMap := m[id].UnstructuredContent()
|
||||
for _, path := range o.pathConfigs {
|
||||
if !id.Gvk().IsSelected(path.GroupVersionKind) {
|
||||
if !id.Gvk().IsSelected(&path.Gvk) {
|
||||
continue
|
||||
}
|
||||
err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addMap)
|
||||
err := mutateField(objMap, path.PathSlice(), path.CreateIfNotPresent, o.addMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user