Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pkg/utils/kubeclient/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ func GetNode(client client.Reader, name string) (node *corev1.Node, err error) {

// IsReady checks if the node is ready
// If the node is ready,it returns True.Otherwise,it returns False.
func IsReady(node corev1.Node) (ready bool) {
ready = true
func IsReady(node corev1.Node) bool {
for _, condition := range node.Status.Conditions {
if condition.Type == corev1.NodeReady && condition.Status != corev1.ConditionTrue {
ready = false
break
if condition.Type == corev1.NodeReady {
return condition.Status == corev1.ConditionTrue
}
}
return ready
return false
}
73 changes: 73 additions & 0 deletions pkg/utils/kubeclient/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,77 @@ var _ = Describe("IsReady", func() {
Expect(result).To(BeFalse())
})
})

Context("when node has no NodeReady condition", func() {
It("should return false when conditions are empty", func() {
node := corev1.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test-empty"},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{},
},
}
result := IsReady(node)
Expect(result).To(BeFalse())
})

It("should return false when other conditions are present but NodeReady is missing", func() {
node := corev1.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test3"},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeMemoryPressure,
Status: corev1.ConditionFalse,
},
},
},
}
result := IsReady(node)
Expect(result).To(BeFalse())
})
})

Context("when node ready condition is unknown", func() {
It("should return false when NodeReady condition status is Unknown", func() {
node := corev1.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test4"},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: corev1.ConditionUnknown,
},
},
},
}
result := IsReady(node)
Expect(result).To(BeFalse())
})
})

Context("when one NodeReady condition is false among other conditions", func() {
It("should return false when NodeReady is False among other conditions", func() {
node := corev1.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test5"},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeDiskPressure,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodeReady,
Status: corev1.ConditionFalse,
},
{
Type: corev1.NodePIDPressure,
Status: corev1.ConditionFalse,
},
},
},
}
result := IsReady(node)
Expect(result).To(BeFalse())
})
})
})