Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@
ENCRYPTIONKEYROTATIONJOB = "encryptionkeyrotationjobs.csiaddons.openshift.io"
DEFAULT_CEPH_DEVICECLASS = "defaultCephDeviceClass"
CRD_KIND = "CustomResourceDefinition"
# ClientProfileSpec defines the desired state of Ceph CSI
# configuration for volumes and snapshots configured to use
# this profile
CLIENT_PROFILE = "ClientProfile"
OCS_OPERATOR_CONFIG_MAP = "ocs-operator-config"

# Provisioners
Expand Down Expand Up @@ -352,6 +356,9 @@
PROVIDER_MODE_STORAGE_CLASS_CLAIM_RBD = os.path.join(
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "storage_class_claim_rbd.yaml"
)
CLIENT_PROFILE_PATH = os.path.join(
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "client_profile.yaml"
)

MACHINE_CONFIG_YAML = os.path.join(
PROVIDER_MODE_OCS_DEPLOYMENT_PATH,
Expand Down Expand Up @@ -522,7 +529,6 @@

# hyperconverged defaults
HYPERCONVERGED_NAMESPACE = "kubevirt-hyperconverged"
# MCE_NAMESPACE_YAML = os.path.join(TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_namespace.yaml")
TEMPLATE_DEPLOYMENT_DIR_HYPERCONVERGED = os.path.join(
TEMPLATE_DIR, "hyperconverged-deployment"
)
Expand Down
118 changes: 118 additions & 0 deletions ocs_ci/ocs/resources/clientprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import logging
import tempfile

from ocs_ci.ocs import constants, ocp
from ocs_ci.framework import config
from ocs_ci.utility import templating
from ocs_ci.utility.templating import dump_data_to_temp_yaml

logger = logging.getLogger(__name__)


class ClientProfile:
"""
Base ClientProfile class
"""

def __init__(self, client_profile_name, consumer_context):

self.consumer_context = consumer_context
self.name = client_profile_name
self.ocp = ocp.OCP(
resource_name=self.name,
kind=constants.CLIENT_PROFILE,
namespace=config.cluster_ctx.ENV_DATA["cluster_namespace"],
)
if self.consumer_context:
self.provider_context = config.cluster_ctx.MULTICLUSTER[
"multicluster_index"
]
else:
self.provider_context = None

def get_ceph_connection_reference(self):
"""
Get the CephConnectionReference name
Returns:
str: CephConnectionReference name
"""
with config.RunWithConfigContext(self.consumer_context):
return (
self.ocp.get(resource_name=self.name)
.get("spec")
.get("cephConnectionRef")
.get("name")
)

def get_ceph_fs_map(self):
"""
Get the CephFSMap from the client profile
SubVolumeGroup string json:"subVolumeGroup,omitempty"
KernelMountOptions map[string] string `json:"kernelMountOptions,omitempty"`
FuseMountOptions map[string] string `json:"fuseMountOptions,omitempty"`
Starting from ODF 4.19 (Converged) this CR has optional Spec field RadosNamespace.
It is to ensure ceph fs has namespace for storing metadata (OMAP data)
RadosNamespace string(can be nil) json:"radosNamespace,omitempty"
Returns:
dict: CephFSMap
"""
with config.RunWithConfigContext(self.consumer_context):
return self.ocp.get(resource_name=self.name).get("spec").get("cephFs")

def get_rbd_map(self):
"""
Get the RBDMap from the client profile
Returns:
dict: RBDMap
"""
with config.RunWithConfigContext(self.consumer_context):
return self.ocp.get(resource_name=self.name).get("spec").get("rbd")

def get_nfs_map(self):
"""
Get the NFSMap from the client profile
Returns:
dict: NFSMap
"""
with config.RunWithConfigContext(self.consumer_context):
return self.ocp.get(resource_name=self.name).get("spec").get("nfs")

def create_client_profile(
self,
name,
ceph_connection_reference,
ceph_fs_map: dict,
rbd_map: dict,
nfs_map: dict,
):
"""
Create a client profile
Returns:
dict: ClientProfile
"""
with config.RunWithConfigContext(self.consumer_context):
client_profile_data = templating.load_yaml(constants.CLIENT_PROFILE_PATH)
client_profile_data["metadata"]["name"] = name
client_profile_data["spec"]["cephConnectionRef"][
"name"
] = ceph_connection_reference
if ceph_fs_map:
client_profile_data["spec"]["cephFs"] = ceph_fs_map
if rbd_map:
client_profile_data["spec"]["rbd"] = rbd_map
if nfs_map:
client_profile_data["spec"]["nfs"] = nfs_map

client_profile_file = tempfile.NamedTemporaryFile(
mode="w+", prefix="client_profile", delete=False
)
dump_data_to_temp_yaml(client_profile_data, client_profile_file.name)

return self.ocp.create(yaml_file=client_profile_file.name)
2 changes: 1 addition & 1 deletion ocs_ci/ocs/resources/storageconsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StorageConsumer:
Base StorageConsumer class
"""

def __init__(self, consumer_name, consumer_context=None):
def __init__(self, consumer_name, consumer_context):
"""
Starting from ODF 4.19 (Converged) this CR has optional Spec fields:
StorageQuotaInGiB int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: csi.ceph.io/v1alpha1
kind: ClientProfile
metadata:
name: sample-clientprofile
spec:
cephConnectionRef:
name: ocs-storagecluster # by default storageCluster name
cephFs:
# fuseMountOptions provides a user-space file system interface and is often used for mounting file systems like CephFS
fuseMountOptions: {}
kernelMountOptions: {}
# radosNamespace is to ensure ceph fs has namespace for storing metadata (OMAP data)
radosNamespace: {}
subVolumeGroup: {}
nfs: {}
rbd:
radosNamespace: rados-namespace