@@ -1356,6 +1356,55 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
1356
1356
},
1357
1357
expected : false ,
1358
1358
},
1359
+ {
1360
+ name : "KCP machine with the pre terminate hook should drain" ,
1361
+ machine : & clusterv1.Machine {
1362
+ ObjectMeta : metav1.ObjectMeta {
1363
+ Name : "test-machine" ,
1364
+ Namespace : metav1 .NamespaceDefault ,
1365
+ Labels : map [string ]string {clusterv1 .MachineControlPlaneLabel : "" },
1366
+ Annotations : map [string ]string {KubeadmControlPlanePreTerminateHookCleanupAnnotation : "" },
1367
+ OwnerReferences : []metav1.OwnerReference {
1368
+ {
1369
+ APIVersion : clusterv1 .GroupVersion .String (),
1370
+ Kind : "KubeadmControlPlane" ,
1371
+ Name : "Foo" ,
1372
+ },
1373
+ },
1374
+ },
1375
+ Spec : clusterv1.MachineSpec {
1376
+ ClusterName : "test-cluster" ,
1377
+ InfrastructureRef : corev1.ObjectReference {},
1378
+ Bootstrap : clusterv1.Bootstrap {DataSecretName : ptr .To ("data" )},
1379
+ },
1380
+ Status : clusterv1.MachineStatus {},
1381
+ },
1382
+ expected : true ,
1383
+ },
1384
+ {
1385
+ name : "KCP machine without the pre terminate hook should stop draining" ,
1386
+ machine : & clusterv1.Machine {
1387
+ ObjectMeta : metav1.ObjectMeta {
1388
+ Name : "test-machine" ,
1389
+ Namespace : metav1 .NamespaceDefault ,
1390
+ Labels : map [string ]string {clusterv1 .MachineControlPlaneLabel : "" },
1391
+ OwnerReferences : []metav1.OwnerReference {
1392
+ {
1393
+ APIVersion : clusterv1 .GroupVersion .String (),
1394
+ Kind : "KubeadmControlPlane" ,
1395
+ Name : "Foo" ,
1396
+ },
1397
+ },
1398
+ },
1399
+ Spec : clusterv1.MachineSpec {
1400
+ ClusterName : "test-cluster" ,
1401
+ InfrastructureRef : corev1.ObjectReference {},
1402
+ Bootstrap : clusterv1.Bootstrap {DataSecretName : ptr .To ("data" )},
1403
+ },
1404
+ Status : clusterv1.MachineStatus {},
1405
+ },
1406
+ expected : false ,
1407
+ },
1359
1408
{
1360
1409
name : "Node draining timeout is over" ,
1361
1410
machine : & clusterv1.Machine {
@@ -1868,6 +1917,55 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
1868
1917
},
1869
1918
expected : false ,
1870
1919
},
1920
+ {
1921
+ name : "KCP machine with the pre terminate hook should wait" ,
1922
+ machine : & clusterv1.Machine {
1923
+ ObjectMeta : metav1.ObjectMeta {
1924
+ Name : "test-machine" ,
1925
+ Namespace : metav1 .NamespaceDefault ,
1926
+ Labels : map [string ]string {clusterv1 .MachineControlPlaneLabel : "" },
1927
+ Annotations : map [string ]string {KubeadmControlPlanePreTerminateHookCleanupAnnotation : "" },
1928
+ OwnerReferences : []metav1.OwnerReference {
1929
+ {
1930
+ APIVersion : clusterv1 .GroupVersion .String (),
1931
+ Kind : "KubeadmControlPlane" ,
1932
+ Name : "Foo" ,
1933
+ },
1934
+ },
1935
+ },
1936
+ Spec : clusterv1.MachineSpec {
1937
+ ClusterName : "test-cluster" ,
1938
+ InfrastructureRef : corev1.ObjectReference {},
1939
+ Bootstrap : clusterv1.Bootstrap {DataSecretName : ptr .To ("data" )},
1940
+ },
1941
+ Status : clusterv1.MachineStatus {},
1942
+ },
1943
+ expected : true ,
1944
+ },
1945
+ {
1946
+ name : "KCP machine without the pre terminate hook should stop waiting" ,
1947
+ machine : & clusterv1.Machine {
1948
+ ObjectMeta : metav1.ObjectMeta {
1949
+ Name : "test-machine" ,
1950
+ Namespace : metav1 .NamespaceDefault ,
1951
+ Labels : map [string ]string {clusterv1 .MachineControlPlaneLabel : "" },
1952
+ OwnerReferences : []metav1.OwnerReference {
1953
+ {
1954
+ APIVersion : clusterv1 .GroupVersion .String (),
1955
+ Kind : "KubeadmControlPlane" ,
1956
+ Name : "Foo" ,
1957
+ },
1958
+ },
1959
+ },
1960
+ Spec : clusterv1.MachineSpec {
1961
+ ClusterName : "test-cluster" ,
1962
+ InfrastructureRef : corev1.ObjectReference {},
1963
+ Bootstrap : clusterv1.Bootstrap {DataSecretName : ptr .To ("data" )},
1964
+ },
1965
+ Status : clusterv1.MachineStatus {},
1966
+ },
1967
+ expected : false ,
1968
+ },
1871
1969
{
1872
1970
name : "Volume detach timeout is over" ,
1873
1971
machine : & clusterv1.Machine {
0 commit comments