From 0afd2b21e86f9dc08f562ab48afdfb51c14aa24d Mon Sep 17 00:00:00 2001 From: oviner Date: Sun, 26 Nov 2023 13:03:40 +0200 Subject: [PATCH] Create Cluster via ACM Signed-off-by: oviner --- ocs_ci/framework/__init__.py | 1 + ocs_ci/framework/conf/default_config.yaml | 12 + .../framework/pytest_customization/marks.py | 2 + ocs_ci/helpers/helpers.py | 19 + ocs_ci/ocs/acm/acm.py | 378 ++++++++++++++++++ ocs_ci/ocs/constants.py | 17 + ocs_ci/ocs/utils.py | 33 ++ .../acm-deployment/cluster-deployment.yaml | 37 ++ .../acm-deployment/install-config.yaml | 48 +++ .../klusterlet-addon-config.yaml | 18 +- .../acm-deployment/machine-pool.yaml | 18 + .../acm-deployment/managed-cluster.yaml | 8 +- ocs_ci/templates/acm-deployment/secret.yaml | 7 + .../acm-deployment/vsphere_credential.yaml | 30 ++ tests/functional/deployment/test_acm.py | 34 +- 15 files changed, 651 insertions(+), 11 deletions(-) create mode 100644 ocs_ci/templates/acm-deployment/cluster-deployment.yaml create mode 100644 ocs_ci/templates/acm-deployment/install-config.yaml create mode 100644 ocs_ci/templates/acm-deployment/machine-pool.yaml create mode 100644 ocs_ci/templates/acm-deployment/secret.yaml create mode 100644 ocs_ci/templates/acm-deployment/vsphere_credential.yaml diff --git a/ocs_ci/framework/__init__.py b/ocs_ci/framework/__init__.py index 18e73ffbf34c..1d2993001914 100644 --- a/ocs_ci/framework/__init__.py +++ b/ocs_ci/framework/__init__.py @@ -36,6 +36,7 @@ class Config: COMPONENTS: dict = field(default_factory=dict) # Used for multicluster only MULTICLUSTER: dict = field(default_factory=dict) + ACM_CONFIG: dict = field(default_factory=dict) def __post_init__(self): self.reset() diff --git a/ocs_ci/framework/conf/default_config.yaml b/ocs_ci/framework/conf/default_config.yaml index 63c73c5f16fd..0fd50acb703f 100644 --- a/ocs_ci/framework/conf/default_config.yaml +++ b/ocs_ci/framework/conf/default_config.yaml @@ -342,3 +342,15 @@ MULTICLUSTER: acm_cluster: False primary_cluster: False active_acm_cluster: False + +ACM_CONFIG: + ocp_image: "img4.14.3-multi-appsub" + cpus: 16 + coresPerSocket: 2 + memoryMB: 65536 + diskSizeGB: 120 + replicas: 3 + clusternetwork_cidr: 10.128.0.0/14 + clusternetwork_hostprefix: 23 + servicenetwork: 172.30.0.0/16 + networktype: OVNKubernetes diff --git a/ocs_ci/framework/pytest_customization/marks.py b/ocs_ci/framework/pytest_customization/marks.py index c2690b82781f..0539840a0bed 100644 --- a/ocs_ci/framework/pytest_customization/marks.py +++ b/ocs_ci/framework/pytest_customization/marks.py @@ -82,6 +82,8 @@ polarion_id = pytest.mark.polarion_id bugzilla = pytest.mark.bugzilla acm_import = pytest.mark.acm_import +acm_install = pytest.mark.acm_install + tier_marks = [ tier1, diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index 979344d8bc59..0b1b4def603c 100644 --- a/ocs_ci/helpers/helpers.py +++ b/ocs_ci/helpers/helpers.py @@ -4449,3 +4449,22 @@ def check_selinux_relabeling(pod_obj): key = '"selinuxRelabel": false' assert key in output, f"{key} is not present in inspect logs" logger.info(f"{key} is present in inspect logs of application pod running node") + + +def get_secret_obj(name, namespace): + """ + Get Secret obj by name + + Args: + name (str): the name secret + namespace (str): the namespace + + Returns: + ocp object: ocp object of secret + + """ + return OCP( + kind="secret", + namespace=namespace, + resource_name=name, + ).get() diff --git a/ocs_ci/ocs/acm/acm.py b/ocs_ci/ocs/acm/acm.py index 592cc33a44aa..c781b689bc50 100644 --- a/ocs_ci/ocs/acm/acm.py +++ b/ocs_ci/ocs/acm/acm.py @@ -3,6 +3,9 @@ import os import tempfile import requests +import yaml +import copy +import base64 from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as ec @@ -40,6 +43,9 @@ from ocs_ci.utility import templating from ocs_ci.ocs.resources.ocs import OCS from ocs_ci.helpers.helpers import create_project +from ocs_ci.ocs.utils import get_secret_name_by_pattern, get_all_acm_indexes +from ocs_ci.helpers.helpers import get_secret_obj + log = logging.getLogger(__name__) @@ -619,3 +625,375 @@ def import_clusters_with_acm(): ) else: import_clusters_via_cli(clusters) + + +class CreateClusterViaACM(object): + """ + Create cluster via ACM + + """ + + def __init__(self): + self.cluster_name = config.ENV_DATA["cluster_name"] + + ssh_priv_key_path = os.path.expanduser(config.DEPLOYMENT["ssh_key_private"]) + with open(ssh_priv_key_path, "r") as fp: + self.ssh_priv_key = fp.read() + + ssh_public_key_path = os.path.expanduser(config.DEPLOYMENT["ssh_key"]) + with open(ssh_public_key_path, "r") as fp: + self.ssh_public_key = fp.read() + + with open(constants.VSPHERE_CA_FILE_PATH, "r") as fp: + self.vsphere_ca = fp.read() + + with open(os.path.join(constants.DATA_DIR, "pull-secret"), "r") as fp: + self.pull_secret = fp.read() + + self.ips = ["a", "b"] + + self.secret_yaml = templating.load_yaml(constants.ACM_SECRET_YAML) + self.manifest_location = tempfile.NamedTemporaryFile( + mode="w+", prefix="create-cluster-", delete=False + ) + self.file_paths = list() + + def create_credential(self): + """ + Create credential + + """ + with RunWithConfigContext(): + cred_vsphere = templating.load_yaml(constants.ACM_VSPHERE_CRED_YAML) + cred_vsphere["stringData"]["vCenter"] = config.ENV_DATA["vsphere_server"] + cred_vsphere["stringData"]["username"] = config.ENV_DATA["vsphere_user"] + cred_vsphere["stringData"]["password"] = config.ENV_DATA["vsphere_password"] + cred_vsphere["stringData"]["cacertificate"] = self.vsphere_ca + + cred_vsphere["stringData"]["cluster"] = config.ENV_DATA["vsphere_cluster"] + cred_vsphere["stringData"]["datacenter"] = config.ENV_DATA[ + "vsphere_datacenter" + ] + cred_vsphere["stringData"]["defaultDatastore"] = config.ENV_DATA[ + "vsphere_datastore" + ] + cred_vsphere["stringData"]["baseDomain"] = config.ENV_DATA["base_domain"] + cred_vsphere["stringData"]["ssh-privatekey"] = self.ssh_priv_key + + cred_vsphere["stringData"]["ssh-publickey"] = self.ssh_public_key + manifest = tempfile.NamedTemporaryFile( + mode="w+", prefix="manifest-", delete=False + ) + logging.info(f"Tmp file name: {manifest.name}") + templating.dump_data_to_temp_yaml(cred_vsphere, manifest.name) + run_cmd(f"oc apply -f {manifest.name}") + + def set_install_config(self): + """ + Set Install Config + + """ + install_config = templating.load_yaml(constants.ACM_VSPHERE_INSTALL_CONFIG_YAML) + install_config["baseDomain"] = config.ENV_DATA["base_domain"] + install_config["platform"]["vsphere"]["vCenter"] = config.ENV_DATA[ + "vsphere_server" + ] + install_config["platform"]["vsphere"]["username"] = config.ENV_DATA[ + "vsphere_user" + ] + install_config["platform"]["vsphere"]["password"] = config.ENV_DATA[ + "vsphere_password" + ] + install_config["platform"]["vsphere"]["datacenter"] = config.ENV_DATA[ + "vsphere_datacenter" + ] + install_config["platform"]["vsphere"]["defaultDatastore"] = config.ENV_DATA[ + "vsphere_datastore" + ] + install_config["platform"]["vsphere"]["cluster"] = config.ENV_DATA[ + "vsphere_server" + ] + install_config["networking"]["networkType"] = config.ACM_CONFIG["networktype"] + install_config["networking"]["clusterNetwork"][0]["cidr"] = config.ACM_CONFIG[ + "clusternetwork_cidr" + ] + install_config["networking"]["clusterNetwork"][0][ + "hostPrefix" + ] = config.ACM_CONFIG["clusternetwork_hostprefix"] + install_config["networking"]["machineNetwork"][0]["cidr"] = config.ENV_DATA[ + "machine_cidr" + ] + install_config["networking"]["serviceNetwork"][0] = config.ACM_CONFIG[ + "servicenetwork" + ] + install_config["platform"]["vsphere"]["apiVIP"] = self.ips[0] + install_config["platform"]["vsphere"]["ingressVIP"] = self.ips[1] + install_config["sshKey"] = self.ssh_public_key + self.install_config_yaml = yaml.dump(install_config, default_flow_style=False) + + def set_managed_cluster(self): + """ + Set managed_cluster + + """ + log.info("Creating ManagedCluster configuration") + managed_cluster = templating.load_yaml(constants.ACM_MANAGEDCLUSTER_YAML) + managed_cluster["metadata"]["labels"]["cloud"] = "vSphere" + managed_cluster["metadata"]["labels"]["name"] = self.cluster_name + managed_cluster["metadata"]["labels"]["vendor"] = "OpenShift" + managed_cluster["metadata"]["name"] = self.cluster_name + self.apply_manifest(managed_cluster) + + def set_cluster_deployment(self): + """ + Set cluster deployment + + """ + log.info("Creating ClusterDeployment configuration") + cluster_deployment = templating.load_yaml(constants.ACM_CLUSTER_DEPLOYMENT) + cluster_deployment["metadata"]["name"] = self.cluster_name + cluster_deployment["metadata"]["namespace"] = self.cluster_name + cluster_deployment["metadata"]["labels"]["cloud"] = "vSphere" + cluster_deployment["metadata"]["labels"]["vendor"] = "OpenShift" + + cluster_deployment["spec"]["baseDomain"] = config.ENV_DATA["base_domain"] + cluster_deployment["spec"]["clusterName"] = self.cluster_name + + cluster_deployment["spec"]["platform"]["vsphere"]["cluster"] = config.ENV_DATA[ + "vsphere_cluster" + ] + cluster_deployment["spec"]["platform"]["vsphere"]["certificatesSecretRef"][ + "name" + ] = f"{self.cluster_name}-vsphere-certs" + + cluster_deployment["spec"]["platform"]["vsphere"]["credentialsSecretRef"][ + "name" + ] = f"{self.cluster_name}-vsphere-creds" + cluster_deployment["spec"]["platform"]["vsphere"]["vCenter"] = config.ENV_DATA[ + "vsphere_server" + ] + + cluster_deployment["spec"]["platform"]["vsphere"][ + "datacenter" + ] = config.ENV_DATA["vsphere_datacenter"] + cluster_deployment["spec"]["platform"]["vsphere"][ + "defaultDatastore" + ] = config.ENV_DATA["vsphere_datastore"] + cluster_deployment["spec"]["platform"]["vsphere"]["network"] = config.ENV_DATA[ + "vm_network" + ] + cluster_deployment["spec"]["provisioning"]["installConfigSecretRef"][ + "name" + ] = f"{self.cluster_name}-install-config" + cluster_deployment["spec"]["provisioning"]["sshPrivateKeySecretRef"][ + "name" + ] = f"{self.cluster_name}-ssh-private-key" + cluster_deployment["spec"]["provisioning"]["imageSetRef"][ + "name" + ] = config.ACM_CONFIG["ocp_image"] + cluster_deployment["spec"]["pullSecretRef"][ + "name" + ] = f"{self.cluster_name}-pull-secret" + self.apply_manifest(cluster_deployment) + + def set_machine_pool(self): + """ + Set machine pool + + """ + log.info("Creating MachinePool configuration") + machine_pool = templating.load_yaml(constants.ACM_MACHINE_POOL_YAML) + machine_pool["metadata"]["name"] = f"{self.cluster_name}-worker" + machine_pool["metadata"]["namespace"] = self.cluster_name + machine_pool["spec"]["clusterDeploymentRef"]["name"] = self.cluster_name + machine_pool["spec"]["name"] = "worker" + self.apply_manifest(machine_pool) + + def set_klusterlet_config(self): + """ + Set klusterlet config + + """ + log.info("Creating klusterlet addon configuration") + klusterlet_config = templating.load_yaml(constants.ACM_HUB_KLUSTERLET_YAML) + klusterlet_config["metadata"]["name"] = self.cluster_name + klusterlet_config["metadata"]["namespace"] = self.cluster_name + klusterlet_config["spec"]["clusterName"] = self.cluster_name + klusterlet_config["spec"]["clusterNamespace"] = self.cluster_name + klusterlet_config["spec"]["clusterLabels"]["cloud"] = "vSphere" + klusterlet_config["spec"]["clusterLabels"]["vendor"] = "OpenShift" + self.apply_manifest(klusterlet_config) + + def set_secret1(self): + secret1 = copy.deepcopy(self.secret_yaml) + secret1["metadata"]["name"] = f"{self.cluster_name}-pull-secret" + secret1["metadata"]["namespace"] = self.cluster_name + secret1["stringData"] = {".dockerconfigjson": self.pull_secret} + secret1["type"] = "kubernetes.io/dockerconfigjson" + self.apply_manifest(secret1) + + def set_secret2(self): + secret2 = copy.deepcopy(self.secret_yaml) + secret2["metadata"]["name"] = f"{self.cluster_name}-install-config" + secret2["metadata"]["namespace"] = self.cluster_name + encoded_install_config_yaml = base64.b64encode( + self.install_config_yaml.encode("utf-8") + ) + encoded_install_config = encoded_install_config_yaml.decode("utf-8") + secret2["data"] = {"install-config.yaml": encoded_install_config} + self.apply_manifest(secret2) + + def set_secret3(self): + secret3 = copy.deepcopy(self.secret_yaml) + secret3["metadata"]["name"] = f"{self.cluster_name}-ssh-private-key" + secret3["metadata"]["namespace"] = self.cluster_name + secret3["stringData"] = {"ssh-privatekey": self.ssh_priv_key} + self.apply_manifest(secret3) + + def set_secret4(self): + secret4 = copy.deepcopy(self.secret_yaml) + secret4["metadata"]["name"] = f"{self.cluster_name}-vsphere-creds" + secret4["metadata"]["namespace"] = self.cluster_name + secret4["stringData"] = { + "username": config.ENV_DATA["vsphere_user"], + "password": config.ENV_DATA["vsphere_password"], + } + # secret4["stringData"] = {"password": config.ENV_DATA["vsphere_password"]} + self.apply_manifest(secret4) + + def set_secret5(self): + secret5 = copy.deepcopy(self.secret_yaml) + secret5["metadata"]["name"] = f"{self.cluster_name}-ssh-private-key" + secret5["metadata"]["namespace"] = self.cluster_name + encoded_vsphere_ca = base64.b64encode(self.vsphere_ca.encode("utf-8")) + encoded_vsphere_ca_str = encoded_vsphere_ca.decode("utf-8") + secret5["data"] = {".cacert": encoded_vsphere_ca_str} + self.apply_manifest(secret5) + + def delete_cluster(self): + """ + Delete cluster + + """ + with RunWithConfigContext(): + ocp_obj = OCP() + log.info(f"Detach a managed cluster {self.cluster_name}") + ocp_obj.exec_oc_cmd( + f"delete managedcluster {self.cluster_name}", out_yaml_format=False + ) + log.info(f"Destroy the managed cluster {self.cluster_name} after detaching") + ocp_obj.exec_oc_cmd( + f"delete clusterdeployment {self.cluster_name} -n {self.cluster_name}", + out_yaml_format=False, + ) + + def apply_manifest(self, data): + """ + Create yaml template + + Args: + data (dic): yaml data + + """ + manifest = tempfile.NamedTemporaryFile( + mode="w+", prefix="manifest-", delete=False + ) + logging.info(f"Tmp file name: {manifest.name}") + templating.dump_data_to_temp_yaml(data, manifest.name) + self.file_paths.append(manifest.name) + + def download_kubeadmin_password(self): + """ + Download kubeconfig anf kubeadmin-password from ACM hub + + Returns: + kuconfig, kubeadmin-password (tuple): + + """ + with RunWithConfigContext(): + kubeadmin_password_secret_name = get_secret_name_by_pattern( + pattern="admin-password", namespace=self.cluster_name + ) + kubeadmin_password_secret_obj = get_secret_obj( + name=kubeadmin_password_secret_name[0], namespace=self.cluster_name + ) + kubeadmin_password_encode = kubeadmin_password_secret_obj["data"][ + "password" + ] + kubeadmin_password_decode = base64.b64decode(kubeadmin_password_encode) + kubeadmin_password_decode_str = kubeadmin_password_decode.decode("utf-8") + + kubeconfig_secret_name = get_secret_name_by_pattern( + pattern="admin-kubeconfig", namespace=self.cluster_name + ) + kubeconfig_secret_obj = get_secret_obj( + name=kubeconfig_secret_name[0], namespace=self.cluster_name + ) + kubeconfig_encode = kubeconfig_secret_obj["data"]["kubeconfig"] + kubeconfig_decode = base64.b64decode(kubeconfig_encode) + kubeconfig_decode_str = kubeconfig_decode.decode("utf-8") + return kubeconfig_decode_str, kubeadmin_password_decode_str + + def verify_cluster_status(self): + """ + Verify new OCP cluster created + + """ + with RunWithConfigContext(): + ocp_obj = OCP(kind=constants.ACM_MANAGEDCLUSTER) + ocp_obj.wait_for_resource( + timeout=10, + condition="True", + column="AVAILABLE", + resource_name=self.cluster_name, + ) + ocp_obj.wait_for_resource( + timeout=10, + condition="True", + column="JOINED", + resource_name=self.cluster_name, + ) + + def combine_yaml_files(self): + """ + Combine yaml files + + """ + with open(self.manifest_location.name, "w") as output_file: + for file_path in self.file_paths: + with open(file_path, "r") as input_file: + data = yaml.safe_load(input_file) + yaml.dump(data, output_file, default_flow_style=False) + output_file.write("---\n") + run_cmd(f"oc apply -f {output_file.name}") + + def create_cluster(self): + """ + Create Cluster + + """ + self.create_credential() + self.set_install_config() + self.set_cluster_deployment() + self.set_managed_cluster() + self.set_machine_pool() + self.set_secret1() + self.set_secret2() + self.set_secret3() + self.set_secret4() + self.set_secret5() + self.set_klusterlet_config() + self.combine_yaml_files() + + +class RunWithConfigContext(object): + def __init__(self): + self.original_config_index = config.cur_index + self.acm_index = get_all_acm_indexes()[0] + + def __enter__(self): + config.switch_ctx(self.acm_index) + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + config.switch_ctx(self.original_config_index) diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 2a5786e596e7..26c6ebdf9897 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -2198,6 +2198,23 @@ ACM_LOCAL_CLUSTER = "local-cluster" ACM_CLUSTERSET_LABEL = "cluster.open-cluster-management.io/clusterset" ACM_ADDONS_NAMESPACE = "open-cluster-management-agent-addon" +ACM_VSPHERE_CRED_YAML = os.path.join( + TEMPLATE_DIR, "acm-deployment", "vsphere_credential.yaml" +) +ACM_VSPHERE_INSTALL_CONFIG_YAML = os.path.join( + TEMPLATE_DIR, "acm-deployment", "install-config.yaml" +) +ACM_MANAGEDCLUSTER_YAML = os.path.join( + TEMPLATE_DIR, "acm-deployment", "managed-cluster.yaml" +) +ACM_MACHINE_POOL_YAML = os.path.join( + TEMPLATE_DIR, "acm-deployment", "machine-pool.yaml" +) +ACM_CLUSTER_DEPLOYMENT = os.path.join( + TEMPLATE_DIR, "acm-deployment", "cluster-deployment.yaml" +) +ACM_SECRET_YAML = os.path.join(TEMPLATE_DIR, "acm-deployment", "secret.yaml") + # GitOps GITOPS_NAMESPACE = "openshift-gitops" diff --git a/ocs_ci/ocs/utils.py b/ocs_ci/ocs/utils.py index 839cd31ffbc3..d6963daaf83d 100644 --- a/ocs_ci/ocs/utils.py +++ b/ocs_ci/ocs/utils.py @@ -724,6 +724,39 @@ def get_pod_name_by_pattern( return pod_list +def get_secret_name_by_pattern( + pattern="client", + namespace=None, + filter=None, +): + """ + In a given namespace find names of the secrets that match + the given pattern + + Args: + pattern (str): name of the secret with given pattern + namespace (str): Namespace value + filter (str): secret name to filter from the list + + Returns: + secret_list (list): List of secret names matching the pattern + + """ + namespace = namespace if namespace else ocsci_config.ENV_DATA["cluster_namespace"] + ocp_obj = OCP(kind="secret", namespace=namespace) + secret_names = ocp_obj.exec_oc_cmd("get secret -o name", out_yaml_format=False) + secret_names = secret_names.split("\n") + secret_list = [] + for name in secret_names: + if filter is not None and re.search(filter, name): + log.info(f"Secret name filtered {name}") + elif re.search(pattern, name): + (_, name) = name.split("/") + log.info(f"secret name match found appending {name}") + secret_list.append(name) + return secret_list + + def get_namespce_name_by_pattern( pattern="client", filter=None, diff --git a/ocs_ci/templates/acm-deployment/cluster-deployment.yaml b/ocs_ci/templates/acm-deployment/cluster-deployment.yaml new file mode 100644 index 000000000000..35edf8e6b758 --- /dev/null +++ b/ocs_ci/templates/acm-deployment/cluster-deployment.yaml @@ -0,0 +1,37 @@ +--- +apiVersion: hive.openshift.io/v1 +kind: ClusterDeployment +metadata: + name: cluster-name + namespace: cluster-name + labels: + cloud: vSphere + vendor: OpenShift +spec: + baseDomain: X + clusterName: cluster-name + controlPlaneConfig: + servingCertificates: {} + installAttemptsLimit: 1 + installed: false + platform: + vsphere: + cluster: Cluster-1 + certificatesSecretRef: + name: cluster-name-vsphere-certs + credentialsSecretRef: + name: cluster-name-vsphere-creds + vCenter: X + datacenter: X + defaultDatastore: X + network: X + provisioning: + installConfigSecretRef: + name: cluster-name-install-config + sshPrivateKeySecretRef: + name: cluster-name-ssh-private-key + imageSetRef: + #quay.io/openshift-release-dev/ocp-release:4.14.3-multi + name: ocp-image + pullSecretRef: + name: cluster-name-pull-secret diff --git a/ocs_ci/templates/acm-deployment/install-config.yaml b/ocs_ci/templates/acm-deployment/install-config.yaml new file mode 100644 index 000000000000..7490bed38126 --- /dev/null +++ b/ocs_ci/templates/acm-deployment/install-config.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +metadata: + name: cluster-name +baseDomain: X +controlPlane: + hyperthreading: Enabled + name: master + replicas: 3 + platform: + vsphere: + cpus: 4 + coresPerSocket: 2 + memoryMB: 16384 + osDisk: + diskSizeGB: 120 +compute: +- hyperthreading: Enabled + name: 'worker' + replicas: 3 + platform: + vsphere: + cpus: 16 + coresPerSocket: 2 + memoryMB: 65536 + osDisk: + diskSizeGB: 120 +networking: + networkType: OVNKubernetes + clusterNetwork: + - cidr: 10.128.0.0/14 + hostPrefix: 23 + machineNetwork: + - cidr: X + serviceNetwork: + - 172.30.0.0/16 +platform: + vsphere: + vCenter: X + username: X + password: X + datacenter: X + defaultDatastore: vsanDatastore + cluster: X + apiVIP: X + ingressVIP: X + network: X +pullSecret: "" # skip, hive will inject based on it's secrets +sshKey: X diff --git a/ocs_ci/templates/acm-deployment/klusterlet-addon-config.yaml b/ocs_ci/templates/acm-deployment/klusterlet-addon-config.yaml index 188491552b16..14ec25ea9469 100644 --- a/ocs_ci/templates/acm-deployment/klusterlet-addon-config.yaml +++ b/ocs_ci/templates/acm-deployment/klusterlet-addon-config.yaml @@ -1,16 +1,22 @@ +--- apiVersion: agent.open-cluster-management.io/v1 kind: KlusterletAddonConfig metadata: - name: cluster_name - namespace: cluster_name + name: cluster-name + namespace: cluster-name spec: + clusterName: cluster-name + clusterNamespace: cluster-name + clusterLabels: + cloud: vSphere + vendor: OpenShift applicationManager: enabled: true - certPolicyController: - enabled: true - iamPolicyController: - enabled: true policyController: enabled: true searchCollector: enabled: true + certPolicyController: + enabled: true + iamPolicyController: + enabled: true diff --git a/ocs_ci/templates/acm-deployment/machine-pool.yaml b/ocs_ci/templates/acm-deployment/machine-pool.yaml new file mode 100644 index 000000000000..fa1061e4e13f --- /dev/null +++ b/ocs_ci/templates/acm-deployment/machine-pool.yaml @@ -0,0 +1,18 @@ +--- +apiVersion: hive.openshift.io/v1 +kind: MachinePool +metadata: + name: cluster-name-worker + namespace: cluster-name +spec: + clusterDeploymentRef: + name: cluster-name + name: worker + platform: + vsphere: + cpus: 16 + coresPerSocket: 2 + memoryMB: 65536 + osDisk: + diskSizeGB: 120 + replicas: 3 diff --git a/ocs_ci/templates/acm-deployment/managed-cluster.yaml b/ocs_ci/templates/acm-deployment/managed-cluster.yaml index 8a433186b2a0..cf42925647a2 100644 --- a/ocs_ci/templates/acm-deployment/managed-cluster.yaml +++ b/ocs_ci/templates/acm-deployment/managed-cluster.yaml @@ -1,9 +1,11 @@ +--- apiVersion: cluster.open-cluster-management.io/v1 kind: ManagedCluster metadata: - name: cluster-name labels: - cloud: auto-detect - vendor: auto-detect + cloud: vSphere + name: cluster-name + vendor: OpenShift + name: cluster-name spec: hubAcceptsClient: true diff --git a/ocs_ci/templates/acm-deployment/secret.yaml b/ocs_ci/templates/acm-deployment/secret.yaml new file mode 100644 index 000000000000..1b9907b57478 --- /dev/null +++ b/ocs_ci/templates/acm-deployment/secret.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: cluster-name-vsphere-creds + namespace: cluster-name diff --git a/ocs_ci/templates/acm-deployment/vsphere_credential.yaml b/ocs_ci/templates/acm-deployment/vsphere_credential.yaml new file mode 100644 index 000000000000..c9c1a434acc7 --- /dev/null +++ b/ocs_ci/templates/acm-deployment/vsphere_credential.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: vsphere-cred + namespace: default + labels: + cluster.open-cluster-management.io/type: vmw + cluster.open-cluster-management.io/credentials: "" +stringData: + vCenter: X + username: X + password: X + cacertificate: X + cluster: X + datacenter: X + defaultDatastore: vsanDatastore + vsphereFolder: "" + vsphereResourcePool: "" + vsphereDiskType: "" + baseDomain: X + pullSecret: X + ssh-privatekey: X + ssh-publickey: X + imageContentSources: "" + disconnectedAdditionalTrustBundle: "" + httpProxy: "" + httpsProxy: "" + noProxy: "" + additionalTrustBundle: "" diff --git a/tests/functional/deployment/test_acm.py b/tests/functional/deployment/test_acm.py index 1dd3690cc522..5af045e93423 100644 --- a/tests/functional/deployment/test_acm.py +++ b/tests/functional/deployment/test_acm.py @@ -1,13 +1,43 @@ -from ocs_ci.ocs.acm.acm import import_clusters_with_acm +import logging + +from ocs_ci.ocs.acm.acm import import_clusters_with_acm, CreateClusterViaACM from ocs_ci.framework.pytest_customization.marks import purple_squad -from ocs_ci.framework.testlib import acm_import +from ocs_ci.framework.testlib import acm_import, acm_install +from ocs_ci.framework import config +from ocs_ci.ocs.utils import get_non_acm_cluster_config + #################################################################################################### # This file is placeholder for calling import ACM as test, until full solution will be implimented # #################################################################################################### +log = logging.getLogger(__name__) + @purple_squad @acm_import def test_acm_import(): import_clusters_with_acm() + + +@purple_squad +@acm_install +def test_acm_create(): + """ + Create ocp cluster via ACM + + """ + non_acm_clusters = get_non_acm_cluster_config() + non_acm_cluster_objs = dict() + for non_acm_cluster in non_acm_clusters: + config.switch_ctx(non_acm_cluster.MULTICLUSTER["multicluster_index"]) + non_acm_cluster_objs[ + non_acm_cluster.MULTICLUSTER["multicluster_index"] + ] = CreateClusterViaACM() + non_acm_cluster_objs[ + non_acm_cluster.MULTICLUSTER["multicluster_index"] + ].create_cluster() + + for context_id, non_acm_cluster_obj in non_acm_cluster_objs.items(): + config.switch_ctx(context_id) + non_acm_cluster_obj.verify()