mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Removing YAMLSupport==false code path.
This continues work on the master and v3.8.* branches to eliminate apimachinery dependence.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
@@ -21,8 +22,6 @@ type plugin struct {
|
||||
loadedPatches []*resource.Resource
|
||||
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
|
||||
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
||||
|
||||
YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"`
|
||||
}
|
||||
|
||||
//noinspection GoUnusedGlobalVariable
|
||||
@@ -35,11 +34,6 @@ func (p *plugin) Config(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !strings.Contains(string(c), "yamlSupport") {
|
||||
// If not explicitly denied,
|
||||
// activate kyaml-based transformation.
|
||||
p.YAMLSupport = true
|
||||
}
|
||||
if len(p.Paths) == 0 && p.Patches == "" {
|
||||
return fmt.Errorf("empty file path and empty patch content")
|
||||
}
|
||||
@@ -83,24 +77,34 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !p.YAMLSupport {
|
||||
err = target.Patch(patch.Copy())
|
||||
} else {
|
||||
patchCopy := patch.DeepCopy()
|
||||
patchCopy.SetName(target.GetName())
|
||||
patchCopy.SetNamespace(target.GetNamespace())
|
||||
patchCopy.SetGvk(target.GetGvk())
|
||||
node, err := filtersutil.GetRNode(patchCopy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||
Patch: node,
|
||||
}, target)
|
||||
}
|
||||
patchCopy := patch.DeepCopy()
|
||||
patchCopy.SetName(target.GetName())
|
||||
patchCopy.SetNamespace(target.GetNamespace())
|
||||
patchCopy.SetGvk(target.GetGvk())
|
||||
node, err := filtersutil.GetRNode(patchCopy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||
Patch: node,
|
||||
}, target)
|
||||
if err != nil {
|
||||
// Check for an error string from UnmarshalJSON that's indicative
|
||||
// of an object that's missing basic KRM fields, and thus may have been
|
||||
// entirely deleted (an acceptable outcome). This error handling should
|
||||
// be deleted along with use of ResMap and apimachinery functions like
|
||||
// UnmarshalJSON.
|
||||
if !strings.Contains(err.Error(), "Object 'Kind' is missing") {
|
||||
// Some unknown error, let it through.
|
||||
return err
|
||||
}
|
||||
if len(target.Map()) != 0 {
|
||||
return errors.Wrapf(
|
||||
err, "with unexpectedly non-empty object map of size %d",
|
||||
len(target.Map()))
|
||||
}
|
||||
// Fall through to handle deleted object.
|
||||
}
|
||||
if len(target.Map()) == 0 {
|
||||
// This means all fields have been removed from the object.
|
||||
// This can happen if a patch required deletion of the
|
||||
|
||||
Reference in New Issue
Block a user