Skip to content

Commit

Permalink
ClusterLoad: Replace FIO DeploymentConfig with Deployment (#7604)
Browse files Browse the repository at this point in the history
Signed-off-by: Elad Ben Aharon <[email protected]>
  • Loading branch information
ebenahar authored Jul 26, 2023
1 parent 82e2550 commit bda6535
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 30 deletions.
48 changes: 34 additions & 14 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def create_pod(
ports=None,
deploy_pod_status=constants.STATUS_COMPLETED,
subpath=None,
deployment=False,
):
"""
Create a pod
Expand Down Expand Up @@ -268,6 +269,7 @@ def create_pod(
deploy_pod_status (str): Expected status of deploy pod. Applicable
only if dc_deployment is True
subpath (str): Value of subPath parameter in pod yaml
deployment (bool): True for Deployment creation, False otherwise
Returns:
Pod: A Pod instance
Expand All @@ -276,6 +278,7 @@ def create_pod(
AssertionError: In case of any failure
"""

if (
interface_type == constants.CEPHBLOCKPOOL
or interface_type == constants.CEPHBLOCKPOOL_THICK
Expand All @@ -285,20 +288,19 @@ def create_pod(
else:
pod_dict = pod_dict_path if pod_dict_path else constants.CSI_CEPHFS_POD_YAML
interface = constants.CEPHFS_INTERFACE
if dc_deployment:
if dc_deployment or deployment:
pod_dict = pod_dict_path if pod_dict_path else constants.FEDORA_DC_YAML
pod_data = templating.load_yaml(pod_dict)
if not pod_name:
pod_name = create_unique_resource_name(f"test-{interface}", "pod")
pod_data["metadata"]["name"] = pod_name
pod_data["metadata"]["namespace"] = namespace
if dc_deployment:
if dc_deployment or deployment:
pod_data["metadata"]["labels"]["app"] = pod_name
pod_data["spec"]["template"]["metadata"]["labels"]["name"] = pod_name
pod_data["spec"]["replicas"] = replica_count

if pvc_name:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["volumes"][0]["persistentVolumeClaim"][
"claimName"
] = pvc_name
Expand All @@ -313,7 +315,11 @@ def create_pod(
pod_data["spec"]["containers"][0]["ports"][0] = ports

if interface_type == constants.CEPHBLOCKPOOL and raw_block_pv:
if pod_dict_path in [constants.FEDORA_DC_YAML, constants.FIO_DC_YAML]:
if pod_dict_path in [
constants.FEDORA_DC_YAML,
constants.FIO_DC_YAML,
constants.FIO_DEPLOYMENT_YAML,
]:
temp_dict = [
{
"devicePath": raw_block_device,
Expand All @@ -328,7 +334,6 @@ def create_pod(
del pod_data["spec"]["template"]["spec"]["containers"][0][
"volumeMounts"
]

pod_data["spec"]["template"]["spec"]["containers"][0][
"volumeDevices"
] = temp_dict
Expand Down Expand Up @@ -357,40 +362,40 @@ def create_pod(
pod_data.get("spec").get("volumes")[0].get("name")
)
if security_context:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["containers"][0][
"securityContext"
] = security_context
else:
pod_data["spec"]["containers"][0]["securityContext"] = security_context
if command:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["containers"][0]["command"] = command
else:
pod_data["spec"]["containers"][0]["command"] = command
if command_args:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["containers"][0]["args"] = command_args
else:
pod_data["spec"]["containers"][0]["args"] = command_args

if node_name:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["nodeName"] = node_name
else:
pod_data["spec"]["nodeName"] = node_name

if node_selector:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["nodeSelector"] = node_selector
else:
pod_data["spec"]["nodeSelector"] = node_selector

if sa_name and dc_deployment:
if sa_name and (dc_deployment or deployment):
pod_data["spec"]["template"]["spec"]["serviceAccountName"] = sa_name

if subpath:
if dc_deployment:
if dc_deployment or deployment:
pod_data["spec"]["template"]["spec"]["containers"][0]["volumeMounts"][0][
"subPath"
] = subpath
Expand All @@ -415,9 +420,24 @@ def create_pod(
)
dpod_list = pod.get_all_pods(namespace=namespace)
for dpod in dpod_list:
if "-1-deploy" not in dpod.name:
labels = dpod.get().get("metadata").get("labels")
if not any("deployer-pod-for" in label for label in labels):
if pod_name in dpod.name:
return dpod
elif deployment:
deployment_obj = create_resource(**pod_data)
logger.info(deployment_obj.name)
deployment_name = deployment_obj.name
label = f"name={deployment_name}"
assert (ocp.OCP(kind="pod", namespace=namespace)).wait_for_resource(
condition=constants.STATUS_RUNNING,
selector=label,
timeout=360,
sleep=3,
)
pod_dict = pod.get_pods_having_label(label=label, namespace=namespace)[0]
return pod.Pod(**pod_dict)

else:
pod_obj = pod.Pod(**pod_data)
pod_name = pod_data.get("metadata").get("name")
Expand Down
9 changes: 5 additions & 4 deletions ocs_ci/ocs/cluster_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def increase_load(self, rate, wait=True):

# Set new arguments with the updated file size to be used for
# DeploymentConfig of FIO pod creation
fio_dc_data = templating.load_yaml(constants.FIO_DC_YAML)
fio_deployment_data = templating.load_yaml(constants.FIO_DEPLOYMENT_YAML)
args = (
fio_dc_data.get("spec")
fio_deployment_data.get("spec")
.get("template")
.get("spec")
.get("containers")[0]
Expand All @@ -126,11 +126,12 @@ def increase_load(self, rate, wait=True):
new_args.append(f"--rate={rate}")
dc_obj = self.pod_factory(
pvc=pvc_obj,
pod_dict_path=constants.FIO_DC_YAML,
pod_dict_path=constants.FIO_DEPLOYMENT_YAML,
raw_block_pv=True,
deployment_config=True,
service_account=service_account,
command_args=new_args,
status=None,
deployment=True,
)
self.dc_objs.append(dc_obj)
if wait:
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@
FIO_IO_RW_PARAMS_YAML = os.path.join(TEMPLATE_FIO_DIR, "workload_io_rw.yaml")
FIO_IO_FILLUP_PARAMS_YAML = os.path.join(TEMPLATE_FIO_DIR, "workload_io_fillup.yaml")
FIO_DC_YAML = os.path.join(TEMPLATE_FIO_DIR, "fio_dc.yaml")
FIO_DEPLOYMENT_YAML = os.path.join(TEMPLATE_FIO_DIR, "fedora_deployment.yaml")

# fio configuration files
FIO_S3 = os.path.join(TEMPLATE_FIO_DIR, "config_s3.fio")
Expand Down
47 changes: 47 additions & 0 deletions ocs_ci/templates/workloads/fio/fedora_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: fio_deployment_raw_block
labels:
app: fio-benchmark
name: fio_deployment_raw_block
spec:
replicas: 1
selector:
matchLabels:
app: fio_deployment_raw_block
template:
metadata:
labels:
app: fio_deployment_raw_block
spec:
containers:
- name: fio
image: datawiseio/fio:latest
volumeDevices:
- devicePath: /dev/rbdblock
name: my-volume
command:
- /usr/bin/fio
args:
- --name=fio-rand-readwrite
- --filename=/dev/rbdblock
- --readwrite=randrw
- --bs=128K
- --direct=1
- --numjobs=1
- --iodepth=4
- --time_based=1
- --runtime=1000000
- --filesize=1G
- --invalidate=1
- --rwmixread=25
- --rate=15M
- --ioengine=libaio
- --output-format=json
imagePullPolicy: IfNotPresent
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: test-raw-block-pv
3 changes: 0 additions & 3 deletions ocs_ci/templates/workloads/fio/fio_dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ spec:
containers:
- name: fio
image: datawiseio/fio:latest
securityContext:
capabilities:
add: ["SYS_ADMIN"]
volumeDevices:
- devicePath: /dev/rbdblock
name: my-volume
Expand Down
25 changes: 16 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def factory(
command=None,
command_args=None,
subpath=None,
deployment=False,
):
"""
Args:
Expand Down Expand Up @@ -1062,6 +1063,7 @@ def factory(
command_args (list): The arguments to be sent to the command running
on the pod
subpath (str): Value of subPath parameter in pod yaml
deployment (bool): True for Deployment creation, False otherwise
Returns:
object: helpers.create_pod instance
Expand All @@ -1087,24 +1089,29 @@ def factory(
command=command,
command_args=command_args,
subpath=subpath,
deployment=deployment,
)
assert pod_obj, "Failed to create pod"
if deployment_config:
dc_name = pod_obj.get_labels().get("name")
dc_ocp_dict = ocp.OCP(
kind=constants.DEPLOYMENTCONFIG, namespace=pod_obj.namespace
).get(resource_name=dc_name)
dc_obj = OCS(**dc_ocp_dict)
instances.append(dc_obj)

if deployment_config or deployment:
d_name = pod_obj.get_labels().get("name")
d_ocp_dict = ocp.OCP(
kind=constants.DEPLOYMENTCONFIG
if deployment_config
else constants.DEPLOYMENT,
namespace=pod_obj.namespace,
).get(resource_name=d_name)
d_obj = OCS(**d_ocp_dict)
instances.append(d_obj)

else:
instances.append(pod_obj)
if status:
helpers.wait_for_resource_state(pod_obj, status, timeout=300)
pod_obj.reload()
pod_obj.pvc = pvc
if deployment_config:
return dc_obj
if deployment_config or deployment:
return d_obj
return pod_obj

def finalizer():
Expand Down

0 comments on commit bda6535

Please sign in to comment.