@@ -1591,6 +1591,116 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
1591
1591
}
1592
1592
}
1593
1593
1594
+ func TestShouldWaitForNodeVolumes (t * testing.T ) {
1595
+ testCluster := & clusterv1.Cluster {
1596
+ TypeMeta : metav1.TypeMeta {Kind : "Cluster" , APIVersion : clusterv1 .GroupVersion .String ()},
1597
+ ObjectMeta : metav1.ObjectMeta {Namespace : metav1 .NamespaceDefault , Name : "test-cluster" },
1598
+ }
1599
+
1600
+ attachedVolumes := []corev1.AttachedVolume {
1601
+ {
1602
+ Name : "test-volume" ,
1603
+ DevicePath : "test-path" ,
1604
+ },
1605
+ }
1606
+
1607
+ tests := []struct {
1608
+ name string
1609
+ node * corev1.Node
1610
+ expected bool
1611
+ }{
1612
+ {
1613
+ name : "Node has volumes attached" ,
1614
+ node : & corev1.Node {
1615
+ ObjectMeta : metav1.ObjectMeta {
1616
+ Name : "test-node" ,
1617
+ },
1618
+ Status : corev1.NodeStatus {
1619
+ Conditions : []corev1.NodeCondition {
1620
+ {
1621
+ Type : corev1 .NodeReady ,
1622
+ Status : corev1 .ConditionTrue ,
1623
+ },
1624
+ },
1625
+ VolumesAttached : attachedVolumes ,
1626
+ },
1627
+ },
1628
+ expected : true ,
1629
+ },
1630
+ {
1631
+ name : "Node has no volumes attached" ,
1632
+ node : & corev1.Node {
1633
+ ObjectMeta : metav1.ObjectMeta {
1634
+ Name : "test-node" ,
1635
+ },
1636
+ Status : corev1.NodeStatus {
1637
+ Conditions : []corev1.NodeCondition {
1638
+ {
1639
+ Type : corev1 .NodeReady ,
1640
+ Status : corev1 .ConditionTrue ,
1641
+ },
1642
+ },
1643
+ },
1644
+ },
1645
+ expected : false ,
1646
+ },
1647
+ {
1648
+ name : "Node is unreachable and has volumes attached" ,
1649
+ node : & corev1.Node {
1650
+ ObjectMeta : metav1.ObjectMeta {
1651
+ Name : "unreachable-node" ,
1652
+ },
1653
+ Status : corev1.NodeStatus {
1654
+ Conditions : []corev1.NodeCondition {
1655
+ {
1656
+ Type : corev1 .NodeReady ,
1657
+ Status : corev1 .ConditionUnknown ,
1658
+ },
1659
+ },
1660
+ VolumesAttached : attachedVolumes ,
1661
+ },
1662
+ },
1663
+ expected : false ,
1664
+ },
1665
+ {
1666
+ name : "Node is unreachable and has no volumes attached" ,
1667
+ node : & corev1.Node {
1668
+ ObjectMeta : metav1.ObjectMeta {
1669
+ Name : "unreachable-node" ,
1670
+ },
1671
+ Status : corev1.NodeStatus {
1672
+ Conditions : []corev1.NodeCondition {
1673
+ {
1674
+ Type : corev1 .NodeReady ,
1675
+ Status : corev1 .ConditionUnknown ,
1676
+ },
1677
+ },
1678
+ },
1679
+ },
1680
+ expected : false ,
1681
+ },
1682
+ }
1683
+ for _ , tt := range tests {
1684
+ t .Run (tt .name , func (t * testing.T ) {
1685
+ g := NewWithT (t )
1686
+
1687
+ var objs []client.Object
1688
+ objs = append (objs , testCluster , tt .node )
1689
+
1690
+ c := fake .NewClientBuilder ().WithObjects (objs ... ).Build ()
1691
+ tracker := remote .NewTestClusterCacheTracker (ctrl .Log , c , c , fakeScheme , client .ObjectKeyFromObject (testCluster ))
1692
+ r := & Reconciler {
1693
+ Client : c ,
1694
+ Tracker : tracker ,
1695
+ }
1696
+
1697
+ got , err := r .shouldWaitForNodeVolumes (ctx , testCluster , tt .node .Name )
1698
+ g .Expect (err ).ToNot (HaveOccurred ())
1699
+ g .Expect (got ).To (Equal (tt .expected ))
1700
+ })
1701
+ }
1702
+ }
1703
+
1594
1704
func TestIsDeleteNodeAllowed (t * testing.T ) {
1595
1705
deletionts := metav1 .Now ()
1596
1706
0 commit comments