Skip to content

Commit

Permalink
Exclude the master nodes when using HCI Provider (#9231)
Browse files Browse the repository at this point in the history
* Exclude the master nodes when using HCI Provider

Signed-off-by: Itzhak Kave <[email protected]>

* Update the docstring regrding exclude the master node if we use HCI

Signed-off-by: Itzhak Kave <[email protected]>

---------

Signed-off-by: Itzhak Kave <[email protected]>
Co-authored-by: Itzhak Kave <[email protected]>
  • Loading branch information
yitzhak12 and Itzhak Kave authored Jan 29, 2024
1 parent ce1f96f commit 05ce898
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ocs_ci/ocs/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def get_node_objs(node_names=None):
def get_nodes(node_type=constants.WORKER_MACHINE, num_of_nodes=None):
"""
Get cluster's nodes according to the node type (e.g. worker, master) and the
number of requested nodes from that type
number of requested nodes from that type.
In case of HCI provider cluster and 'node_type' is worker, it will exclude the master nodes.
Args:
node_type (str): The node type (e.g. worker, master)
Expand All @@ -85,6 +86,8 @@ def get_nodes(node_type=constants.WORKER_MACHINE, num_of_nodes=None):
list: The nodes OCP instances
"""
from ocs_ci.ocs.cluster import is_hci_provider_cluster

if (
config.ENV_DATA["platform"].lower() in constants.MANAGED_SERVICE_PLATFORMS
and node_type == constants.WORKER_MACHINE
Expand All @@ -104,6 +107,14 @@ def get_nodes(node_type=constants.WORKER_MACHINE, num_of_nodes=None):
if node_type
in node.ocp.get_resource(resource_name=node.name, column="ROLES")
]
if is_hci_provider_cluster() and node_type == constants.WORKER_MACHINE:
typed_nodes = [
node
for node in typed_nodes
if constants.MASTER_MACHINE
not in node.ocp.get_resource(resource_name=node.name, column="ROLES")
]

if num_of_nodes:
typed_nodes = typed_nodes[:num_of_nodes]
return typed_nodes
Expand Down Expand Up @@ -1166,11 +1177,14 @@ def get_master_nodes():
def get_worker_nodes():
"""
Fetches all worker nodes.
In case of HCI provider cluster, it will exclude the master nodes.
Returns:
list: List of names of worker nodes
"""
from ocs_ci.ocs.cluster import is_hci_provider_cluster

label = "node-role.kubernetes.io/worker"
ocp_node_obj = ocp.OCP(kind=constants.NODE)
nodes = ocp_node_obj.get(selector=label).get("items")
Expand All @@ -1186,6 +1200,9 @@ def get_worker_nodes():
if node.get("metadata").get("name") not in infra_node_ids
]
worker_nodes_list = [node.get("metadata").get("name") for node in nodes]
if is_hci_provider_cluster():
master_node_list = get_master_nodes()
worker_nodes_list = list(set(worker_nodes_list) - set(master_node_list))
return worker_nodes_list


Expand Down

0 comments on commit 05ce898

Please sign in to comment.