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) logger.info("iso downloaded, starting nodes") nodes.start_all() logger.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 logger.info("Waiting for agent status verification") Agent.wait_for_agents_to_be_ready_for_install(agents) return infra_env
def run_installation_flow_kube_api( cluster_deployment, agent_cluster_install, nodes_number, kubeconfig_path, ): log.info("Approving agents") agents = cluster_deployment.wait_for_agents(nodes_number) for agent in agents: agent.approve() log.info("Waiting for agent status verification") Agent.wait_for_agents_to_install(agents) log.info("Waiting for installation to start") agent_cluster_install.wait_to_be_installing() log.info("Waiting until cluster finishes installation") agent_cluster_install.wait_to_be_installed() log.info("Download kubeconfig-noingress") agent_cluster_install.download_kubeconfig(kubeconfig_path=kubeconfig_path)
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: logger.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) logger.info("iso downloaded, starting nodes") nodes.start_all() logger.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) logger.info("Waiting for agent status verification") Agent.wait_for_agents_to_install(agents) agent_cluster_install.wait_to_be_ready(True) logger.info("waiting for agent-cluster-install to be in installing state") agent_cluster_install.wait_to_be_installing() try: logger.info("installation started, waiting for completion") agent_cluster_install.wait_to_be_installed() logger.info("installation completed successfully") except Exception: logger.exception("Failure during kube-api installation flow:") collect_debug_info_from_cluster(cluster_deployment, agent_cluster_install)
def _wait_for_install(agent_cluster_install, agents): agent_cluster_install.wait_to_be_ready(True) agent_cluster_install.wait_to_be_installing() Agent.wait_for_agents_to_install(agents) agent_cluster_install.wait_to_be_installed()
def nodes_flow(client, cluster_name, cluster, machine_net, kube_client=None, cluster_deployment=None): tf_folder = utils.get_tf_folder(cluster_name, args.namespace) nodes_details = utils.get_tfvars(tf_folder) if cluster: nodes_details["cluster_inventory_id"] = cluster.id utils.set_tfvars(tf_folder, nodes_details) tf = terraform_utils.TerraformUtils(working_dir=tf_folder) is_ipv4 = machine_net.has_ip_v4 or not machine_net.has_ip_v6 create_nodes_and_wait_till_registered(inventory_client=client, cluster=cluster, nodes_details=nodes_details, tf=tf, is_ipv4=is_ipv4) main_cidr = args.vm_network_cidr if is_ipv4 else args.vm_network_cidr6 secondary_cidr = machine_net.provisioning_cidr_v4 if is_ipv4 else machine_net.provisioning_cidr_v6 if client: cluster_info = client.cluster_get(cluster.id) macs = utils.get_libvirt_nodes_macs( nodes_details["libvirt_network_name"]) if is_none_platform_mode(): macs += utils.get_libvirt_nodes_macs( nodes_details["libvirt_secondary_network_name"]) if not (cluster_info.api_vip and cluster_info.ingress_vip): utils.wait_till_hosts_with_macs_are_in_status( client=client, cluster_id=cluster.id, macs=macs, statuses=[ consts.NodesStatus.INSUFFICIENT, consts.NodesStatus.PENDING_FOR_INPUT, consts.NodesStatus.KNOWN ], ) if args.master_count == 1: tf.change_variables({ "single_node_ip": helper_cluster.Cluster.get_ip_for_single_node( client, cluster.id, main_cidr, ipv4_first=is_ipv4) }) set_cluster_machine_cidr(client, cluster.id, machine_net, set_vip_dhcp_allocation=False) elif is_none_platform_mode(): set_cluster_vips(client, cluster.id, machine_net) elif args.vip_dhcp_allocation: set_cluster_machine_cidr(client, cluster.id, machine_net) else: set_cluster_vips(client, cluster.id, machine_net) else: log.info("VIPs already configured") set_hosts_roles(client, cluster, nodes_details, machine_net, tf, args.master_count, args.with_static_network_config) if is_none_platform_mode() and args.master_count > 1: master_ips = helper_cluster.Cluster.get_master_ips( client, cluster.id, main_cidr) + helper_cluster.Cluster.get_master_ips( client, cluster.id, secondary_cidr) worker_ips = helper_cluster.Cluster.get_worker_ips( client, cluster.id, main_cidr) + helper_cluster.Cluster.get_worker_ips( client, cluster.id, secondary_cidr) if not worker_ips: worker_ips = master_ips load_balancer_ip = _get_host_ip_from_cidr( machine_net.cidr_v6 if machine_net.has_ip_v6 and not machine_net.has_ip_v4 else machine_net.cidr_v4) lb_controller = LoadBalancerController(tf) lb_controller.set_load_balancing_config(load_balancer_ip, master_ips, worker_ips) utils.wait_till_hosts_with_macs_are_in_status( client=client, cluster_id=cluster.id, macs=macs, statuses=[consts.NodesStatus.KNOWN], ) if args.install_cluster: if args.kube_api: for agent in Agent.list(CustomObjectsApi(kube_client), cluster_deployment): agent.approve() install_cluster.run_install_flow( client=client, cluster_id=cluster.id, kubeconfig_path=consts.DEFAULT_CLUSTER_KUBECONFIG_PATH, pull_secret=args.pull_secret, tf=tf, kube_client=kube_client, cluster_deployment=cluster_deployment, ) # Validate DNS domains resolvability validate_dns(client, cluster.id)