@@ -20,9 +20,6 @@ import (
2020 "github.com/pkg/errors"
2121 corev1 "k8s.io/api/core/v1"
2222 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23- "sigs.k8s.io/controller-runtime/pkg/client"
24-
25- clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2623)
2724
2825// OwnerGraph contains a graph with all the objects considered by clusterctl move as nodes and the OwnerReference relationship
@@ -61,12 +58,8 @@ func GetOwnerGraph(namespace, kubeconfigPath string) (OwnerGraph, error) {
6158
6259 graph := newObjectGraph (p , invClient )
6360
64- cl , err := p .NewClient ()
65- if err != nil {
66- return OwnerGraph {}, errors .Wrap (err , "failed to create client for ownerGraph" )
67- }
6861 // Gets all the types defined by the CRDs installed by clusterctl plus the ConfigMap/Secret core types.
69- err = graph .getDiscoveryTypes ()
62+ err : = graph .getDiscoveryTypes ()
7063 if err != nil {
7164 return OwnerGraph {}, errors .Wrap (err , "failed to retrieve discovery types" )
7265 }
@@ -78,18 +71,8 @@ func GetOwnerGraph(namespace, kubeconfigPath string) (OwnerGraph, error) {
7871 return OwnerGraph {}, errors .Wrap (err , "failed to discover the object graph" )
7972 }
8073 owners := OwnerGraph {}
81- for _ , v := range graph .uidToNode {
82- // The Discovery function returns all secrets in the Cluster namespace. Ensure a Secret that is not part of the
83- // Cluster is not added to the OwnerGraph.
84- if v .identity .Kind == "Secret" {
85- clusterSecret , err := isClusterSecret (v .identity , cl )
86- if err != nil {
87- return OwnerGraph {}, err
88- }
89- if ! clusterSecret {
90- continue
91- }
92- }
74+ // Using getMoveNodes here ensures only objects that are part of the Cluster are added to the OwnerGraph.
75+ for _ , v := range graph .getMoveNodes () {
9376 n := OwnerGraphNode {Object : v .identity , Owners : []metav1.OwnerReference {}}
9477 for owner , attributes := range v .owners {
9578 n .Owners = append (n .Owners , nodeToOwnerRef (owner , attributes ))
@@ -98,12 +81,3 @@ func GetOwnerGraph(namespace, kubeconfigPath string) (OwnerGraph, error) {
9881 }
9982 return owners , nil
10083}
101-
102- // isClusterSecret checks whether a Secret is related to a CAPI Cluster by checking if the secret type is ClusterSecretType.
103- func isClusterSecret (ref corev1.ObjectReference , c client.Client ) (bool , error ) {
104- s := & corev1.Secret {}
105- if err := c .Get (ctx , client.ObjectKey {Namespace : ref .Namespace , Name : ref .Name }, s ); err != nil {
106- return false , err
107- }
108- return s .Type == clusterv1 .ClusterSecretType , nil
109- }
0 commit comments