Drop uses of 'unstructured' terminology.

This commit is contained in:
monopole
2021-03-13 08:44:01 -08:00
parent 123a5d6e56
commit 235101a614
12 changed files with 84 additions and 272 deletions

View File

@@ -21,16 +21,16 @@ import (
// Factory makes instances of Resource.
type Factory struct {
hasher ifc.KunstructuredHasher
hasher ifc.KustHasher
}
// NewFactory makes an instance of Factory.
func NewFactory(h ifc.KunstructuredHasher) *Factory {
func NewFactory(h ifc.KustHasher) *Factory {
return &Factory{hasher: h}
}
// Hasher returns an ifc.KunstructuredHasher
func (rf *Factory) Hasher() ifc.KunstructuredHasher {
// Hasher returns an ifc.KustHasher
func (rf *Factory) Hasher() ifc.KustHasher {
return rf.hasher
}
@@ -69,7 +69,7 @@ func (rf *Factory) makeOne(rn *yaml.RNode, o *types.GenArgs) *Resource {
if o == nil {
o = types.NewGenArgs(nil)
}
return &Resource{kunStr: rn, options: o}
return &Resource{node: rn, options: o}
}
// SliceFromPatches returns a slice of resources given a patch path

View File

@@ -337,7 +337,7 @@ kind: List
// The error using kyaml is:
// json: unsupported type: map[interface {}]interface {}
// maybe arising from too many conversions between
// yaml, json, Resource, RNode, Unstructured etc.
// yaml, json, Resource, RNode, etc.
// These conversions go away after closing #3506
// TODO(#3271) This shouldn't have an error, but does when kyaml is used.
expectedErr: true,

View File

@@ -21,11 +21,10 @@ import (
"sigs.k8s.io/yaml"
)
// Resource is a representation of a Kubernetes Resource Model (KRM) object
// Resource is an RNode, representing a Kubernetes Resource Model object,
// paired with metadata used by kustomize.
// For more history, see sigs.k8s.io/kustomize/api/ifc.Unstructured
type Resource struct {
kunStr *kyaml.RNode
node *kyaml.RNode
options *types.GenArgs
refBy []resid.ResId
refVarNames []string
@@ -55,15 +54,15 @@ var buildAnnotations = []string{
}
func (r *Resource) AsRNode() *kyaml.RNode {
return r.kunStr.Copy()
return r.node.Copy()
}
func (r *Resource) ResetPrimaryData(incoming *Resource) {
r.kunStr = incoming.kunStr.Copy()
r.node = incoming.node.Copy()
}
func (r *Resource) GetAnnotations() map[string]string {
annotations, err := r.kunStr.GetAnnotations()
annotations, err := r.node.GetAnnotations()
if err != nil || annotations == nil {
return make(map[string]string)
}
@@ -72,19 +71,19 @@ func (r *Resource) GetAnnotations() map[string]string {
func (r *Resource) GetFieldValue(f string) (interface{}, error) {
//nolint:staticcheck
return r.kunStr.GetFieldValue(f)
return r.node.GetFieldValue(f)
}
func (r *Resource) GetDataMap() map[string]string {
return r.kunStr.GetDataMap()
return r.node.GetDataMap()
}
func (r *Resource) GetBinaryDataMap() map[string]string {
return r.kunStr.GetBinaryDataMap()
return r.node.GetBinaryDataMap()
}
func (r *Resource) GetGvk() resid.Gvk {
meta, err := r.kunStr.GetMeta()
meta, err := r.node.GetMeta()
if err != nil {
return resid.GvkFromString("")
}
@@ -92,16 +91,16 @@ func (r *Resource) GetGvk() resid.Gvk {
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) Hash(h ifc.KustHasher) (string, error) {
return h.Hash(r.node)
}
func (r *Resource) GetKind() string {
return r.kunStr.GetKind()
return r.node.GetKind()
}
func (r *Resource) GetLabels() map[string]string {
l, err := r.kunStr.GetLabels()
l, err := r.node.GetLabels()
if err != nil {
return map[string]string{}
}
@@ -109,78 +108,78 @@ func (r *Resource) GetLabels() map[string]string {
}
func (r *Resource) GetName() string {
return r.kunStr.GetName()
return r.node.GetName()
}
func (r *Resource) GetSlice(p string) ([]interface{}, error) {
//nolint:staticcheck
return r.kunStr.GetSlice(p)
return r.node.GetSlice(p)
}
func (r *Resource) GetString(p string) (string, error) {
//nolint:staticcheck
return r.kunStr.GetString(p)
return r.node.GetString(p)
}
func (r *Resource) IsEmpty() bool {
return r.kunStr.IsNilOrEmpty()
return r.node.IsNilOrEmpty()
}
func (r *Resource) Map() (map[string]interface{}, error) {
return r.kunStr.Map()
return r.node.Map()
}
func (r *Resource) MarshalJSON() ([]byte, error) {
return r.kunStr.MarshalJSON()
return r.node.MarshalJSON()
}
func (r *Resource) MatchesLabelSelector(selector string) (bool, error) {
return r.kunStr.MatchesLabelSelector(selector)
return r.node.MatchesLabelSelector(selector)
}
func (r *Resource) MatchesAnnotationSelector(selector string) (bool, error) {
return r.kunStr.MatchesAnnotationSelector(selector)
return r.node.MatchesAnnotationSelector(selector)
}
func (r *Resource) SetAnnotations(m map[string]string) {
if len(m) == 0 {
// Force field erasure.
r.kunStr.SetAnnotations(nil)
r.node.SetAnnotations(nil)
return
}
r.kunStr.SetAnnotations(m)
r.node.SetAnnotations(m)
}
func (r *Resource) SetDataMap(m map[string]string) {
r.kunStr.SetDataMap(m)
r.node.SetDataMap(m)
}
func (r *Resource) SetBinaryDataMap(m map[string]string) {
r.kunStr.SetBinaryDataMap(m)
r.node.SetBinaryDataMap(m)
}
func (r *Resource) SetGvk(gvk resid.Gvk) {
r.kunStr.SetMapField(
r.node.SetMapField(
kyaml.NewScalarRNode(gvk.Kind), kyaml.KindField)
r.kunStr.SetMapField(
r.node.SetMapField(
kyaml.NewScalarRNode(gvk.ApiVersion()), kyaml.APIVersionField)
}
func (r *Resource) SetLabels(m map[string]string) {
if len(m) == 0 {
// Force field erasure.
r.kunStr.SetLabels(nil)
r.node.SetLabels(nil)
return
}
r.kunStr.SetLabels(m)
r.node.SetLabels(m)
}
func (r *Resource) SetName(n string) {
r.kunStr.SetName(n)
r.node.SetName(n)
}
func (r *Resource) SetNamespace(n string) {
r.kunStr.SetNamespace(n)
r.node.SetNamespace(n)
}
func (r *Resource) SetKind(k string) {
@@ -190,7 +189,7 @@ func (r *Resource) SetKind(k string) {
}
func (r *Resource) UnmarshalJSON(s []byte) error {
return r.kunStr.UnmarshalJSON(s)
return r.node.UnmarshalJSON(s)
}
// ResCtx is an interface describing the contextual added
@@ -210,14 +209,14 @@ type ResCtxMatcher func(ResCtx) bool
// DeepCopy returns a new copy of resource
func (r *Resource) DeepCopy() *Resource {
rc := &Resource{
kunStr: r.kunStr.Copy(),
node: r.node.Copy(),
}
rc.copyOtherFields(r)
return rc
}
// CopyMergeMetaDataFields copies everything but the non-metadata in
// the ifc.Kunstructured map, merging labels and annotations.
// the resource.
func (r *Resource) CopyMergeMetaDataFieldsFrom(other *Resource) {
r.SetLabels(mergeStringMaps(other.GetLabels(), r.GetLabels()))
r.SetAnnotations(
@@ -283,8 +282,10 @@ func (r *Resource) ReferencesEqual(other *Resource) bool {
return len(setSelf) == len(setOther)
}
func (r *Resource) KunstructEqual(o *Resource) bool {
return reflect.DeepEqual(r.kunStr, o.kunStr)
// NodeEqual returns true if the resource's nodes are
// equal, ignoring ancillary information like genargs, refby, etc.
func (r *Resource) NodeEqual(o *Resource) bool {
return reflect.DeepEqual(r.node, o.node)
}
func (r *Resource) copyRefBy() []resid.ResId {
@@ -572,10 +573,10 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
}
func (r *Resource) ApplyFilter(f kio.Filter) error {
l, err := f.Filter([]*kyaml.RNode{r.kunStr})
l, err := f.Filter([]*kyaml.RNode{r.node})
if len(l) == 0 {
// The node was deleted. The following makes r.IsEmpty() true.
r.kunStr = nil
r.node = nil
}
return err
}