@@ -20,6 +20,7 @@ import (
20
20
"k8s.io/apimachinery/pkg/util/intstr"
21
21
"k8s.io/client-go/kubernetes/scheme"
22
22
"k8s.io/client-go/tools/record"
23
+ "k8s.io/utils/pointer"
23
24
"sigs.k8s.io/controller-runtime/pkg/client"
24
25
"sigs.k8s.io/controller-runtime/pkg/client/fake"
25
26
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -364,11 +365,27 @@ func TestReconcile(t *testing.T) {
364
365
}
365
366
}
366
367
367
- func TestHasMachineSetOwner (t * testing.T ) {
368
+ func TestHasControllerOwner (t * testing.T ) {
368
369
machineWithMachineSet := maotesting .NewMachine ("machineWithMachineSet" , "node" )
370
+
369
371
machineWithNoMachineSet := maotesting .NewMachine ("machineWithNoMachineSet" , "node" )
370
372
machineWithNoMachineSet .OwnerReferences = nil
371
373
374
+ machineWithAnyControllerOwner := maotesting .NewMachine ("machineWithAnyControllerOwner" , "node" )
375
+ machineWithAnyControllerOwner .OwnerReferences = []metav1.OwnerReference {
376
+ {
377
+ Kind : "Any" ,
378
+ Controller : pointer .BoolPtr (true ),
379
+ },
380
+ }
381
+
382
+ machineWithNoControllerOwner := maotesting .NewMachine ("machineWithNoControllerOwner" , "node" )
383
+ machineWithNoControllerOwner .OwnerReferences = []metav1.OwnerReference {
384
+ {
385
+ Kind : "Any" ,
386
+ },
387
+ }
388
+
372
389
testsCases := []struct {
373
390
target target
374
391
expected bool
@@ -385,10 +402,22 @@ func TestHasMachineSetOwner(t *testing.T) {
385
402
},
386
403
expected : true ,
387
404
},
405
+ {
406
+ target : target {
407
+ Machine : * machineWithAnyControllerOwner ,
408
+ },
409
+ expected : true ,
410
+ },
411
+ {
412
+ target : target {
413
+ Machine : * machineWithNoControllerOwner ,
414
+ },
415
+ expected : false ,
416
+ },
388
417
}
389
418
390
419
for _ , tc := range testsCases {
391
- if got := tc .target .hasMachineSetOwner (); got != tc .expected {
420
+ if got := tc .target .hasControllerOwner (); got != tc .expected {
392
421
t .Errorf ("Test case: Machine %s. Expected: %t, got: %t" , tc .target .Machine .Name , tc .expected , got )
393
422
}
394
423
}
@@ -1820,11 +1849,16 @@ func TestRemediate(t *testing.T) {
1820
1849
APIVersion : "machine.openshift.io/v1beta1" ,
1821
1850
},
1822
1851
ObjectMeta : metav1.ObjectMeta {
1823
- Annotations : make (map [string ]string ),
1824
- Name : "test" ,
1825
- Namespace : namespace ,
1826
- Labels : map [string ]string {"foo" : "bar" },
1827
- OwnerReferences : []metav1.OwnerReference {{Kind : "MachineSet" }},
1852
+ Annotations : make (map [string ]string ),
1853
+ Name : "test" ,
1854
+ Namespace : namespace ,
1855
+ Labels : map [string ]string {"foo" : "bar" },
1856
+ OwnerReferences : []metav1.OwnerReference {
1857
+ {
1858
+ Kind : "MachineSet" ,
1859
+ Controller : pointer .BoolPtr (true ),
1860
+ },
1861
+ },
1828
1862
},
1829
1863
Spec : mapiv1beta1.MachineSpec {},
1830
1864
Status : mapiv1beta1.MachineStatus {},
@@ -1858,12 +1892,17 @@ func TestRemediate(t *testing.T) {
1858
1892
APIVersion : "machine.openshift.io/v1beta1" ,
1859
1893
},
1860
1894
ObjectMeta : metav1.ObjectMeta {
1861
- Annotations : make (map [string ]string ),
1862
- Name : "test" ,
1863
- Namespace : namespace ,
1864
- Labels : map [string ]string {"foo" : "bar" },
1865
- OwnerReferences : []metav1.OwnerReference {{Kind : "MachineSet" }},
1866
- UID : "uid" ,
1895
+ Annotations : make (map [string ]string ),
1896
+ Name : "test" ,
1897
+ Namespace : namespace ,
1898
+ Labels : map [string ]string {"foo" : "bar" },
1899
+ OwnerReferences : []metav1.OwnerReference {
1900
+ {
1901
+ Kind : "MachineSet" ,
1902
+ Controller : pointer .BoolPtr (true ),
1903
+ },
1904
+ },
1905
+ UID : "uid" ,
1867
1906
},
1868
1907
//Spec: mapiv1beta1.MachineSpec{},
1869
1908
//Status: mapiv1beta1.MachineStatus{},
@@ -1905,7 +1944,12 @@ func TestRemediate(t *testing.T) {
1905
1944
Labels : map [string ]string {
1906
1945
machineRoleLabel : machineMasterRole ,
1907
1946
},
1908
- OwnerReferences : []metav1.OwnerReference {{Kind : "MachineSet" }},
1947
+ OwnerReferences : []metav1.OwnerReference {
1948
+ {
1949
+ Kind : "MachineSet" ,
1950
+ Controller : pointer .BoolPtr (true ),
1951
+ },
1952
+ },
1909
1953
},
1910
1954
Spec : mapiv1beta1.MachineSpec {},
1911
1955
Status : mapiv1beta1.MachineStatus {},
0 commit comments