mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
Enable using kyaml namespace transformer in builtin plugin
This commit is contained in:
@@ -6,6 +6,8 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
"sigs.k8s.io/kustomize/api/transform"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
@@ -19,6 +21,10 @@ import (
|
|||||||
type NamespaceTransformerPlugin struct {
|
type NamespaceTransformerPlugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
|
|
||||||
|
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
||||||
|
// kunstruct transformer
|
||||||
|
YAMLSupport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *NamespaceTransformerPlugin) Config(
|
func (p *NamespaceTransformerPlugin) Config(
|
||||||
@@ -39,12 +45,25 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := r.OrgId()
|
id := r.OrgId()
|
||||||
applicableFs := p.applicableFieldSpecs(id)
|
|
||||||
|
|
||||||
for _, fs := range applicableFs {
|
if !p.YAMLSupport {
|
||||||
err := transform.MutateField(
|
// use the old style transform
|
||||||
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
applicableFs := p.applicableFieldSpecs(id)
|
||||||
p.changeNamespace(r))
|
|
||||||
|
for _, fs := range applicableFs {
|
||||||
|
err := transform.MutateField(
|
||||||
|
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
||||||
|
p.changeNamespace(r))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// use the new style transform
|
||||||
|
err := filtersutil.ApplyToJSON(namespace.Filter{
|
||||||
|
Namespace: p.Namespace,
|
||||||
|
FsSlice: p.FieldSpecs,
|
||||||
|
}, r.Kunstructured)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||||
"sigs.k8s.io/kustomize/api/transform"
|
"sigs.k8s.io/kustomize/api/transform"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
@@ -20,6 +22,10 @@ import (
|
|||||||
type plugin struct {
|
type plugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
|
|
||||||
|
// YAMLSupport can be set to true to use the kyaml filter instead of the
|
||||||
|
// kunstruct transformer
|
||||||
|
YAMLSupport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
@@ -43,12 +49,25 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
id := r.OrgId()
|
id := r.OrgId()
|
||||||
applicableFs := p.applicableFieldSpecs(id)
|
|
||||||
|
|
||||||
for _, fs := range applicableFs {
|
if !p.YAMLSupport {
|
||||||
err := transform.MutateField(
|
// use the old style transform
|
||||||
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
applicableFs := p.applicableFieldSpecs(id)
|
||||||
p.changeNamespace(r))
|
|
||||||
|
for _, fs := range applicableFs {
|
||||||
|
err := transform.MutateField(
|
||||||
|
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
||||||
|
p.changeNamespace(r))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// use the new style transform
|
||||||
|
err := filtersutil.ApplyToJSON(namespace.Filter{
|
||||||
|
Namespace: p.Namespace,
|
||||||
|
FsSlice: p.FieldSpecs,
|
||||||
|
}, r.Kunstructured)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user