From efa39f85f05dcec4684aa8440e3b09170ec15f16 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 15 May 2023 11:35:55 +0300 Subject: [PATCH 1/5] remove defaults from define request Signed-off-by: matancarmeli7 --- .../definition_manager/request.py | 26 ++++++++----------- .../host_definer/resource_manager/secret.py | 1 - controllers/servers/host_definer/types.py | 6 ++--- .../host_definer/utils/test_utils.py | 5 ++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/controllers/servers/host_definer/definition_manager/request.py b/controllers/servers/host_definer/definition_manager/request.py index 331956d6a..1fdc5e6b6 100644 --- a/controllers/servers/host_definer/definition_manager/request.py +++ b/controllers/servers/host_definer/definition_manager/request.py @@ -19,32 +19,28 @@ def generate_request(self, host_definition_info): node_name = host_definition_info.node_name logger.info(messages.GENERATE_REQUEST_FOR_NODE.format(node_name)) node_info = self.resource_info_manager.get_node_info(node_name) - request = self._get_new_request(node_info.labels) - request = self._add_array_connectivity_info_to_request( - request, host_definition_info.secret_name, host_definition_info.secret_namespace, node_info.labels) + request = self._get_new_request(host_definition_info.secret_name, + host_definition_info.secret_namespace, node_info.labels) if request: request.node_id_from_host_definition = host_definition_info.node_id request.node_id_from_csi_node = self._get_node_id_by_node(host_definition_info) request.io_group = self._get_io_group_by_node(host_definition_info.node_name) return request - def _get_new_request(self, labels): - request = DefineHostRequest() + def _get_new_request(self, secret_name, secret_namespace, labels): connectivity_type_label_on_node = self._get_label_value(labels, settings.CONNECTIVITY_TYPE_LABEL) - request.prefix = utils.get_prefix() - request.connectivity_type_from_user = utils.get_connectivity_type_from_user(connectivity_type_label_on_node) - return request + prefix = utils.get_prefix() + connectivity_type_from_user = utils.get_connectivity_type_from_user(connectivity_type_label_on_node) + array_connection_info = self.secret_manager.get_array_connection_info(secret_name, secret_namespace, labels) + + if array_connection_info: + return DefineHostRequest(prefix=prefix, connectivity_type_from_user=connectivity_type_from_user, + array_connection_info=array_connection_info) + return None def _get_label_value(self, labels, label): return labels.get(label) - def _add_array_connectivity_info_to_request(self, request, secret_name, secret_namespace, labels): - request.array_connection_info = self.secret_manager.get_array_connection_info( - secret_name, secret_namespace, labels) - if request.array_connection_info: - return request - return None - def _get_node_id_by_node(self, host_definition_info): try: return NODES[host_definition_info.node_name].node_id diff --git a/controllers/servers/host_definer/resource_manager/secret.py b/controllers/servers/host_definer/resource_manager/secret.py index b930b5b03..e067c56ac 100644 --- a/controllers/servers/host_definer/resource_manager/secret.py +++ b/controllers/servers/host_definer/resource_manager/secret.py @@ -5,7 +5,6 @@ from controllers.servers.host_definer.globals import MANAGED_SECRETS from controllers.servers.host_definer import settings from controllers.servers.host_definer.utils import utils -from controllers.servers.host_definer.types import SecretInfo import controllers.servers.host_definer.messages as messages from controllers.servers.host_definer.k8s.api import K8SApi from controllers.servers.host_definer.resource_manager.resource_info import ResourceInfoManager diff --git a/controllers/servers/host_definer/types.py b/controllers/servers/host_definer/types.py index 90b40ec6c..f63788547 100644 --- a/controllers/servers/host_definer/types.py +++ b/controllers/servers/host_definer/types.py @@ -5,11 +5,11 @@ @dataclass class DefineHostRequest: - prefix: str = '' - connectivity_type_from_user: str = '' + prefix: str + connectivity_type_from_user: str + array_connection_info: ArrayConnectionInfo node_id_from_host_definition: str = '' node_id_from_csi_node: str = '' - array_connection_info: ArrayConnectionInfo = ArrayConnectionInfo(array_addresses='', user='', password='') io_group: str = '' diff --git a/controllers/tests/controller_server/host_definer/utils/test_utils.py b/controllers/tests/controller_server/host_definer/utils/test_utils.py index d5bd2797c..27bcfc155 100644 --- a/controllers/tests/controller_server/host_definer/utils/test_utils.py +++ b/controllers/tests/controller_server/host_definer/utils/test_utils.py @@ -173,9 +173,8 @@ def get_array_connection_info(): def get_define_request(prefix='', connectivity_type='', node_id_from_host_definition=''): return DefineHostRequest( - prefix, connectivity_type, node_id_from_host_definition, test_settings.FAKE_NODE_ID, - get_array_connection_info(), - test_settings.FAKE_STRING_IO_GROUP) + prefix, connectivity_type, get_array_connection_info(), + node_id_from_host_definition, test_settings.FAKE_NODE_ID, test_settings.FAKE_STRING_IO_GROUP) def get_define_response(connectivity_type, ports): From 699ce16b1302721c7ea8b22879bd6f8cfda79acf Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 15 May 2023 11:46:07 +0300 Subject: [PATCH 2/5] remove defaults from CsiNodeInfo class Signed-off-by: matancarmeli7 --- .../servers/host_definer/resource_manager/resource_info.py | 7 ++----- controllers/servers/host_definer/types.py | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/controllers/servers/host_definer/resource_manager/resource_info.py b/controllers/servers/host_definer/resource_manager/resource_info.py index bb0498192..a2fe6f9af 100644 --- a/controllers/servers/host_definer/resource_manager/resource_info.py +++ b/controllers/servers/host_definer/resource_manager/resource_info.py @@ -27,13 +27,10 @@ def get_csi_node_info(self, node_name): k8s_csi_node = self.k8s_api.get_csi_node(node_name) if k8s_csi_node: return self.generate_csi_node_info(k8s_csi_node) - return CsiNodeInfo() + return CsiNodeInfo('', '') def generate_csi_node_info(self, k8s_csi_node): - csi_node_info = CsiNodeInfo() - csi_node_info.name = k8s_csi_node.metadata.name - csi_node_info.node_id = self._get_node_id_from_k8s_csi_node(k8s_csi_node) - return csi_node_info + return CsiNodeInfo(name=k8s_csi_node.metadata.name, node_id=self._get_node_id_from_k8s_csi_node(k8s_csi_node)) def _get_node_id_from_k8s_csi_node(self, k8s_csi_node): if k8s_csi_node.spec.drivers: diff --git a/controllers/servers/host_definer/types.py b/controllers/servers/host_definer/types.py index f63788547..7d34433d4 100644 --- a/controllers/servers/host_definer/types.py +++ b/controllers/servers/host_definer/types.py @@ -49,8 +49,8 @@ class HostDefinitionInfo: @dataclass class CsiNodeInfo: - name: str = '' - node_id: str = '' + name: str + node_id: str @dataclass From d8260ddb4a58d9e07cf3b289e80a24b071e8ea4d Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 15 May 2023 11:47:45 +0300 Subject: [PATCH 3/5] remove default values from PodInfo class Signed-off-by: matancarmeli7 --- .../servers/host_definer/resource_manager/resource_info.py | 5 +---- controllers/servers/host_definer/types.py | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/controllers/servers/host_definer/resource_manager/resource_info.py b/controllers/servers/host_definer/resource_manager/resource_info.py index a2fe6f9af..bb0363b7f 100644 --- a/controllers/servers/host_definer/resource_manager/resource_info.py +++ b/controllers/servers/host_definer/resource_manager/resource_info.py @@ -64,10 +64,7 @@ def get_csi_pods_info(self): return pods_info def _generate_pod_info(self, k8s_pod): - pod_info = PodInfo() - pod_info.name = k8s_pod.metadata.name - pod_info.node_name = k8s_pod.spec.node_name - return pod_info + return PodInfo(name=k8s_pod.metadata.name, node_name=k8s_pod.spec.node_name) def generate_host_definition_info(self, k8s_host_definition): host_definition_info = HostDefinitionInfo() diff --git a/controllers/servers/host_definer/types.py b/controllers/servers/host_definer/types.py index 7d34433d4..183eae2fd 100644 --- a/controllers/servers/host_definer/types.py +++ b/controllers/servers/host_definer/types.py @@ -55,8 +55,8 @@ class CsiNodeInfo: @dataclass class PodInfo: - name: str = '' - node_name: str = '' + name: str + node_name: str @dataclass From 6892e917ff423e88d27971823f1af0f98a790392 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 15 May 2023 11:49:40 +0300 Subject: [PATCH 4/5] remove default values from StorageClassInfo class Signed-off-by: matancarmeli7 --- .../host_definer/resource_manager/resource_info.py | 8 +++----- controllers/servers/host_definer/types.py | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/controllers/servers/host_definer/resource_manager/resource_info.py b/controllers/servers/host_definer/resource_manager/resource_info.py index bb0363b7f..fb5f12504 100644 --- a/controllers/servers/host_definer/resource_manager/resource_info.py +++ b/controllers/servers/host_definer/resource_manager/resource_info.py @@ -47,11 +47,9 @@ def get_storage_classes_info(self): return storage_classes_info def generate_storage_class_info(self, k8s_storage_class): - storage_class_info = StorageClassInfo() - storage_class_info.name = k8s_storage_class.metadata.name - storage_class_info.provisioner = k8s_storage_class.provisioner - storage_class_info.parameters = k8s_storage_class.parameters - return storage_class_info + return StorageClassInfo( + name=k8s_storage_class.metadata.name, provisioner=k8s_storage_class.provisioner, + parameters=k8s_storage_class.parameters) def get_csi_pods_info(self): pods_info = [] diff --git a/controllers/servers/host_definer/types.py b/controllers/servers/host_definer/types.py index 183eae2fd..bb8cb35cf 100644 --- a/controllers/servers/host_definer/types.py +++ b/controllers/servers/host_definer/types.py @@ -67,9 +67,9 @@ class NodeInfo: @dataclass class StorageClassInfo: - name: str = '' - provisioner: str = '' - parameters: dict = field(default_factory=dict) + name: str + provisioner: str + parameters: dict class ManagedNode: From e316183a8a3129ca6cd5be7d76b3bcc5a4f1ca8e Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 15 May 2023 11:55:22 +0300 Subject: [PATCH 5/5] remove more default values from DefineHostRequest Signed-off-by: matancarmeli7 --- .../servers/host_definer/definition_manager/request.py | 6 ++++-- controllers/servers/host_definer/types.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/controllers/servers/host_definer/definition_manager/request.py b/controllers/servers/host_definer/definition_manager/request.py index 1fdc5e6b6..dec398061 100644 --- a/controllers/servers/host_definer/definition_manager/request.py +++ b/controllers/servers/host_definer/definition_manager/request.py @@ -34,8 +34,10 @@ def _get_new_request(self, secret_name, secret_namespace, labels): array_connection_info = self.secret_manager.get_array_connection_info(secret_name, secret_namespace, labels) if array_connection_info: - return DefineHostRequest(prefix=prefix, connectivity_type_from_user=connectivity_type_from_user, - array_connection_info=array_connection_info) + return DefineHostRequest( + prefix=prefix, connectivity_type_from_user=connectivity_type_from_user, + array_connection_info=array_connection_info, node_id_from_host_definition='', node_id_from_csi_node='', + io_group='') return None def _get_label_value(self, labels, label): diff --git a/controllers/servers/host_definer/types.py b/controllers/servers/host_definer/types.py index bb8cb35cf..278d9620e 100644 --- a/controllers/servers/host_definer/types.py +++ b/controllers/servers/host_definer/types.py @@ -8,9 +8,9 @@ class DefineHostRequest: prefix: str connectivity_type_from_user: str array_connection_info: ArrayConnectionInfo - node_id_from_host_definition: str = '' - node_id_from_csi_node: str = '' - io_group: str = '' + node_id_from_host_definition: str + node_id_from_csi_node: str + io_group: str @dataclass