-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance node ready logic at KubernetesClient , increase timeout to 30…
…min and add unit tests (#411) Add the same checks done by the clusterloader2 to check if node is ready to be scheduled: https://github.com/Azure/perf-tests/blob/395a79947d2c98aa8376c204071ef865e552a292/clusterloader2/pkg/util/cluster.go#L92-L138 --------- Co-authored-by: Rafael Mendes Pereira <[email protected]>
- Loading branch information
1 parent
0a68ec1
commit e7867fd
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from kubernetes.client.models import ( | ||
V1Node, V1NodeStatus, V1NodeCondition, V1NodeSpec, V1ObjectMeta, V1Taint | ||
) | ||
from clusterloader2.kubernetes_client import KubernetesClient | ||
|
||
class TestKubernetesClient(unittest.TestCase): | ||
|
||
@patch('kubernetes.config.load_kube_config') | ||
def setUp(self, mock_load_kube_config): | ||
self.client = KubernetesClient() | ||
return super().setUp() | ||
|
||
def _create_node(self, name, ready_status, network_unavailable_status=None, unschedulable=False, taints=None): | ||
conditions = [V1NodeCondition(type="Ready", status=ready_status)] | ||
if network_unavailable_status is not None: | ||
conditions.append(V1NodeCondition(type="NetworkUnavailable", status=network_unavailable_status)) | ||
return V1Node( | ||
metadata=V1ObjectMeta(name=name), | ||
status=V1NodeStatus(conditions=conditions), | ||
spec=V1NodeSpec(unschedulable=unschedulable, taints=taints) | ||
) | ||
|
||
@patch('clusterloader2.kubernetes_client.KubernetesClient.get_nodes') | ||
def test_get_ready_nodes_with_network_unavailable(self, mock_get_nodes): | ||
# Mock nodes | ||
# Nodes ready to be scheduled | ||
node_ready_network_available = self._create_node(name="node_ready_network_available", ready_status="True", network_unavailable_status="False") | ||
node_ready_no_network_condition = self._create_node(name="node_ready_no_network_condition", ready_status="True") | ||
node_ready_taint_no_effect = self._create_node( | ||
name="node_ready_taint_no_effect", ready_status="True", taints=[V1Taint(key="node.cloudprovider.kubernetes.io/shutdown", effect="")]) | ||
# Nodes NOT ready to be scheduled | ||
node_not_ready = self._create_node(name="node_not_ready", ready_status="False") | ||
node_ready_network_unavailable = self._create_node(name="node_ready_network_unavailable", ready_status="True", network_unavailable_status="True") | ||
node_ready_unschedulable_true = self._create_node(name="node_ready_unschedulable", ready_status="True", unschedulable=True) | ||
node_ready_shutdown_taint = self._create_node( | ||
name="node_ready_shutdown_taint", ready_status="True", taints=[V1Taint(key="node.cloudprovider.kubernetes.io/shutdown", effect="NoSchedule")]) | ||
|
||
|
||
mock_get_nodes.return_value = [ | ||
node_not_ready, | ||
node_ready_network_available, | ||
node_ready_network_unavailable, | ||
node_ready_no_network_condition, | ||
node_ready_unschedulable_true, | ||
node_ready_shutdown_taint, | ||
node_ready_taint_no_effect | ||
] | ||
|
||
ready_nodes = self.client.get_ready_nodes() | ||
|
||
self.maxDiff = None | ||
self.assertCountEqual(ready_nodes, | ||
[node_ready_network_available, node_ready_no_network_condition, node_ready_taint_no_effect] | ||
) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters