@@ -3,6 +3,7 @@ package forest
33import (
44 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
55 "k8s.io/apimachinery/pkg/runtime/schema"
6+ "k8s.io/apimachinery/pkg/types"
67)
78
89// SetSourceObject updates or creates the source object in forest.namespace.
@@ -35,11 +36,11 @@ func (ns *Namespace) DeleteSourceObject(gvk schema.GroupVersionKind, nm string)
3536 }
3637}
3738
38- // GetSourceObjects returns all source objects in the namespace.
39- func (ns * Namespace ) GetSourceObjects (gvk schema.GroupVersionKind ) []* unstructured. Unstructured {
40- o := []* unstructured. Unstructured {}
39+ // GetSourceNames returns all source objects in the namespace.
40+ func (ns * Namespace ) GetSourceNames (gvk schema.GroupVersionKind ) []types. NamespacedName {
41+ o := []types. NamespacedName {}
4142 for _ , obj := range ns .sourceObjects [gvk ] {
42- o = append (o , obj )
43+ o = append (o , types. NamespacedName { Name : obj . GetName (), Namespace : obj . GetNamespace ()} )
4344 }
4445 return o
4546}
@@ -50,10 +51,10 @@ func (ns *Namespace) GetNumSourceObjects(gvk schema.GroupVersionKind) int {
5051 return len (ns .sourceObjects [gvk ])
5152}
5253
53- // GetAncestorSourceObjects returns all source objects with the specified name
54+ // GetAncestorSourceNames returns all source objects with the specified name
5455// in the ancestors (including itself) from top down. If the name is not
5556// specified, all the source objects in the ancestors will be returned.
56- func (ns * Namespace ) GetAncestorSourceObjects (gvk schema.GroupVersionKind , name string ) []* unstructured. Unstructured {
57+ func (ns * Namespace ) GetAncestorSourceNames (gvk schema.GroupVersionKind , name string ) []types. NamespacedName {
5758 // The namespace could be nil when we use this function on "ns.Parent()" to
5859 // get the source objects of the ancestors excluding itself without caring if
5960 // the "ns.Parent()" is nil.
@@ -62,22 +63,22 @@ func (ns *Namespace) GetAncestorSourceObjects(gvk schema.GroupVersionKind, name
6263 }
6364
6465 // Get the source objects in the ancestors from top down.
65- objs := []* unstructured. Unstructured {}
66- ans := ns .AncestryNames ()
67- for _ , n := range ans {
68- nsObjs := ns .forest .Get (n ). GetSourceObjects (gvk )
66+ allNNMs := []types. NamespacedName {}
67+ ancs := ns .AncestryNames ()
68+ for _ , anc := range ancs {
69+ nnms := ns .forest .Get (anc ). GetSourceNames (gvk )
6970 if name == "" {
7071 // Get all the source objects if the name is not specified.
71- objs = append (objs , ns . forest . Get ( n ). GetSourceObjects ( gvk ) ... )
72+ allNNMs = append (allNNMs , nnms ... )
7273 } else {
7374 // If a name is specified, return the matching objects.
74- for _ , o := range nsObjs {
75- if o .GetName () == name {
76- objs = append (objs , o )
75+ for _ , o := range nnms {
76+ if o .Name == name {
77+ allNNMs = append (allNNMs , o )
7778 }
7879 }
7980 }
8081 }
8182
82- return objs
83+ return allNNMs
8384}
0 commit comments