Skip to content

Commit

Permalink
Set cluster_kubeconfig based on the type of resource available in pro…
Browse files Browse the repository at this point in the history
…vider cluster only (red-hat-storage#10172)

In provider mode multicluster run, set 'cluster_kubeconfig' if the resource kind is available only in provider cluster.

Created a primary list of 'Kind' which are available in provider cluster.
Set the cluster_kubeconfig value to provider cluster kubeconfig path if the Kind is available in the list.

Signed-off-by: Jilju Joy <[email protected]>
  • Loading branch information
jilju authored Sep 20, 2024
1 parent 7c13e43 commit b452aaa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
37 changes: 37 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 24 additions & 1 deletion ocs_ci/ocs/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b452aaa

Please sign in to comment.