Skip to content

Commit 86e700f

Browse files
class and template for client profile (red-hat-storage#11759)
* class and template for clientprofile Signed-off-by: Daniel Osypenko <dosypenk@redhat.com>
1 parent 032bb5a commit 86e700f

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

ocs_ci/ocs/constants.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@
255255
ENCRYPTIONKEYROTATIONJOB = "encryptionkeyrotationjobs.csiaddons.openshift.io"
256256
DEFAULT_CEPH_DEVICECLASS = "defaultCephDeviceClass"
257257
CRD_KIND = "CustomResourceDefinition"
258+
# ClientProfileSpec defines the desired state of Ceph CSI
259+
# configuration for volumes and snapshots configured to use
260+
# this profile
261+
CLIENT_PROFILE = "ClientProfile"
258262
OCS_OPERATOR_CONFIG_MAP = "ocs-operator-config"
259263
SERVICE_TYPE_NODEPORT = "NodePort"
260264

@@ -353,6 +357,9 @@
353357
PROVIDER_MODE_STORAGE_CLASS_CLAIM_RBD = os.path.join(
354358
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "storage_class_claim_rbd.yaml"
355359
)
360+
CLIENT_PROFILE_PATH = os.path.join(
361+
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "client_profile.yaml"
362+
)
356363

357364
MACHINE_CONFIG_YAML = os.path.join(
358365
PROVIDER_MODE_OCS_DEPLOYMENT_PATH,
@@ -523,7 +530,6 @@
523530

524531
# hyperconverged defaults
525532
HYPERCONVERGED_NAMESPACE = "kubevirt-hyperconverged"
526-
# MCE_NAMESPACE_YAML = os.path.join(TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_namespace.yaml")
527533
TEMPLATE_DEPLOYMENT_DIR_HYPERCONVERGED = os.path.join(
528534
TEMPLATE_DIR, "hyperconverged-deployment"
529535
)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import logging
2+
import tempfile
3+
4+
from ocs_ci.ocs import constants, ocp
5+
from ocs_ci.framework import config
6+
from ocs_ci.utility import templating
7+
from ocs_ci.utility.templating import dump_data_to_temp_yaml
8+
9+
logger = logging.getLogger(__name__)
10+
11+
12+
class ClientProfile:
13+
"""
14+
Base ClientProfile class
15+
"""
16+
17+
def __init__(self, client_profile_name, consumer_context):
18+
19+
self.consumer_context = consumer_context
20+
self.name = client_profile_name
21+
self.ocp = ocp.OCP(
22+
resource_name=self.name,
23+
kind=constants.CLIENT_PROFILE,
24+
namespace=config.cluster_ctx.ENV_DATA["cluster_namespace"],
25+
)
26+
if self.consumer_context:
27+
self.provider_context = config.cluster_ctx.MULTICLUSTER[
28+
"multicluster_index"
29+
]
30+
else:
31+
self.provider_context = None
32+
33+
def get_ceph_connection_reference(self):
34+
"""
35+
Get the CephConnectionReference name
36+
37+
Returns:
38+
str: CephConnectionReference name
39+
"""
40+
with config.RunWithConfigContext(self.consumer_context):
41+
return (
42+
self.ocp.get(resource_name=self.name)
43+
.get("spec")
44+
.get("cephConnectionRef")
45+
.get("name")
46+
)
47+
48+
def get_ceph_fs_map(self):
49+
"""
50+
Get the CephFSMap from the client profile
51+
52+
SubVolumeGroup string json:"subVolumeGroup,omitempty"
53+
KernelMountOptions map[string] string `json:"kernelMountOptions,omitempty"`
54+
FuseMountOptions map[string] string `json:"fuseMountOptions,omitempty"`
55+
56+
Starting from ODF 4.19 (Converged) this CR has optional Spec field RadosNamespace.
57+
It is to ensure ceph fs has namespace for storing metadata (OMAP data)
58+
RadosNamespace string(can be nil) json:"radosNamespace,omitempty"
59+
60+
Returns:
61+
dict: CephFSMap
62+
"""
63+
with config.RunWithConfigContext(self.consumer_context):
64+
return self.ocp.get(resource_name=self.name).get("spec").get("cephFs")
65+
66+
def get_rbd_map(self):
67+
"""
68+
Get the RBDMap from the client profile
69+
70+
Returns:
71+
dict: RBDMap
72+
"""
73+
with config.RunWithConfigContext(self.consumer_context):
74+
return self.ocp.get(resource_name=self.name).get("spec").get("rbd")
75+
76+
def get_nfs_map(self):
77+
"""
78+
Get the NFSMap from the client profile
79+
80+
Returns:
81+
dict: NFSMap
82+
"""
83+
with config.RunWithConfigContext(self.consumer_context):
84+
return self.ocp.get(resource_name=self.name).get("spec").get("nfs")
85+
86+
def create_client_profile(
87+
self,
88+
name,
89+
ceph_connection_reference,
90+
ceph_fs_map: dict,
91+
rbd_map: dict,
92+
nfs_map: dict,
93+
):
94+
"""
95+
Create a client profile
96+
97+
Returns:
98+
dict: ClientProfile
99+
"""
100+
with config.RunWithConfigContext(self.consumer_context):
101+
client_profile_data = templating.load_yaml(constants.CLIENT_PROFILE_PATH)
102+
client_profile_data["metadata"]["name"] = name
103+
client_profile_data["spec"]["cephConnectionRef"][
104+
"name"
105+
] = ceph_connection_reference
106+
if ceph_fs_map:
107+
client_profile_data["spec"]["cephFs"] = ceph_fs_map
108+
if rbd_map:
109+
client_profile_data["spec"]["rbd"] = rbd_map
110+
if nfs_map:
111+
client_profile_data["spec"]["nfs"] = nfs_map
112+
113+
client_profile_file = tempfile.NamedTemporaryFile(
114+
mode="w+", prefix="client_profile", delete=False
115+
)
116+
dump_data_to_temp_yaml(client_profile_data, client_profile_file.name)
117+
118+
return self.ocp.create(yaml_file=client_profile_file.name)

ocs_ci/ocs/resources/storageconsumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StorageConsumer:
2121
Base StorageConsumer class
2222
"""
2323

24-
def __init__(self, consumer_name, consumer_context=None):
24+
def __init__(self, consumer_name, consumer_context):
2525
"""
2626
Starting from ODF 4.19 (Converged) this CR has optional Spec fields:
2727
StorageQuotaInGiB int
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: csi.ceph.io/v1alpha1
2+
kind: ClientProfile
3+
metadata:
4+
name: sample-clientprofile
5+
spec:
6+
cephConnectionRef:
7+
name: ocs-storagecluster # by default storageCluster name
8+
cephFs:
9+
# fuseMountOptions provides a user-space file system interface and is often used for mounting file systems like CephFS
10+
fuseMountOptions: {}
11+
kernelMountOptions: {}
12+
# radosNamespace is to ensure ceph fs has namespace for storing metadata (OMAP data)
13+
radosNamespace: {}
14+
subVolumeGroup: {}
15+
nfs: {}
16+
rbd:
17+
radosNamespace: rados-namespace

0 commit comments

Comments
 (0)