def kube_api_test_prepare_late_binding_infraenv(
        kube_api_context,
        nodes: Nodes,
        infraenv_config: InfraEnvConfig,
        *,
        is_ipv4=True):
    infraenv_name = infraenv_config.entity_name.get()

    secret = Secret(
        kube_api_client=kube_api_context.api_client,
        name=f"{infraenv_name}-secret",
        namespace=global_variables.spoke_namespace,
    )
    secret.create(pull_secret=infraenv_config.pull_secret)

    ignition_config_override = None

    infra_env = InfraEnv(
        kube_api_client=kube_api_context.api_client,
        name=f"{infraenv_name}-infra-env",
        namespace=global_variables.spoke_namespace,
    )
    infra_env.create(
        cluster_deployment=None,
        ignition_config_override=ignition_config_override,
        secret=secret,
        proxy=None,
        ssh_pub_key=infraenv_config.ssh_public_key,
    )

    infra_env.status()

    download_iso_from_infra_env(infra_env, infraenv_config.iso_download_path)

    log.info("iso downloaded, starting nodes")
    nodes.start_all()

    log.info("waiting for host agent")
    agents = infra_env.wait_for_agents(len(nodes))
    for agent in agents:
        agent.approve()
        set_agent_hostname(nodes[0], agent,
                           is_ipv4)  # Currently only supports single node

    log.info("Waiting for agent status verification")
    Agent.wait_for_agents_to_be_ready_for_install(agents)

    return infra_env
示例#2
0
    def start_nodes(cls, nodes: Nodes, infra_env: InfraEnv, entity_config: BaseEntityConfig) -> List[Agent]:
        infra_env.status()  # wait until install-env will have status (i.e until resource will be processed).
        cls.download_iso_from_infra_env(infra_env, entity_config.iso_download_path)

        log.info("iso downloaded, starting nodes")
        nodes.controller.log_configuration()
        log.info(f"Entity configuration {entity_config}")

        nodes.start_all(check_ips=not (entity_config.is_static_ip and entity_config.is_ipv6))

        log.info("waiting for host agent")
        agents = infra_env.wait_for_agents(len(nodes))
        node_list = nodes.controller.list_nodes()
        for agent in agents:
            agent.approve()
            cls._set_host_name_from_node(node_list, agent, entity_config.is_ipv4)

        return agents
示例#3
0
def kube_api_test(
    kube_api_context,
    nodes: Nodes,
    cluster_config: ClusterConfig,
    proxy_server=None,
    *,
    is_ipv4=True,
    is_disconnected=False,
):
    cluster_name = cluster_config.cluster_name.get()

    # TODO resolve it from the service if the node controller doesn't have this information
    #  (please see cluster.get_primary_machine_cidr())
    machine_cidr = nodes.controller.get_primary_machine_cidr()

    agent_cluster_install = AgentClusterInstall(
        kube_api_client=kube_api_context.api_client,
        name=f"{cluster_name}-agent-cluster-install",
        namespace=global_variables.spoke_namespace,
    )

    secret = Secret(
        kube_api_client=kube_api_context.api_client,
        name=f"{cluster_name}-secret",
        namespace=global_variables.spoke_namespace,
    )
    secret.create(pull_secret=cluster_config.pull_secret)

    cluster_deployment = ClusterDeployment(
        kube_api_client=kube_api_context.api_client,
        name=cluster_name,
        namespace=global_variables.spoke_namespace,
    )
    cluster_deployment.create(
        agent_cluster_install_ref=agent_cluster_install.ref,
        secret=secret,
    )

    agent_cluster_install.create(
        cluster_deployment_ref=cluster_deployment.ref,
        image_set_ref=deploy_image_set(cluster_name, kube_api_context),
        cluster_cidr=cluster_config.cluster_networks[0].cidr,
        host_prefix=cluster_config.cluster_networks[0].host_prefix,
        service_network=cluster_config.service_networks[0].cidr,
        ssh_pub_key=cluster_config.ssh_public_key,
        hyperthreading=cluster_config.hyperthreading,
        control_plane_agents=nodes.controller.params.master_count,
        worker_agents=nodes.controller.params.worker_count,
        machine_cidr=machine_cidr,
    )
    agent_cluster_install.wait_to_be_ready(False)

    if is_disconnected:
        log.info("getting igntion and install config override for disconected install")
        ca_bundle = get_ca_bundle_from_hub()
        patch_install_config_with_ca_bundle(cluster_deployment, ca_bundle)
        ignition_config_override = get_ignition_config_override(ca_bundle)
    else:
        ignition_config_override = None

    proxy = setup_proxy(cluster_config, machine_cidr, cluster_name, proxy_server)

    infra_env = InfraEnv(
        kube_api_client=kube_api_context.api_client,
        name=f"{cluster_name}-infra-env",
        namespace=global_variables.spoke_namespace,
    )
    infra_env.create(
        cluster_deployment=cluster_deployment,
        ignition_config_override=ignition_config_override,
        secret=secret,
        proxy=proxy,
        ssh_pub_key=cluster_config.ssh_public_key,
    )
    infra_env.status()
    download_iso_from_infra_env(infra_env, cluster_config.iso_download_path)

    log.info("iso downloaded, starting nodes")
    nodes.start_all()

    log.info("waiting for host agent")
    agents = cluster_deployment.wait_for_agents(len(nodes))
    for agent in agents:
        agent.approve()
        set_agent_hostname(nodes[0], agent, is_ipv4)  # Currently only supports single node

    if len(nodes) == 1:
        set_single_node_ip(cluster_deployment, nodes, is_ipv4)

    log.info("Waiting for agent status verification")
    Agent.wait_for_agents_to_install(agents)

    agent_cluster_install.wait_to_be_ready(True)

    log.info("waiting for agent-cluster-install to be in installing state")
    agent_cluster_install.wait_to_be_installing()

    try:
        log.info("installation started, waiting for completion")
        agent_cluster_install.wait_to_be_installed()
        log.info("installation completed successfully")
    except Exception:
        log.exception("Failure during kube-api installation flow:")
        collect_debug_info_from_cluster(cluster_deployment, agent_cluster_install)
