Skip to content

Commit f17502a

Browse files
authored
Merge pull request #7976 from killianmuldoon/fix-ownerRef-secrets
🐛 Use tenancy as filter in ownerReference test
2 parents 7573e94 + dd50972 commit f17502a

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

cmd/clusterctl/client/cluster/ownergraph.go

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

test/framework/ownerreference_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ var KubernetesReferenceAssertions = map[string]func([]metav1.OwnerReference) err
177177
},
178178
configMapKind: func(owners []metav1.OwnerReference) error {
179179
// The only configMaps considered here are those owned by a ClusterResourceSet.
180-
return hasOneOfExactOwnersByGVK(owners, []schema.GroupVersionKind{clusterResourceSetGVK}, []schema.GroupVersionKind{})
180+
return hasOneOfExactOwnersByGVK(owners, []schema.GroupVersionKind{clusterResourceSetGVK})
181181
},
182182
}
183183

0 commit comments

Comments
 (0)