@@ -59,8 +59,8 @@ func newMockAPI(useInformer bool, res resources) (
5959
6060 if useInformer {
6161 api .Sync (nil )
62- metadataAPI .Sync (nil )
6362 }
63+ metadataAPI .Sync (nil )
6464
6565 return api , metadataAPI , k8sResults , nil
6666}
@@ -1057,12 +1057,16 @@ func TestGetOwnerKindAndName(t *testing.T) {
10571057 for i , tt := range []struct {
10581058 resources
10591059
1060- expectedOwnerKind string
1061- expectedOwnerName string
1060+ expectedOwnerKind string
1061+ expectedOwnerName string
1062+ expectedRootOwnerKind string
1063+ expectedRootOwnerName string
10621064 }{
10631065 {
1064- expectedOwnerKind : "deployment" ,
1065- expectedOwnerName : "t2" ,
1066+ expectedOwnerKind : "deployment" ,
1067+ expectedOwnerName : "t2" ,
1068+ expectedRootOwnerKind : "Deployment" ,
1069+ expectedRootOwnerName : "t2" ,
10661070 resources : resources {
10671071 results : []string {`
10681072apiVersion: v1
@@ -1084,13 +1088,14 @@ metadata:
10841088 ownerReferences:
10851089 - apiVersion: apps/v1
10861090 kind: Deployment
1087- name: t2` ,
1088- },
1091+ name: t2` },
10891092 },
10901093 },
10911094 {
1092- expectedOwnerKind : "replicaset" ,
1093- expectedOwnerName : "t1-b4f55d87f" ,
1095+ expectedOwnerKind : "replicaset" ,
1096+ expectedOwnerName : "t1-b4f55d87f" ,
1097+ expectedRootOwnerKind : "ReplicaSet" ,
1098+ expectedRootOwnerName : "t1-b4f55d87f" ,
10941099 resources : resources {
10951100 results : []string {`
10961101apiVersion: v1
@@ -1106,8 +1111,10 @@ metadata:
11061111 },
11071112 },
11081113 {
1109- expectedOwnerKind : "job" ,
1110- expectedOwnerName : "slow-cooker" ,
1114+ expectedOwnerKind : "job" ,
1115+ expectedOwnerName : "slow-cooker" ,
1116+ expectedRootOwnerKind : "Job" ,
1117+ expectedRootOwnerName : "slow-cooker" ,
11111118 resources : resources {
11121119 results : []string {`
11131120apiVersion: v1
@@ -1123,8 +1130,10 @@ metadata:
11231130 },
11241131 },
11251132 {
1126- expectedOwnerKind : "replicationcontroller" ,
1127- expectedOwnerName : "web" ,
1133+ expectedOwnerKind : "replicationcontroller" ,
1134+ expectedOwnerName : "web" ,
1135+ expectedRootOwnerKind : "ReplicationController" ,
1136+ expectedRootOwnerName : "web" ,
11281137 resources : resources {
11291138 results : []string {`
11301139apiVersion: v1
@@ -1140,8 +1149,10 @@ metadata:
11401149 },
11411150 },
11421151 {
1143- expectedOwnerKind : "pod" ,
1144- expectedOwnerName : "vote-bot" ,
1152+ expectedOwnerKind : "pod" ,
1153+ expectedOwnerName : "vote-bot" ,
1154+ expectedRootOwnerKind : "Pod" ,
1155+ expectedRootOwnerName : "vote-bot" ,
11451156 resources : resources {
11461157 results : []string {`
11471158apiVersion: v1
@@ -1153,8 +1164,10 @@ metadata:
11531164 },
11541165 },
11551166 {
1156- expectedOwnerKind : "cronjob" ,
1157- expectedOwnerName : "my-cronjob" ,
1167+ expectedOwnerKind : "cronjob" ,
1168+ expectedOwnerName : "my-cronjob" ,
1169+ expectedRootOwnerKind : "CronJob" ,
1170+ expectedRootOwnerName : "my-cronjob" ,
11581171 resources : resources {
11591172 results : []string {`
11601173apiVersion: v1
@@ -1176,13 +1189,14 @@ metadata:
11761189 ownerReferences:
11771190 - apiVersion: batch/v1
11781191 kind: CronJob
1179- name: my-cronjob` ,
1180- },
1192+ name: my-cronjob` },
11811193 },
11821194 },
11831195 {
1184- expectedOwnerKind : "replicaset" ,
1185- expectedOwnerName : "invalid-rs-parent-2abdffa" ,
1196+ expectedOwnerKind : "replicaset" ,
1197+ expectedOwnerName : "invalid-rs-parent-2abdffa" ,
1198+ expectedRootOwnerKind : "InvalidParentKind" ,
1199+ expectedRootOwnerName : "invalid-parent" ,
11861200 resources : resources {
11871201 results : []string {`
11881202apiVersion: v1
@@ -1204,8 +1218,7 @@ metadata:
12041218 ownerReferences:
12051219 - apiVersion: invalidParent/v1
12061220 kind: InvalidParentKind
1207- name: invalid-parent` ,
1208- },
1221+ name: invalid-parent` },
12091222 },
12101223 },
12111224 } {
@@ -1232,10 +1245,7 @@ metadata:
12321245 t .Fatalf ("Expected name to be [%s], got [%s]" , tt .expectedOwnerName , ownerName )
12331246 }
12341247
1235- ownerKind , ownerName , err = metadataAPI .GetOwnerKindAndName (context .Background (), pod , retry )
1236- if err != nil {
1237- t .Fatalf ("Unexpected error: %s" , err )
1238- }
1248+ ownerKind , ownerName = metadataAPI .GetOwnerKindAndName (context .Background (), pod , retry )
12391249
12401250 if ownerKind != tt .expectedOwnerKind {
12411251 t .Fatalf ("Expected kind to be [%s], got [%s]" , tt .expectedOwnerKind , ownerKind )
@@ -1244,6 +1254,16 @@ metadata:
12441254 if ownerName != tt .expectedOwnerName {
12451255 t .Fatalf ("Expected name to be [%s], got [%s]" , tt .expectedOwnerName , ownerName )
12461256 }
1257+
1258+ tm , om := metadataAPI .GetRootOwnerKindAndName (context .Background (), & pod .TypeMeta , & pod .ObjectMeta )
1259+
1260+ if tm .Kind != tt .expectedRootOwnerKind {
1261+ t .Fatalf ("Expected root kind to be [%s], got [%s]" , tt .expectedRootOwnerKind , tm .Kind )
1262+ }
1263+
1264+ if om .Name != tt .expectedRootOwnerName {
1265+ t .Fatalf ("Expected root name to be [%s], got [%s]" , tt .expectedRootOwnerName , om .Name )
1266+ }
12471267 })
12481268 }
12491269 }
0 commit comments