Skip to content

Commit 982c6b1

Browse files
class and template for clientprofile
Signed-off-by: Daniel Osypenko <dosypenk@redhat.com>
1 parent 1546da4 commit 982c6b1

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

ocs_ci/ocs/constants.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@
250250
ENCRYPTIONKEYROTATIONJOB = "encryptionkeyrotationjobs.csiaddons.openshift.io"
251251
DEFAULT_CEPH_DEVICECLASS = "defaultCephDeviceClass"
252252
CRD_KIND = "CustomResourceDefinition"
253+
"""
254+
ClientProfileSpec defines the desired state of Ceph CSI
255+
configuration for volumes and snapshots configured to use
256+
this profile
257+
"""
258+
CLIENT_PROFILE = "ClientProfile"
253259

254260
# Provisioners
255261
AWS_EFS_PROVISIONER = "openshift.org/aws-efs"
@@ -346,6 +352,9 @@
346352
PROVIDER_MODE_STORAGE_CLASS_CLAIM_RBD = os.path.join(
347353
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "storage_class_claim_rbd.yaml"
348354
)
355+
CLIENT_PROFILE_PATH = os.path.join(
356+
PROVIDER_MODE_OCS_DEPLOYMENT_PATH, "client_profile.yaml"
357+
)
349358

350359
MACHINE_CONFIG_YAML = os.path.join(
351360
PROVIDER_MODE_OCS_DEPLOYMENT_PATH,
@@ -512,7 +521,6 @@
512521

513522
# hyperconverged defaults
514523
HYPERCONVERGED_NAMESPACE = "kubevirt-hyperconverged"
515-
# MCE_NAMESPACE_YAML = os.path.join(TEMPLATE_DEPLOYMENT_DIR_MCE, "mce_namespace.yaml")
516524
TEMPLATE_DEPLOYMENT_DIR_HYPERCONVERGED = os.path.join(
517525
TEMPLATE_DIR, "hyperconverged-deployment"
518526
)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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=None):
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+
with config.RunWithConfigContext(self.consumer_context):
38+
return (
39+
self.ocp.get(resource_name=self.name)
40+
.get("spec")
41+
.get("cephConnectionRef")
42+
.get("name")
43+
)
44+
45+
def get_ceph_fs_map(self):
46+
"""
47+
Get the CephFSMap from the client profile
48+
49+
SubVolumeGroup string `json:"subVolumeGroup,omitempty"`
50+
KernelMountOptions map[string] string `json:"kernelMountOptions,omitempty"`
51+
FuseMountOptions map[string] string `json:"fuseMountOptions,omitempty"`
52+
53+
Starting from ODF 4.19 (Converged) this CR has optional Spec field RadosNamespace.
54+
It is to ensure ceph fs has namespace for storing metadata (OMAP data)
55+
RadosNamespace *string `json:"radosNamespace,omitempty"`
56+
"""
57+
with config.RunWithConfigContext(self.consumer_context):
58+
return self.ocp.get(resource_name=self.name).get("spec").get("cephFs")
59+
60+
def get_rbd_map(self):
61+
"""
62+
Get the RBDMap from the client profile
63+
64+
radosNamespace string `json:"radosNamespace,omitempty"
65+
"""
66+
with config.RunWithConfigContext(self.consumer_context):
67+
return self.ocp.get(resource_name=self.name).get("spec").get("rbd")
68+
69+
def get_nfs_map(self):
70+
"""
71+
Get the NFSMap from the client profile
72+
73+
"""
74+
with config.RunWithConfigContext(self.consumer_context):
75+
return self.ocp.get(resource_name=self.name).get("spec").get("nfs")
76+
77+
def create_client_profile(
78+
self,
79+
name,
80+
ceph_connection_reference,
81+
ceph_fs_map: dict,
82+
rbd_map: dict,
83+
nfs_map: dict,
84+
):
85+
"""
86+
Create a client profile
87+
"""
88+
with config.RunWithConfigContext(self.consumer_context):
89+
client_profile_data = templating.load_yaml(constants.CLIENT_PROFILE_PATH)
90+
client_profile_data["metadata"]["name"] = name
91+
client_profile_data["spec"]["cephConnectionRef"][
92+
"name"
93+
] = ceph_connection_reference
94+
if ceph_fs_map:
95+
client_profile_data["spec"]["cephFs"] = ceph_fs_map
96+
if rbd_map:
97+
client_profile_data["spec"]["rbd"] = rbd_map
98+
if nfs_map:
99+
client_profile_data["spec"]["nfs"] = nfs_map
100+
101+
client_profile_file = tempfile.NamedTemporaryFile(
102+
mode="w+", prefix="client_profile", delete=False
103+
)
104+
dump_data_to_temp_yaml(client_profile_data, client_profile_file.name)
105+
106+
return self.ocp.create(yaml_file=client_profile_file.name)
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)