@@ -107,25 +107,29 @@ func addController(controller *controllerFetcher, obj runtime.Object) {
107
107
108
108
func TestControllerFetcher (t * testing.T ) {
109
109
type testCase struct {
110
+ name string
110
111
apiVersion string
111
112
key * ControllerKeyWithAPIVersion
112
113
objects []runtime.Object
113
114
expectedKey * ControllerKeyWithAPIVersion
114
115
expectedError error
115
116
}
116
- for i , tc := range []testCase {
117
+ for _ , tc := range []testCase {
117
118
{
119
+ name : "nils" ,
118
120
key : nil ,
119
121
expectedKey : nil ,
120
122
expectedError : nil ,
121
123
},
122
124
{
125
+ name : "deployment doesn't exist" ,
123
126
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
124
127
Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
125
128
expectedKey : nil ,
126
129
expectedError : fmt .Errorf ("Deployment test-namesapce/test-deployment does not exist" ),
127
130
},
128
131
{
132
+ name : "deployment no parent" ,
129
133
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
130
134
Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
131
135
objects : []runtime.Object {& appsv1.Deployment {
@@ -142,6 +146,7 @@ func TestControllerFetcher(t *testing.T) {
142
146
expectedError : nil ,
143
147
},
144
148
{
149
+ name : "deployment with parent" ,
145
150
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
146
151
Name : "test-rs" , Kind : "ReplicaSet" , Namespace : "test-namesapce" }},
147
152
objects : []runtime.Object {& appsv1.Deployment {
@@ -173,6 +178,7 @@ func TestControllerFetcher(t *testing.T) {
173
178
expectedError : nil ,
174
179
},
175
180
{
181
+ name : "StatefulSet" ,
176
182
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
177
183
Name : "test-statefulset" , Kind : "StatefulSet" , Namespace : "test-namesapce" }},
178
184
objects : []runtime.Object {& appsv1.StatefulSet {
@@ -189,6 +195,7 @@ func TestControllerFetcher(t *testing.T) {
189
195
expectedError : nil ,
190
196
},
191
197
{
198
+ name : "DaemonSet" ,
192
199
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
193
200
Name : "test-daemonset" , Kind : "DaemonSet" , Namespace : "test-namesapce" }},
194
201
objects : []runtime.Object {& appsv1.DaemonSet {
@@ -205,6 +212,7 @@ func TestControllerFetcher(t *testing.T) {
205
212
expectedError : nil ,
206
213
},
207
214
{
215
+ name : "CronJob" ,
208
216
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
209
217
Name : "test-job" , Kind : "Job" , Namespace : "test-namespace" }},
210
218
objects : []runtime.Object {& batchv1.Job {
@@ -236,6 +244,7 @@ func TestControllerFetcher(t *testing.T) {
236
244
expectedError : nil ,
237
245
},
238
246
{
247
+ name : "CronJob no parent" ,
239
248
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
240
249
Name : "test-cronjob" , Kind : "CronJob" , Namespace : "test-namespace" }},
241
250
objects : []runtime.Object {& batchv1beta1.CronJob {
@@ -252,6 +261,7 @@ func TestControllerFetcher(t *testing.T) {
252
261
expectedError : nil ,
253
262
},
254
263
{
264
+ name : "rc no parent" ,
255
265
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
256
266
Name : "test-rc" , Kind : "ReplicationController" , Namespace : "test-namesapce" }},
257
267
objects : []runtime.Object {& corev1.ReplicationController {
@@ -268,6 +278,7 @@ func TestControllerFetcher(t *testing.T) {
268
278
expectedError : nil ,
269
279
},
270
280
{
281
+ name : "deployment cycle in ownership" ,
271
282
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
272
283
Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
273
284
objects : []runtime.Object {& appsv1.Deployment {
@@ -291,6 +302,7 @@ func TestControllerFetcher(t *testing.T) {
291
302
expectedError : fmt .Errorf ("Cycle detected in ownership chain" ),
292
303
},
293
304
{
305
+ name : "deployment, parent with no scale subresource" ,
294
306
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
295
307
Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
296
308
objects : []runtime.Object {& appsv1.Deployment {
@@ -316,6 +328,7 @@ func TestControllerFetcher(t *testing.T) {
316
328
expectedError : nil ,
317
329
},
318
330
{
331
+ name : "deployment, parent not well known with scale subresource" ,
319
332
key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
320
333
Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
321
334
objects : []runtime.Object {& appsv1.Deployment {
@@ -340,8 +353,33 @@ func TestControllerFetcher(t *testing.T) {
340
353
Name : "iCanScale" , Kind : "Scale" , Namespace : "test-namesapce" }, ApiVersion : "Foo/Foo" }, // Parent supports scale subresource"
341
354
expectedError : nil ,
342
355
},
356
+ {
357
+ name : "pod, parent is node" ,
358
+ key : & ControllerKeyWithAPIVersion {ControllerKey : ControllerKey {
359
+ Name : "test-deployment" , Kind : "Deployment" , Namespace : "test-namesapce" }},
360
+ objects : []runtime.Object {& appsv1.Deployment {
361
+ TypeMeta : metav1.TypeMeta {
362
+ Kind : "Deployment" ,
363
+ },
364
+ ObjectMeta : metav1.ObjectMeta {
365
+ Name : "test-deployment" ,
366
+ Namespace : "test-namesapce" ,
367
+ // Parent is a node
368
+ OwnerReferences : []metav1.OwnerReference {
369
+ {
370
+ APIVersion : "v1" ,
371
+ Controller : & trueVar ,
372
+ Kind : "Node" ,
373
+ Name : "node" ,
374
+ },
375
+ },
376
+ },
377
+ }},
378
+ expectedKey : nil ,
379
+ expectedError : fmt .Errorf ("Unhandled targetRef v1 / Node / node, last error node is not a valid owner" ),
380
+ },
343
381
} {
344
- t .Run (fmt . Sprintf ( "test case %d" , i ) , func (t * testing.T ) {
382
+ t .Run (tc . name , func (t * testing.T ) {
345
383
f := simpleControllerFetcher ()
346
384
for _ , obj := range tc .objects {
347
385
addController (f , obj )
0 commit comments