@@ -20,9 +20,6 @@ import (
20
20
"github.com/pkg/errors"
21
21
corev1 "k8s.io/api/core/v1"
22
22
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"
26
23
)
27
24
28
25
// 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) {
61
58
62
59
graph := newObjectGraph (p , invClient )
63
60
64
- cl , err := p .NewClient ()
65
- if err != nil {
66
- return OwnerGraph {}, errors .Wrap (err , "failed to create client for ownerGraph" )
67
- }
68
61
// 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 ()
70
63
if err != nil {
71
64
return OwnerGraph {}, errors .Wrap (err , "failed to retrieve discovery types" )
72
65
}
@@ -78,18 +71,8 @@ func GetOwnerGraph(namespace, kubeconfigPath string) (OwnerGraph, error) {
78
71
return OwnerGraph {}, errors .Wrap (err , "failed to discover the object graph" )
79
72
}
80
73
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 () {
93
76
n := OwnerGraphNode {Object : v .identity , Owners : []metav1.OwnerReference {}}
94
77
for owner , attributes := range v .owners {
95
78
n .Owners = append (n .Owners , nodeToOwnerRef (owner , attributes ))
@@ -98,12 +81,3 @@ func GetOwnerGraph(namespace, kubeconfigPath string) (OwnerGraph, error) {
98
81
}
99
82
return owners , nil
100
83
}
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