@@ -59,8 +59,8 @@ func newMockAPI(useInformer bool, res resources) (
59
59
60
60
if useInformer {
61
61
api .Sync (nil )
62
- metadataAPI .Sync (nil )
63
62
}
63
+ metadataAPI .Sync (nil )
64
64
65
65
return api , metadataAPI , k8sResults , nil
66
66
}
@@ -1057,12 +1057,16 @@ func TestGetOwnerKindAndName(t *testing.T) {
1057
1057
for i , tt := range []struct {
1058
1058
resources
1059
1059
1060
- expectedOwnerKind string
1061
- expectedOwnerName string
1060
+ expectedOwnerKind string
1061
+ expectedOwnerName string
1062
+ expectedRootOwnerKind string
1063
+ expectedRootOwnerName string
1062
1064
}{
1063
1065
{
1064
- expectedOwnerKind : "deployment" ,
1065
- expectedOwnerName : "t2" ,
1066
+ expectedOwnerKind : "deployment" ,
1067
+ expectedOwnerName : "t2" ,
1068
+ expectedRootOwnerKind : "Deployment" ,
1069
+ expectedRootOwnerName : "t2" ,
1066
1070
resources : resources {
1067
1071
results : []string {`
1068
1072
apiVersion: v1
@@ -1084,13 +1088,14 @@ metadata:
1084
1088
ownerReferences:
1085
1089
- apiVersion: apps/v1
1086
1090
kind: Deployment
1087
- name: t2` ,
1088
- },
1091
+ name: t2` },
1089
1092
},
1090
1093
},
1091
1094
{
1092
- expectedOwnerKind : "replicaset" ,
1093
- expectedOwnerName : "t1-b4f55d87f" ,
1095
+ expectedOwnerKind : "replicaset" ,
1096
+ expectedOwnerName : "t1-b4f55d87f" ,
1097
+ expectedRootOwnerKind : "ReplicaSet" ,
1098
+ expectedRootOwnerName : "t1-b4f55d87f" ,
1094
1099
resources : resources {
1095
1100
results : []string {`
1096
1101
apiVersion: v1
@@ -1106,8 +1111,10 @@ metadata:
1106
1111
},
1107
1112
},
1108
1113
{
1109
- expectedOwnerKind : "job" ,
1110
- expectedOwnerName : "slow-cooker" ,
1114
+ expectedOwnerKind : "job" ,
1115
+ expectedOwnerName : "slow-cooker" ,
1116
+ expectedRootOwnerKind : "Job" ,
1117
+ expectedRootOwnerName : "slow-cooker" ,
1111
1118
resources : resources {
1112
1119
results : []string {`
1113
1120
apiVersion: v1
@@ -1123,8 +1130,10 @@ metadata:
1123
1130
},
1124
1131
},
1125
1132
{
1126
- expectedOwnerKind : "replicationcontroller" ,
1127
- expectedOwnerName : "web" ,
1133
+ expectedOwnerKind : "replicationcontroller" ,
1134
+ expectedOwnerName : "web" ,
1135
+ expectedRootOwnerKind : "ReplicationController" ,
1136
+ expectedRootOwnerName : "web" ,
1128
1137
resources : resources {
1129
1138
results : []string {`
1130
1139
apiVersion: v1
@@ -1140,8 +1149,10 @@ metadata:
1140
1149
},
1141
1150
},
1142
1151
{
1143
- expectedOwnerKind : "pod" ,
1144
- expectedOwnerName : "vote-bot" ,
1152
+ expectedOwnerKind : "pod" ,
1153
+ expectedOwnerName : "vote-bot" ,
1154
+ expectedRootOwnerKind : "Pod" ,
1155
+ expectedRootOwnerName : "vote-bot" ,
1145
1156
resources : resources {
1146
1157
results : []string {`
1147
1158
apiVersion: v1
@@ -1153,8 +1164,10 @@ metadata:
1153
1164
},
1154
1165
},
1155
1166
{
1156
- expectedOwnerKind : "cronjob" ,
1157
- expectedOwnerName : "my-cronjob" ,
1167
+ expectedOwnerKind : "cronjob" ,
1168
+ expectedOwnerName : "my-cronjob" ,
1169
+ expectedRootOwnerKind : "CronJob" ,
1170
+ expectedRootOwnerName : "my-cronjob" ,
1158
1171
resources : resources {
1159
1172
results : []string {`
1160
1173
apiVersion: v1
@@ -1176,13 +1189,14 @@ metadata:
1176
1189
ownerReferences:
1177
1190
- apiVersion: batch/v1
1178
1191
kind: CronJob
1179
- name: my-cronjob` ,
1180
- },
1192
+ name: my-cronjob` },
1181
1193
},
1182
1194
},
1183
1195
{
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" ,
1186
1200
resources : resources {
1187
1201
results : []string {`
1188
1202
apiVersion: v1
@@ -1204,8 +1218,7 @@ metadata:
1204
1218
ownerReferences:
1205
1219
- apiVersion: invalidParent/v1
1206
1220
kind: InvalidParentKind
1207
- name: invalid-parent` ,
1208
- },
1221
+ name: invalid-parent` },
1209
1222
},
1210
1223
},
1211
1224
} {
@@ -1232,10 +1245,7 @@ metadata:
1232
1245
t .Fatalf ("Expected name to be [%s], got [%s]" , tt .expectedOwnerName , ownerName )
1233
1246
}
1234
1247
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 )
1239
1249
1240
1250
if ownerKind != tt .expectedOwnerKind {
1241
1251
t .Fatalf ("Expected kind to be [%s], got [%s]" , tt .expectedOwnerKind , ownerKind )
@@ -1244,6 +1254,16 @@ metadata:
1244
1254
if ownerName != tt .expectedOwnerName {
1245
1255
t .Fatalf ("Expected name to be [%s], got [%s]" , tt .expectedOwnerName , ownerName )
1246
1256
}
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
+ }
1247
1267
})
1248
1268
}
1249
1269
}
0 commit comments