diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 65f00575958..b9734ff7d2d 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -357,6 +357,43 @@ PROVIDER_CLIENT_DEPLOYMENT_DIR, "native_storage_client.yaml" ) +PROVIDER_CLUSTER_RESOURCE_KINDS = [ + "cephblockpoolradosnamespaces", + "cephblockpoolradosnamespace", + "cephblockpools", + "cephblockpool", + "cephclients", + "cephclient", + "cephclusters", + "cephcluster", + "cephfilesystems", + "cephfilesystem", + "cephfilesystemsubvolumegroups", + "cephfilesystemsubvolumegroup", + "cephobjectstores", + "cephobjectstore", + "cephobjectstoreusers", + "cephobjectstoreuser", + "localvolumediscoveries", + "localvolumediscovery", + "localvolumediscoveryresults", + "localvolumediscoveryresult", + "localvolumes", + "localvolume", + "localvolumesets", + "localvolumeset", + "storageclusters", + "storagecluster", + "storageconsumers", + "storageconsumer", + "storageprofiles", + "storageprofile", + "storagerequests", + "storagerequest", + "storagesystems", + "storagesystem", +] + OCS_CLIENT_OPERATOR_CONTROLLER_MANAGER_PREFIX = "ocs-client-operator-controller-manager" OCS_CLIENT_OPERATOR_CONSOLE = "ocs-client-operator-console" STORAGE_CLIENT_NAME = "storage-client" diff --git a/ocs_ci/ocs/ocp.py b/ocs_ci/ocs/ocp.py index c6c58bae112..70031391615 100644 --- a/ocs_ci/ocs/ocp.py +++ b/ocs_ci/ocs/ocp.py @@ -81,10 +81,33 @@ def __init__( self._data = {} self.selector = selector self.field_selector = field_selector - self.cluster_kubeconfig = cluster_kubeconfig + # In provider mode multicluster run, certain kind of resources are available in the provider cluster only. + # Setting cluster_kubeconfig of provider cluster in such cases will enable running "oc" commands seamlessly even + # when dealing with two instances of this class simultaneously despite the cluster context. This is achievable + # because all the methods use "exec_oc_cmd" method to run "oc" commmands. Primary cluster context being a + # client cluster, the test cases need not switch context to provider cluster before initializing a resource of + # the kinds listed in constants.PROVIDER_CLUSTER_RESOURCE_KINDS + if ( + (not cluster_kubeconfig) + and config.multicluster + and config.ENV_DATA.get("odf_provider_mode_deployment", False) + and kind.lower() in constants.PROVIDER_CLUSTER_RESOURCE_KINDS + ): + provider_cluster_index = config.get_provider_index() + provider_kubeconfig_path = os.path.join( + config.clusters[provider_cluster_index].ENV_DATA["cluster_path"], + config.clusters[provider_cluster_index].RUN.get("kubeconfig_location"), + ) + self.cluster_kubeconfig = provider_kubeconfig_path + # TODO : self.cluster_context = provider_cluster_index, remove cluster_kubeconfig check in if condition + else: + self.cluster_kubeconfig = cluster_kubeconfig self.threading_lock = threading_lock self.silent = silent self.skip_tls_verify = skip_tls_verify + # TODO: Set cluster_context based on the conditions of setting cluster_kubeconfig. Currently, setting + # cluster_context expects the current context to be the cluster where the resource is present. + # This cannot deal with simultaneous usage of two instances in two different clusters. self.cluster_context = config.cluster_ctx.MULTICLUSTER.get("multicluster_index") @property