diff --git a/conf/README.md b/conf/README.md index 09db077e697..4f9e45f04ef 100644 --- a/conf/README.md +++ b/conf/README.md @@ -349,6 +349,7 @@ higher priority). * `continue_upgrade_after_checks_even_if_not_healthy` - if set to true Rook will continue the OSD daemon upgrade process even if the PGs are not clean. * `upgrade_osd_requires_healthy_pgs` - If set to true OSD upgrade process won't start until PGs are healthy. * `workaround_mark_disks_as_ssd` - WORKAROUND: mark disks as SSD (not rotational - `0` in `/sys/block/*d*/queue/rotational`) +* `node_labels` - Comma-separated labels to be applied to the nodes in the cluster, e.g. 'cluster.ocs.openshift.io/openshift-storage="",node-role.kubernetes.io/infra=""', default - empty string #### UPGRADE diff --git a/conf/deployment/aws/rosa_hcp_1az_3w_m5.12x.yaml b/conf/deployment/aws/rosa_hcp_1az_3w_m5.12x.yaml index a8438908e9f..33a1f036a3e 100644 --- a/conf/deployment/aws/rosa_hcp_1az_3w_m5.12x.yaml +++ b/conf/deployment/aws/rosa_hcp_1az_3w_m5.12x.yaml @@ -26,3 +26,4 @@ ENV_DATA: ms_env_type: "staging" addon_name: "ocs-converged" persistent-monitoring: false + node_labels: cluster.ocs.openshift.io/openshift-storage="" diff --git a/conf/deployment/aws/rosa_hcp_1az_6w_m5.2x.yaml b/conf/deployment/aws/rosa_hcp_1az_6w_m5.2x.yaml index 960bbde5a56..f2c44d37f9e 100644 --- a/conf/deployment/aws/rosa_hcp_1az_6w_m5.2x.yaml +++ b/conf/deployment/aws/rosa_hcp_1az_6w_m5.2x.yaml @@ -26,3 +26,4 @@ ENV_DATA: ms_env_type: "staging" addon_name: "ocs-converged" persistent-monitoring: false + node_labels: cluster.ocs.openshift.io/openshift-storage="" diff --git a/ocs_ci/deployment/rosa.py b/ocs_ci/deployment/rosa.py index 6b03b58c259..2d803dac102 100644 --- a/ocs_ci/deployment/rosa.py +++ b/ocs_ci/deployment/rosa.py @@ -100,6 +100,11 @@ def deploy(self, log_level=""): machinepool_details.wait_replicas_ready( target_replicas=config.ENV_DATA["worker_replicas"], timeout=1200 ) + if node_labels := config.ENV_DATA.get("node_labels"): + if machinepool_id := config.ENV_DATA.get("machine_pool"): + rosa.label_nodes( + self.cluster_name, machinepool_id, node_labels, rewrite=False + ) logger.info("generate kubeconfig and kubeadmin-password files") if config.ENV_DATA["ms_env_type"] == "staging": diff --git a/ocs_ci/framework/conf/default_config.yaml b/ocs_ci/framework/conf/default_config.yaml index e988c7ff40d..23f01d8feb8 100644 --- a/ocs_ci/framework/conf/default_config.yaml +++ b/ocs_ci/framework/conf/default_config.yaml @@ -279,6 +279,9 @@ ENV_DATA: #RDR Green field rdr_osd_deployment_mode: "greenfield" + # Label nodes with specific labels, used for example fot ODF deployment on ROSA HCP + node_labels: "" + # Assisted Installer related settings # This section is related to upgrade diff --git a/ocs_ci/ocs/machinepool.py b/ocs_ci/ocs/machinepool.py index 765f4874538..bfb66d0840d 100644 --- a/ocs_ci/ocs/machinepool.py +++ b/ocs_ci/ocs/machinepool.py @@ -137,6 +137,7 @@ class MachinePool: exist: bool = field( default=False ) # not a part of the data fetched from the cluster + labels: Dict[str, str] = field(default_factory=dict) def __post_init__(self): """Automatically populate fields by fetching machine pool details.""" @@ -173,8 +174,16 @@ def from_dict(cls, data: dict, cluster_name=None): "id" ), # this parameter is different in node_conf and data fetched from machinepool cluster_name=cluster_name, + labels=data.get("labels", {}), ) + def refresh(self): + """Refresh the machine pool details.""" + details = self.get_machinepool_details(self.cluster_name, self.machinepool_id) + if details: + self.__dict__.update(details.__dict__) + self.exist = True + def get_machinepool_updated_replicas(self) -> Dict[str, int]: """ Retrieve the number of replicas and current replicas for this machine pool. @@ -463,10 +472,6 @@ def build_machinepool_cmd_base(cluster_name, node_conf, action): raise ValueError( "When 'enable_autoscaling' is True, 'min_replicas' and 'max_replicas' are required." ) - elif node_conf.get("replicas") is None: - raise ValueError( - "Parameter 'replicas' is required when autoscaling is disabled." - ) cmd = f"rosa {action} machinepool --cluster {cluster_name} " diff --git a/ocs_ci/utility/rosa.py b/ocs_ci/utility/rosa.py index 3e317f6418e..0e35bbb390e 100644 --- a/ocs_ci/utility/rosa.py +++ b/ocs_ci/utility/rosa.py @@ -19,6 +19,7 @@ ResourceWrongStatusException, TimeoutExpiredError, ) +from ocs_ci.ocs.machinepool import MachinePools, NodeConf from ocs_ci.utility import openshift_dedicated as ocm from ocs_ci.utility import utils @@ -1112,3 +1113,41 @@ def get_associated_oidc_config_id(cluster_name): logger.warning(f"Failed to get OIDC config id: {proc.stderr.decode().strip()}") return "" return proc.stdout.decode().strip() + + +def label_nodes(cluster_name, machinepool_id, labels, rewrite=False): + """ + Label nodes of the given cluster. + ! Important + This method rewrites existing behavior of labeling nodes in the cluster, it appends the labels to the existing + labels, but not rewrite them. This prevents the issue of accidental overwriting the existing labels. + + Args: + cluster_name (str): The cluster name + machinepool_id (str): The machinepool id + labels (str): The labels to apply + rewrite (bool): If True, rewrite the labels. False, otherwise. + + Returns: + str: The output of the command + """ + machine_pools = MachinePools(cluster_name) + machine_pool = machine_pools.filter(machinepool_id="workers", pick_first=True) + if not rewrite: + labels_dict = machine_pool.labels + logger.info(f"Existing labels: {labels_dict}") + # convert to comma separated string + if labels_dict: + labels = ( + ",".join([f"{key}={value}" for key, value in labels_dict.items()]) + + "," + + labels + ) + else: + labels = labels + machine_pools.edit_machine_pool( + NodeConf(**{"machinepool_id": machinepool_id, "labels": labels}), + wait_ready=False, + ) + machine_pool.refresh() + return machine_pool.labels