mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Merge pull request #1355 from Liujingfang1/patch
enable extended patch transformer and add tests
This commit is contained in:
1147
pkg/target/extendedpatch_test.go
Normal file
1147
pkg/target/extendedpatch_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -64,6 +64,7 @@ func (kt *KustTarget) configureBuiltinTransformers(
|
||||
// - patch SMP
|
||||
configurators := []transformerConfigurator{
|
||||
kt.configureBuiltinPatchStrategicMergeTransformer,
|
||||
kt.configureBuiltinPatchTransformer,
|
||||
kt.configureBuiltinNamespaceTransformer,
|
||||
kt.configureBuiltinNameTransformer,
|
||||
kt.configureBuiltinLabelTransformer,
|
||||
@@ -170,7 +171,6 @@ func (kt *KustTarget) configureBuiltinPatchStrategicMergeTransformer(
|
||||
tConfig *config.TransformerConfig) (
|
||||
result []transformers.Transformer, err error) {
|
||||
if len(kt.kustomization.PatchesStrategicMerge) == 0 {
|
||||
result = append(result, transformers.NewNoOpTransformer())
|
||||
return
|
||||
}
|
||||
var c struct {
|
||||
@@ -188,6 +188,31 @@ func (kt *KustTarget) configureBuiltinPatchStrategicMergeTransformer(
|
||||
return
|
||||
}
|
||||
|
||||
func (kt *KustTarget) configureBuiltinPatchTransformer(
|
||||
tConfig *config.TransformerConfig) (
|
||||
result []transformers.Transformer, err error) {
|
||||
if len(kt.kustomization.Patches) == 0 {
|
||||
return
|
||||
}
|
||||
var c struct {
|
||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
|
||||
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
|
||||
}
|
||||
for _, patch := range kt.kustomization.Patches {
|
||||
c.Target = &patch.Target
|
||||
c.Patch = patch.Patch
|
||||
c.Path = patch.Path
|
||||
p := builtin.NewPatchTransformerPlugin()
|
||||
err = kt.configureBuiltinPlugin(p, c, "patch")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = append(result, p)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (kt *KustTarget) configureBuiltinLabelTransformer(
|
||||
tConfig *config.TransformerConfig) (
|
||||
result []transformers.Transformer, err error) {
|
||||
|
||||
@@ -200,7 +200,6 @@ func (k *Kustomization) EnforceFields() []string {
|
||||
// new field names.
|
||||
func FixKustomizationPreUnmarshalling(data []byte) []byte {
|
||||
deprecateFieldsMap := map[string]string{
|
||||
"patches:": "patchesStrategicMerge:",
|
||||
"imageTags:": "images:",
|
||||
}
|
||||
for oldname, newname := range deprecateFieldsMap {
|
||||
|
||||
@@ -114,10 +114,11 @@ func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
}
|
||||
}
|
||||
if p.loadedPatch != nil {
|
||||
p.loadedPatch.SetName(resource.GetName())
|
||||
p.loadedPatch.SetNamespace(resource.GetNamespace())
|
||||
p.loadedPatch.SetGvk(resource.GetGvk())
|
||||
err = resource.Patch(p.loadedPatch.Kunstructured)
|
||||
patchCopy := p.loadedPatch.DeepCopy()
|
||||
patchCopy.SetName(resource.GetName())
|
||||
patchCopy.SetNamespace(resource.GetNamespace())
|
||||
patchCopy.SetGvk(resource.GetGvk())
|
||||
err = resource.Patch(patchCopy.Kunstructured)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -115,10 +115,11 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
}
|
||||
}
|
||||
if p.loadedPatch != nil {
|
||||
p.loadedPatch.SetName(resource.GetName())
|
||||
p.loadedPatch.SetNamespace(resource.GetNamespace())
|
||||
p.loadedPatch.SetGvk(resource.GetGvk())
|
||||
err = resource.Patch(p.loadedPatch.Kunstructured)
|
||||
patchCopy := p.loadedPatch.DeepCopy()
|
||||
patchCopy.SetName(resource.GetName())
|
||||
patchCopy.SetNamespace(resource.GetNamespace())
|
||||
patchCopy.SetGvk(resource.GetGvk())
|
||||
err = resource.Patch(patchCopy.Kunstructured)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user