Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 175bb33

Browse files
committed
Fix lint
Signed-off-by: Jonathan Ogilvie <[email protected]>
1 parent 58363ad commit 175bb33

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

pkg/cache/cluster.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,13 +1119,13 @@ func buildGraph(nsNodes map[kube.ResourceKey]*Resource, allResources map[kube.Re
11191119
// Try same-namespace lookup first (preserves existing behavior)
11201120
sameNSKey := kube.ResourceKey{Group: group.Group, Kind: ownerRef.Kind, Namespace: childNode.Ref.Namespace, Name: ownerRef.Name}
11211121
graphKeyNode, ok := nsNodes[sameNSKey]
1122-
1122+
11231123
// If not found and we have cross-namespace capabilities, try cluster-scoped lookup
11241124
if !ok && allResources != nil {
11251125
clusterScopedKey := kube.ResourceKey{Group: group.Group, Kind: ownerRef.Kind, Namespace: "", Name: ownerRef.Name}
11261126
graphKeyNode, ok = allResources[clusterScopedKey]
11271127
}
1128-
1128+
11291129
if !ok {
11301130
// No resource found with the given graph key, so move on.
11311131
continue
@@ -1147,7 +1147,7 @@ func buildGraph(nsNodes map[kube.ResourceKey]*Resource, allResources map[kube.Re
11471147
}
11481148
}
11491149
}
1150-
1150+
11511151
if ok {
11521152
for _, uidNode := range uidNodes {
11531153
// Update the graph for this owner to include the child.
@@ -1170,33 +1170,31 @@ func buildGraph(nsNodes map[kube.ResourceKey]*Resource, allResources map[kube.Re
11701170
}
11711171
}
11721172
}
1173-
1173+
11741174
// Second pass: process cross-namespace children if allResources is provided
1175-
if allResources != nil {
1176-
for _, childNode := range allResources {
1177-
// Skip if already processed in the current namespace
1178-
if _, exists := nsNodes[childNode.ResourceKey()]; exists {
1175+
for _, childNode := range allResources {
1176+
// Skip if already processed in the current namespace
1177+
if _, exists := nsNodes[childNode.ResourceKey()]; exists {
1178+
continue
1179+
}
1180+
1181+
// Check if this child has a parent in the current namespace
1182+
for _, ownerRef := range childNode.OwnerRefs {
1183+
group, err := schema.ParseGroupVersion(ownerRef.APIVersion)
1184+
if err != nil {
11791185
continue
11801186
}
1181-
1182-
// Check if this child has a parent in the current namespace
1183-
for _, ownerRef := range childNode.OwnerRefs {
1184-
group, err := schema.ParseGroupVersion(ownerRef.APIVersion)
1185-
if err != nil {
1186-
continue
1187-
}
1188-
parentKey := kube.ResourceKey{Group: group.Group, Kind: ownerRef.Kind, Namespace: "", Name: ownerRef.Name}
1189-
if parentNode, exists := nsNodes[parentKey]; exists {
1190-
// Found a cross-namespace relationship
1191-
if _, ok := graph[parentNode.ResourceKey()]; !ok {
1192-
graph[parentNode.ResourceKey()] = make(map[types.UID]*Resource)
1193-
}
1194-
graph[parentNode.ResourceKey()][childNode.Ref.UID] = childNode
1187+
parentKey := kube.ResourceKey{Group: group.Group, Kind: ownerRef.Kind, Namespace: "", Name: ownerRef.Name}
1188+
if parentNode, exists := nsNodes[parentKey]; exists {
1189+
// Found a cross-namespace relationship
1190+
if _, ok := graph[parentNode.ResourceKey()]; !ok {
1191+
graph[parentNode.ResourceKey()] = make(map[types.UID]*Resource)
11951192
}
1193+
graph[parentNode.ResourceKey()][childNode.Ref.UID] = childNode
11961194
}
11971195
}
11981196
}
1199-
1197+
12001198
return graph
12011199
}
12021200

pkg/cache/cluster_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ func newClusterWithOptions(_ testing.TB, opts []UpdateSettingsFunc, objs ...runt
9292
client.PrependReactor("list", "*", func(action testcore.Action) (handled bool, ret runtime.Object, err error) {
9393
handled, ret, err = reactor.React(action)
9494
if err != nil || !handled {
95-
return
95+
return handled, ret, fmt.Errorf("reactor failed: %w", err)
9696
}
9797
// make sure list response have resource version
9898
ret.(metav1.ListInterface).SetResourceVersion("123")
99-
return
99+
return handled, ret, nil
100100
})
101101

102102
apiResources := []kube.APIResourceInfo{{
@@ -1158,12 +1158,12 @@ func TestIterateHierachyV2(t *testing.T) {
11581158
})
11591159
}
11601160

1161-
// TestIterateHierarchyV2_CrossNamespaceOwnerReference tests that cross-namespace
1162-
// owner references work correctly, specifically cluster-scoped resources with
1161+
// TestIterateHierarchyV2_CrossNamespaceOwnerReference tests that cross-namespace
1162+
// owner references work correctly, specifically cluster-scoped resources with
11631163
// namespaced children
11641164
func TestIterateHierarchyV2_CrossNamespaceOwnerReference(t *testing.T) {
11651165
cluster := newCluster(t)
1166-
1166+
11671167
// Create cluster-scoped parent resource (ProviderRevision)
11681168
parentUID := types.UID("parent-uid-123")
11691169
clusterScopedParent := &Resource{
@@ -1220,35 +1220,36 @@ func TestIterateHierarchyV2_CrossNamespaceOwnerReference(t *testing.T) {
12201220
var visitedResources []*Resource
12211221
cluster.IterateHierarchyV2(
12221222
[]kube.ResourceKey{clusterScopedParent.ResourceKey()},
1223-
func(resource *Resource, namespaceResources map[kube.ResourceKey]*Resource) bool {
1223+
func(resource *Resource, _ map[kube.ResourceKey]*Resource) bool {
12241224
visitedResources = append(visitedResources, resource)
12251225
return true
12261226
},
12271227
)
12281228

12291229
// Should visit parent + both children (3 resources)
1230-
assert.Equal(t, 3, len(visitedResources), "Should visit parent and both children")
1231-
1230+
assert.Len(t, visitedResources, 3, "Should visit parent and both children")
1231+
12321232
visitedNames := make([]string, len(visitedResources))
12331233
for i, res := range visitedResources {
12341234
visitedNames[i] = res.Ref.Name
12351235
}
1236-
1236+
12371237
// Check we have the expected resources by type and namespace combination
12381238
foundParent := false
12391239
foundClusterChild := false
12401240
foundNamespacedChild := false
1241-
1241+
12421242
for _, res := range visitedResources {
1243-
if res.Ref.Kind == "ProviderRevision" && res.Ref.Namespace == "" {
1243+
switch {
1244+
case res.Ref.Kind == "ProviderRevision" && res.Ref.Namespace == "":
12441245
foundParent = true
1245-
} else if res.Ref.Kind == "ClusterRole" && res.Ref.Namespace == "" {
1246+
case res.Ref.Kind == "ClusterRole" && res.Ref.Namespace == "":
12461247
foundClusterChild = true
1247-
} else if res.Ref.Kind == "Deployment" && res.Ref.Namespace == "crossplane-system" {
1248+
case res.Ref.Kind == "Deployment" && res.Ref.Namespace == "crossplane-system":
12481249
foundNamespacedChild = true
12491250
}
12501251
}
1251-
1252+
12521253
assert.True(t, foundParent, "Should visit ProviderRevision parent")
12531254
assert.True(t, foundClusterChild, "Should visit ClusterRole child")
12541255
assert.True(t, foundNamespacedChild, "Should visit Deployment child (this tests the fix)")
@@ -1286,7 +1287,7 @@ func Test_watchEvents_Deadlock(t *testing.T) {
12861287
// deadlock.RLock()
12871288
// defer deadlock.RUnlock()
12881289

1289-
return
1290+
return info, cacheManifest
12901291
}),
12911292
}, res1, res2, testDeploy())
12921293
defer func() {

0 commit comments

Comments
 (0)