@@ -140,7 +140,7 @@ func (c *clusterCache) WithAPIResources(newApiResources []kube.APIResourceInfo)
140140
141141func getChildren (cluster * clusterCache , un * unstructured.Unstructured ) []* Resource {
142142 hierarchy := make ([]* Resource , 0 )
143- cluster .IterateHierarchy ( kube .GetResourceKey (un ), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
143+ cluster .IterateHierarchyV2 ([] kube.ResourceKey { kube . GetResourceKey (un )} , func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
144144 hierarchy = append (hierarchy , child )
145145 return true
146146 })
@@ -1045,92 +1045,6 @@ func testDeploy() *appsv1.Deployment {
10451045 }
10461046}
10471047
1048- func TestIterateHierachy (t * testing.T ) {
1049- cluster := newCluster (t , testPod1 (), testPod2 (), testRS (), testExtensionsRS (), testDeploy ())
1050- err := cluster .EnsureSynced ()
1051- require .NoError (t , err )
1052-
1053- t .Run ("IterateAll" , func (t * testing.T ) {
1054- keys := []kube.ResourceKey {}
1055- cluster .IterateHierarchy (kube .GetResourceKey (mustToUnstructured (testDeploy ())), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
1056- keys = append (keys , child .ResourceKey ())
1057- return true
1058- })
1059-
1060- assert .ElementsMatch (t ,
1061- []kube.ResourceKey {
1062- kube .GetResourceKey (mustToUnstructured (testPod1 ())),
1063- kube .GetResourceKey (mustToUnstructured (testPod2 ())),
1064- kube .GetResourceKey (mustToUnstructured (testRS ())),
1065- kube .GetResourceKey (mustToUnstructured (testDeploy ())),
1066- },
1067- keys )
1068- })
1069-
1070- t .Run ("ExitAtRoot" , func (t * testing.T ) {
1071- keys := []kube.ResourceKey {}
1072- cluster .IterateHierarchy (kube .GetResourceKey (mustToUnstructured (testDeploy ())), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
1073- keys = append (keys , child .ResourceKey ())
1074- return false
1075- })
1076-
1077- assert .ElementsMatch (t ,
1078- []kube.ResourceKey {
1079- kube .GetResourceKey (mustToUnstructured (testDeploy ())),
1080- },
1081- keys )
1082- })
1083-
1084- t .Run ("ExitAtSecondLevelChild" , func (t * testing.T ) {
1085- keys := []kube.ResourceKey {}
1086- cluster .IterateHierarchy (kube .GetResourceKey (mustToUnstructured (testDeploy ())), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
1087- keys = append (keys , child .ResourceKey ())
1088- return child .ResourceKey ().Kind != kube .ReplicaSetKind
1089- })
1090-
1091- assert .ElementsMatch (t ,
1092- []kube.ResourceKey {
1093- kube .GetResourceKey (mustToUnstructured (testDeploy ())),
1094- kube .GetResourceKey (mustToUnstructured (testRS ())),
1095- },
1096- keys )
1097- })
1098-
1099- t .Run ("ExitAtThirdLevelChild" , func (t * testing.T ) {
1100- keys := []kube.ResourceKey {}
1101- cluster .IterateHierarchy (kube .GetResourceKey (mustToUnstructured (testDeploy ())), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
1102- keys = append (keys , child .ResourceKey ())
1103- return child .ResourceKey ().Kind != kube .PodKind
1104- })
1105-
1106- assert .ElementsMatch (t ,
1107- []kube.ResourceKey {
1108- kube .GetResourceKey (mustToUnstructured (testDeploy ())),
1109- kube .GetResourceKey (mustToUnstructured (testRS ())),
1110- kube .GetResourceKey (mustToUnstructured (testPod1 ())),
1111- kube .GetResourceKey (mustToUnstructured (testPod2 ())),
1112- },
1113- keys )
1114- })
1115-
1116- // After uid is backfilled for owner of pod2, it should appear in results here as well.
1117- t .Run ("IterateStartFromExtensionsRS" , func (t * testing.T ) {
1118- keys := []kube.ResourceKey {}
1119- cluster .IterateHierarchy (kube .GetResourceKey (mustToUnstructured (testExtensionsRS ())), func (child * Resource , _ map [kube.ResourceKey ]* Resource ) bool {
1120- keys = append (keys , child .ResourceKey ())
1121- return true
1122- })
1123-
1124- assert .ElementsMatch (t ,
1125- []kube.ResourceKey {
1126- kube .GetResourceKey (mustToUnstructured (testPod1 ())),
1127- kube .GetResourceKey (mustToUnstructured (testPod2 ())),
1128- kube .GetResourceKey (mustToUnstructured (testExtensionsRS ())),
1129- },
1130- keys )
1131- })
1132- }
1133-
11341048func TestIterateHierachyV2 (t * testing.T ) {
11351049 cluster := newCluster (t , testPod1 (), testPod2 (), testRS (), testExtensionsRS (), testDeploy ())
11361050 err := cluster .EnsureSynced ()
@@ -1378,18 +1292,3 @@ func BenchmarkIterateHierarchyV2(b *testing.B) {
13781292 })
13791293 }
13801294}
1381-
1382- // func BenchmarkIterateHierarchy(b *testing.B) {
1383- // cluster := newCluster(b)
1384- // for _, resource := range testResources {
1385- // cluster.setNode(resource)
1386- // }
1387- // b.ResetTimer()
1388- // for n := 0; n < b.N; n++ {
1389- // cluster.IterateHierarchy(kube.ResourceKey{
1390- // Namespace: "default", Name: "test-1", Kind: "Pod",
1391- // }, func(child *Resource, _ map[kube.ResourceKey]*Resource) bool {
1392- // return true
1393- // })
1394- // }
1395- //}
0 commit comments