Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update agent hosted cluster prerequisite #9976

Closed
wants to merge 15 commits into from
70 changes: 41 additions & 29 deletions ocs_ci/deployment/hosted_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ocs_ci.ocs.ocp import OCP
from ocs_ci.ocs.resources.catalog_source import CatalogSource
from ocs_ci.ocs.resources.csv import check_all_csvs_are_succeeded
from ocs_ci.ocs.resources.ocs import OCS
from ocs_ci.ocs.resources.pod import (
wait_for_pods_to_be_in_statuses_concurrently,
)
Expand Down Expand Up @@ -487,20 +488,23 @@ def deploy_dependencies(

# Enable central infrastructure management service for agent
if config.DEPLOYMENT.get("hosted_cluster_platform") == "agent":
provisioning_obj = OCP(**OCP(kind=constants.PROVISIONING).get()[0])
if not provisioning_obj.data["spec"].get("watchAllNamespaces") == "true":
provisioning_obj.patch(
resource_name=provisioning_obj.resource_name,
provisioning_obj = OCS(
**OCP(kind=constants.PROVISIONING).get().get("items")[0]
)
if not provisioning_obj.data["spec"].get("watchAllNamespaces"):
provisioning_obj.ocp.patch(
resource_name=provisioning_obj.name,
params='{"spec":{"watchAllNamespaces": true }}',
format_type="merge",
)
assert (
provisioning_obj.get()["spec"].get("watchAllNamespaces") == "true"
assert provisioning_obj.get()["spec"].get(
"watchAllNamespaces"
), "Cannot proceed with hosted cluster creation using agent."

if not OCP(kind=constants.AGENT_SERVICE_CONFIG).get(dont_raise=True):
if not len(
OCP(kind=constants.AGENT_SERVICE_CONFIG).get(dont_raise=True)["items"]
):
create_agent_service_config()
if not OCP(kind=constants.INFRA_ENV).get(dont_raise=True):
create_host_inventory()


Expand All @@ -519,47 +523,55 @@ def create_agent_service_config():
# Verify new pods that should be created
wait_for_pods_to_be_in_statuses_concurrently(
app_selectors_to_resource_count_list=[
"app=assisted-service",
"app=assisted-image-service",
{"app=assisted-service": 1},
{"app=assisted-image-service": 1},
],
namespace="multicluster-engine",
timeout=600,
status=constants.STATUS_RUNNING,
)
logger.info("Created AgentServiceConfig.")


def create_host_inventory():
"""
Create InfraEnv resource for host inventory

"""
# Create new project
project_name = helpers.create_project(project_name="bm-agents").resource_name

# Create pull secret for InfraEnv
secret_obj = OCP(
kind=constants.POD,
resource_name="pull-secret",
namespace=constants.OPENSHIFT_CONFIG_NAMESPACE,
)
secret_data = secret_obj.get()
# This is the name of pull secret and namespace used in InfraEnv template
secret_data["metadata"]["name"] = "pull-secret-agents"
secret_data["metadata"]["namespace"] = project_name
helpers.create_resource(**secret_data)

# Create InfraEnv
template_yaml = os.path.join(
constants.TEMPLATE_DIR, "hosted-cluster", "infra-env.yaml"
)
infra_env_data = templating.load_yaml(template_yaml)
ssh_pub_file_path = config.DEPLOYMENT["ssh_key"]
infra_env_data = templating.load_yaml(file=template_yaml, multi_document=True)
ssh_pub_file_path = os.path.expanduser(config.DEPLOYMENT["ssh_key"])
with open(ssh_pub_file_path, "r") as ssh_key:
ssh_pub_key = ssh_key.read().strip()
infra_env_data["spec"]["sshAuthorizedKey"] = ssh_pub_key
# TODO: Add custom OS image details. Reference https://access.redhat.com/documentation/en-us/red_hat_advanced_
# cluster_management_for_kubernetes/2.10/html-single/clusters/index#create-host-inventory-cli-steps
helpers.create_resource(**infra_env_data)
for data in infra_env_data:
if data["kind"] == constants.INFRA_ENV:
data["spec"]["sshAuthorizedKey"] = ssh_pub_key
infra_env_namespace = data["metadata"]["namespace"]
# Create project
helpers.create_project(project_name=infra_env_namespace)
# Create new secret in the namespace using the existing secret
secret_obj = OCP(
kind=constants.SECRET,
resource_name="pull-secret",
namespace=constants.OPENSHIFT_CONFIG_NAMESPACE,
)
secret_info = secret_obj.get()
secret_data = templating.load_yaml(constants.OCS_SECRET_YAML)
secret_data["data"][".dockerconfigjson"] = secret_info["data"][".dockerconfigjson"]
secret_data["metadata"]["namespace"] = infra_env_namespace
secret_data["metadata"]["name"] = "pull-secret"
secret_manifest = tempfile.NamedTemporaryFile(
mode="w+", prefix="pull_secret", delete=False
)
templating.dump_data_to_temp_yaml(secret_data, secret_manifest.name)
exec_cmd(cmd=f"oc create -f {secret_manifest.name}")
helpers.create_resource(**data)
logger.info("Created InfraEnv.")


class HostedODF(HypershiftHostedOCP):
Expand Down
2 changes: 1 addition & 1 deletion ocs_ci/templates/hosted-cluster/infra-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
agentLabels:
'agentclusterinstalls.extensions.hive.openshift.io/location': localagents
pullSecretRef:
name: pull-secret-agents
name: pull-secret
sshAuthorizedKey: ssh-public-key-value
nmStateConfigLabelSelector:
matchLabels:
Expand Down
Loading