示例#4
0
def capi_test(
    kube_api_context,
    nodes: Nodes,
    cluster_config: ClusterConfig,
    proxy_server=None,
    *,
    is_ipv4=True,
    is_disconnected=False,
):
    cluster_name = cluster_config.cluster_name.get()
    cluster_config
    # TODO resolve it from the service if the node controller doesn't have this information
    #  (please see cluster.get_primary_machine_cidr())
    machine_cidr = nodes.controller.get_primary_machine_cidr()

    secret = Secret(
        kube_api_client=kube_api_context.api_client,
        name=f"{cluster_name}-secret",
        namespace=global_variables.spoke_namespace,
    )
    secret.create(pull_secret=cluster_config.pull_secret)

    if is_disconnected:
        log.info("getting igntion and install config override for disconected install")
        ca_bundle = get_ca_bundle_from_hub()
        ignition_config_override = get_ignition_config_override(ca_bundle)
    else:
        ignition_config_override = None

    proxy = setup_proxy(cluster_config, machine_cidr, cluster_name, proxy_server)

    infra_env = InfraEnv(
        kube_api_client=kube_api_context.api_client,
        name=f"{cluster_name}-infra-env",
        namespace=global_variables.spoke_namespace,
    )
    infra_env.create(
        cluster_deployment=None,
        ignition_config_override=ignition_config_override,
        secret=secret,
        proxy=proxy,
        ssh_pub_key=cluster_config.ssh_public_key,
    )
    infra_env.status()
    download_iso_from_infra_env(infra_env, cluster_config.iso_download_path)

    log.info("iso downloaded, starting nodes")
    nodes.start_all()

    log.info("waiting for host agent")
    agents = infra_env.wait_for_agents(len(nodes))
    for agent in agents:
        agent.approve()
        set_agent_hostname(nodes[0], agent, is_ipv4)

    hypershift = HyperShift(name=cluster_name)

    with utils.pull_secret_file() as ps:
        with tempfile.NamedTemporaryFile(mode="w") as f:
            f.write(cluster_config.ssh_public_key)
            f.flush()
            ssh_public_key_file = f.name
            hypershift.create(pull_secret_file=ps, ssh_key=ssh_public_key_file)

    cluster_deployment = ClusterDeployment(
        kube_api_client=kube_api_context.api_client, name=cluster_name, namespace=f"clusters-{cluster_name}"
    )

    def _cluster_deployment_installed() -> bool:
        return cluster_deployment.get().get("spec", {}).get("installed")

    waiting.wait(
        _cluster_deployment_installed,
        sleep_seconds=1,
        timeout_seconds=60,
        waiting_for="clusterDeployment to get created",
        expected_exceptions=Exception,
    )
    set_node_count_and_wait_for_ready_nodes(cluster_deployment, hypershift, kube_api_context, 1)
    set_node_count_and_wait_for_ready_nodes(cluster_deployment, hypershift, kube_api_context, 2)