Skip to content

Commit bea9bc9

Browse files
use ticketgen script with quota
Signed-off-by: Daniel Osypenko <[email protected]>
1 parent 9c0a67c commit bea9bc9

8 files changed

+80
-13
lines changed

conf/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ higher priority).
349349
* `hosted_odf_registry` - registry for hosted ODF (default: quay.io/rhceph-dev/ocs-registry)
350350
* `hosted_odf_version` - version of ODF to be deployed on hosted clusters
351351
* `cp_availability_policy` - "HighlyAvailable" or "SingleReplica"; if not provided the default value is "SingleReplica"
352+
* `storage_quota` - storage quota for the hosted cluster
352353
* `wait_timeout_for_healthy_osd_in_minutes` - timeout waiting for healthy OSDs before continuing upgrade (see https://bugzilla.redhat.com/show_bug.cgi?id=2276694 for more details)
353354
* `osd_maintenance_timeout` - is a duration in minutes that determines how long an entire failureDomain like region/zone/host will be held in noout
354355
* `odf_provider_mode_deployment` - True if you would like to enable provider mode deployment.

conf/examples/provider_mode_ibm_cloud_baremetal_kubevirt_clients.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ENV_DATA:
3232
setup_storage_client: true # if true, the Storage Client will be created and verification will be performed
3333
nodepool_replicas: 3 # number of worker nodes created for Hosted cluster
3434
cp_availability_policy: "HighlyAvailable" # this field is optional, if not provided the default value is "SingleReplica"
35+
storage_quota: 100 # int. 100 means "100Gi". this field is optional, if not provided client will have unlimited storage quota
3536
hcp415-bm3-f:
3637
hosted_cluster_path: "~/clusters/hcp416-bm3-f/openshift-cluster-dir" # path to store auth_path dir or cluster related files
3738
ocp_version: "4.15.10" # this is an example, please provide the desired OCP version

ocs_ci/deployment/deployment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def do_deploy_mce(self):
464464
"""
465465
if config.ENV_DATA["skip_ocs_deployment"]:
466466

467-
if config.DEPLOYMENT.get("deploy_mce"):
467+
if config.ENV_DATA.get("deploy_mce"):
468468
mce_installer = MCEInstaller()
469469
mce_installer.deploy_mce()
470470

ocs_ci/deployment/hosted_cluster.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ def __init__(self, name: str):
632632
constants.PROVIDER_MODE_STORAGE_CLIENT
633633
)
634634
self.storage_client_name = storage_client_data["metadata"]["name"]
635+
self.storage_quota = (
636+
config.ENV_DATA.get("clusters", {})
637+
.get(self.name, {})
638+
.get("storage_quota", None)
639+
)
635640

636641
@kubeconfig_exists_decorator
637642
def exec_oc_cmd(self, cmd, timeout=300, ignore_error=False, **kwargs):
@@ -976,7 +981,11 @@ def get_onboarding_key(self):
976981
)
977982

978983
try:
979-
token = generate_onboarding_token(private_key=decoded_key)
984+
token = generate_onboarding_token(
985+
private_key=decoded_key,
986+
use_ticketgen_with_quota=True,
987+
storage_quota=self.storage_quota,
988+
)
980989
except Exception as e:
981990
logger.error(f"Error during onboarding token generation: {e}")
982991
token = ""

ocs_ci/deployment/hyperconverged.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import semantic_version
33

4-
from ocs_ci.ocs.exceptions import HyperConvergedNotDeployedException
4+
from ocs_ci.ocs.exceptions import HyperConvergedNotDeployedException, CommandFailed
55
from ocs_ci.ocs.ocp import OCP
66
from ocs_ci.ocs import constants
77
from ocs_ci.ocs.resources.deployment import Deployment
@@ -11,6 +11,7 @@
1111
from ocs_ci.ocs.version import get_ocp_version
1212
from ocs_ci.utility import templating
1313
from ocs_ci.ocs.resources.catalog_source import CatalogSource
14+
from ocs_ci.utility.retry import retry
1415
from ocs_ci.utility.utils import wait_custom_resource_defenition_available
1516

1617
logger = logging.getLogger(__name__)
@@ -147,7 +148,10 @@ def create_hyperconverged_instance(self):
147148
constants.HYPERCONVERGED_YAML
148149
)
149150
hyperconverged_instance_yaml = OCS(**hyperconverged_instance_yaml_file)
150-
hyperconverged_instance_yaml.create()
151+
retry(CommandFailed, tries=10, delay=60)(
152+
hyperconverged_instance_yaml.create
153+
)()
154+
151155
self.hyperconverged.check_resource_existence(
152156
should_exist=True, resource_name=constants.HYPERCONVERGED_NAME
153157
)

ocs_ci/deployment/mce.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ def deploy_mce(self):
239239
qe_app_registry.icsp()
240240
qe_app_registry.catalog_source()
241241
self.create_mce_namespace()
242+
self.create_multiclusterengine_operatorgroup()
242243
self.create_mce_subscription()
243244
if not wait_custom_resource_defenition_available(
244245
constants.MULTICLUSTER_ENGINE_CRD
245246
):
246247
raise MultiClusterEngineNotDeployedException(
247248
f"crd {constants.MULTICLUSTER_ENGINE_CRD} is unavailable"
248249
)
249-
self.create_multiclusterengine_operatorgroup()
250250

251251
# check whether mce instance is created, if it is installed but mce don't pass validation we can not heal it in
252252
# script here, hence no sense for full validation of mce

ocs_ci/templates/mce-deployment/mce_subscription.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ kind: Subscription
33
metadata:
44
name: multicluster-engine
55
namespace: multicluster-engine
6+
labels:
7+
operators.coreos.com/multicluster-engine.multicluster-engine: ""
68
spec:
79
channel: stable-2.8
810
installPlanApproval: Automatic
911
name: multicluster-engine
1012
source: qe-app-registry
1113
sourceNamespace: openshift-marketplace
14+
startingCSV: multicluster-engine.v2.8.0

ocs_ci/utility/managedservice.py

+57-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import stat
4+
from pathlib import Path
45

56
from tempfile import NamedTemporaryFile
67

@@ -12,7 +13,12 @@
1213
logger = logging.getLogger(__name__)
1314

1415

15-
def generate_onboarding_token(private_key: str = None):
16+
def generate_onboarding_token(
17+
private_key: str = None,
18+
use_ticketgen_with_quota: bool = False,
19+
subject_role: str = None,
20+
storage_quota: int = None,
21+
):
1622
"""
1723
Generate Onboarding token for consumer cluster via following steps:
1824
@@ -27,6 +33,9 @@ def generate_onboarding_token(private_key: str = None):
2733
2834
Args:
2935
private_key (str): private key for Managed Service
36+
use_ticketgen_with_quota (bool): If True, the ticketgen.sh script will be run with -q flag
37+
subject_role (str): Role of the subject, this role has a default in ticketgen-with-quota.sh - ocs-client
38+
storage_quota (int): Quota for the storage cluster
3039
3140
Raises:
3241
CommandFailed: In case the script ticketgen.sh fails.
@@ -38,12 +47,31 @@ def generate_onboarding_token(private_key: str = None):
3847
"""
3948
logger.debug("Generate onboarding token for ODF to ODF deployment")
4049
ticketgen_script_path = os.path.join(constants.DATA_DIR, "ticketgen.sh")
41-
# download ticketgen.sh script
42-
logger.debug("Download and prepare ticketgen.sh script")
43-
download_file(
44-
"https://raw.githubusercontent.com/red-hat-storage/ocs-operator/main/hack/ticketgen/ticketgen.sh",
45-
ticketgen_script_path,
46-
)
50+
51+
if not use_ticketgen_with_quota:
52+
logger.debug("Download and prepare ticketgen.sh script")
53+
download_file(
54+
"https://raw.githubusercontent.com/red-hat-storage/ocs-operator/main/hack/ticketgen/ticketgen.sh",
55+
ticketgen_script_path,
56+
)
57+
if not Path(ticketgen_script_path).exists():
58+
raise FileNotFoundError(
59+
f"Failed to download ticketgen.sh script to {ticketgen_script_path}"
60+
)
61+
else:
62+
logger.info("using ticketgen.sh script with --quota flag")
63+
script_path = (
64+
Path(__file__).resolve().parents[2]
65+
/ "scripts"
66+
/ "bash"
67+
/ "ticketgen-with-quota.sh"
68+
)
69+
if not script_path.exists():
70+
raise FileNotFoundError(
71+
f"Failed to find ticketgen-with-quota.sh script in {script_path}"
72+
)
73+
ticketgen_script_path = str(script_path)
74+
4775
# add execute permission to the ticketgen.sh script
4876
current_file_permissions = os.stat(ticketgen_script_path)
4977
os.chmod(
@@ -67,13 +95,34 @@ def generate_onboarding_token(private_key: str = None):
6795
' private_key: "..."\n'
6896
' public_key: "..."'
6997
)
98+
99+
script_cmd = f"{ticketgen_script_path}"
100+
101+
if use_ticketgen_with_quota:
102+
103+
from ocs_ci.ocs.ocp import OCP
104+
105+
sc_obj = OCP(
106+
kind=constants.STORAGECLUSTER,
107+
namespace=config.ENV_DATA["cluster_namespace"],
108+
)
109+
uid = sc_obj.get()["items"][0]["metadata"]["uid"]
110+
script_cmd += f" -c {uid} "
111+
112+
if subject_role:
113+
script_cmd += f" -r {subject_role}"
114+
if storage_quota:
115+
script_cmd += f" -q {storage_quota}"
116+
70117
with NamedTemporaryFile(
71118
mode="w", prefix="private", suffix=".pem", delete=True
72119
) as key_file:
73120
key_file.write(private_key)
74121
key_file.flush()
75122
logger.debug("Generate Onboarding token")
76-
ticketgen_result = exec_cmd(f"{ticketgen_script_path} {key_file.name}")
123+
script_cmd += f" {key_file.name}"
124+
ticketgen_result = exec_cmd(script_cmd)
125+
77126
ticketgen_output = ticketgen_result.stdout.decode()
78127
if ticketgen_result.stderr:
79128
raise CommandFailed(

0 commit comments

Comments
 (0)