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