mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 09:49:13 +00:00
Remove the wrappy layer.
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/wrappy"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resid"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
@@ -26,7 +25,7 @@ import (
|
||||
// paired with metadata used by kustomize.
|
||||
// For more history, see sigs.k8s.io/kustomize/api/ifc.Unstructured
|
||||
type Resource struct {
|
||||
kunStr ifc.Kunstructured
|
||||
kunStr *kyaml.RNode
|
||||
options *types.GenArgs
|
||||
refBy []resid.ResId
|
||||
refVarNames []string
|
||||
@@ -55,23 +54,24 @@ var buildAnnotations = []string{
|
||||
buildAnnotationAllowKindChange,
|
||||
}
|
||||
|
||||
func (r *Resource) AsRNode() *kyaml.RNode {
|
||||
return r.kunStr.Copy()
|
||||
}
|
||||
|
||||
func (r *Resource) ResetPrimaryData(incoming *Resource) {
|
||||
r.kunStr = incoming.Copy()
|
||||
r.kunStr = incoming.kunStr.Copy()
|
||||
}
|
||||
|
||||
func (r *Resource) GetAnnotations() map[string]string {
|
||||
annotations := r.kunStr.GetAnnotations()
|
||||
if annotations == nil {
|
||||
annotations, err := r.kunStr.GetAnnotations()
|
||||
if err != nil || annotations == nil {
|
||||
return make(map[string]string)
|
||||
}
|
||||
return annotations
|
||||
}
|
||||
|
||||
func (r *Resource) Copy() ifc.Kunstructured {
|
||||
return r.kunStr.Copy()
|
||||
}
|
||||
|
||||
func (r *Resource) GetFieldValue(f string) (interface{}, error) {
|
||||
//nolint:staticcheck
|
||||
return r.kunStr.GetFieldValue(f)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,16 @@ func (r *Resource) GetBinaryDataMap() map[string]string {
|
||||
}
|
||||
|
||||
func (r *Resource) GetGvk() resid.Gvk {
|
||||
return r.kunStr.GetGvk()
|
||||
meta, err := r.kunStr.GetMeta()
|
||||
if err != nil {
|
||||
return resid.GvkFromString("")
|
||||
}
|
||||
g, v := resid.ParseGroupVersion(meta.APIVersion)
|
||||
return resid.Gvk{Group: g, Version: v, Kind: meta.Kind}
|
||||
}
|
||||
|
||||
func (r *Resource) Hash(h ifc.KunstructuredHasher) (string, error) {
|
||||
return h.Hash(r.kunStr)
|
||||
}
|
||||
|
||||
func (r *Resource) GetKind() string {
|
||||
@@ -92,7 +101,11 @@ func (r *Resource) GetKind() string {
|
||||
}
|
||||
|
||||
func (r *Resource) GetLabels() map[string]string {
|
||||
return r.kunStr.GetLabels()
|
||||
l, err := r.kunStr.GetLabels()
|
||||
if err != nil {
|
||||
return map[string]string{}
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (r *Resource) GetName() string {
|
||||
@@ -100,16 +113,17 @@ func (r *Resource) GetName() string {
|
||||
}
|
||||
|
||||
func (r *Resource) GetSlice(p string) ([]interface{}, error) {
|
||||
//nolint:staticcheck
|
||||
return r.kunStr.GetSlice(p)
|
||||
}
|
||||
|
||||
func (r *Resource) GetString(p string) (string, error) {
|
||||
//nolint:staticcheck
|
||||
return r.kunStr.GetString(p)
|
||||
}
|
||||
|
||||
func (r *Resource) IsEmpty() (bool, error) {
|
||||
m, err := r.kunStr.Map()
|
||||
return len(m) == 0, err
|
||||
func (r *Resource) IsEmpty() bool {
|
||||
return r.kunStr.IsNilOrEmpty()
|
||||
}
|
||||
|
||||
func (r *Resource) Map() (map[string]interface{}, error) {
|
||||
@@ -146,7 +160,10 @@ func (r *Resource) SetBinaryDataMap(m map[string]string) {
|
||||
}
|
||||
|
||||
func (r *Resource) SetGvk(gvk resid.Gvk) {
|
||||
r.kunStr.SetGvk(gvk)
|
||||
r.kunStr.SetMapField(
|
||||
kyaml.NewScalarRNode(gvk.Kind), kyaml.KindField)
|
||||
r.kunStr.SetMapField(
|
||||
kyaml.NewScalarRNode(gvk.ApiVersion()), kyaml.APIVersionField)
|
||||
}
|
||||
|
||||
func (r *Resource) SetLabels(m map[string]string) {
|
||||
@@ -193,7 +210,7 @@ type ResCtxMatcher func(ResCtx) bool
|
||||
// DeepCopy returns a new copy of resource
|
||||
func (r *Resource) DeepCopy() *Resource {
|
||||
rc := &Resource{
|
||||
kunStr: r.Copy(),
|
||||
kunStr: r.kunStr.Copy(),
|
||||
}
|
||||
rc.copyOtherFields(r)
|
||||
return rc
|
||||
@@ -541,11 +558,7 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
empty, err := r.IsEmpty()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if empty {
|
||||
if r.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
if !patch.KindChangeAllowed() {
|
||||
@@ -559,15 +572,12 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
|
||||
}
|
||||
|
||||
func (r *Resource) ApplyFilter(f kio.Filter) error {
|
||||
if wn, ok := r.kunStr.(*wrappy.WNode); ok {
|
||||
l, err := f.Filter([]*kyaml.RNode{wn.AsRNode()})
|
||||
if len(l) == 0 {
|
||||
// Hack to deal with deletion.
|
||||
r.kunStr = wrappy.NewWNode()
|
||||
}
|
||||
return err
|
||||
l, err := f.Filter([]*kyaml.RNode{r.kunStr})
|
||||
if len(l) == 0 {
|
||||
// The node was deleted. The following makes r.IsEmpty() true.
|
||||
r.kunStr = nil
|
||||
}
|
||||
return filtersutil.ApplyToJSON(f, r)
|
||||
return err
|
||||
}
|
||||
|
||||
func mergeStringMaps(maps ...map[string]string) map[string]string {
|
||||
|
||||
Reference in New Issue
Block a user