def nodes_flow_kube_api(cluster_name, machine_net, cluster_deployment,
                        agent_cluster_install):
    tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
    baremetal_template = os.path.join(tf_folder, consts.Platforms.BARE_METAL)

    nodes_details = utils.get_tfvars(baremetal_template)
    tf = terraform_utils.TerraformUtils(working_dir=baremetal_template)
    is_ipv4 = machine_net.has_ip_v4 or not machine_net.has_ip_v6
    nodes_number = args.master_count + args.number_of_workers

    create_nodes_and_wait_till_registered(
        inventory_client=None,
        cluster=None,
        nodes_details=nodes_details,
        tf=tf,
        is_ipv4=is_ipv4,
        nodes_number=nodes_number,
        cluster_deployment=cluster_deployment,
    )

    if args.master_count == 1:
        set_single_node_ip(
            client=None,
            cluster_id=None,
            main_cidr=args.vm_network_cidr
            if is_ipv4 else args.vm_network_cidr6,
            is_ipv4=is_ipv4,
            cluster_deployment=cluster_deployment,
            tf=tf,
        )
    else:
        log.info("VIPs already configured")

    kubeapi_utils.set_agents_hostnames(
        cluster_deployment=cluster_deployment,
        is_ipv4=is_ipv4,
        static_network_mode=args.with_static_network_config,
        tf=tf,
        nodes_number=nodes_number,
    )

    if args.install_cluster:
        install_cluster.run_installation_flow_kube_api(
            cluster_deployment=cluster_deployment,
            agent_cluster_install=agent_cluster_install,
            nodes_number=nodes_number,
            kubeconfig_path=utils.get_kubeconfig_path(cluster_name))
Exemple #2
0
def nodes_flow(
        client,
        cluster_name,
        cluster,
        machine_net,
        cluster_deployment=None,
        agent_cluster_install=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
    nodes_number = args.master_count + args.number_of_workers

    create_nodes_and_wait_till_registered(
        inventory_client=client,
        cluster=cluster,
        nodes_details=nodes_details,
        tf=tf,
        is_ipv4=is_ipv4,
        nodes_number=nodes_number,
        cluster_deployment=cluster_deployment,
    )

    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):
            if not args.kube_api:
                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:
                set_single_node_ip(
                    client=client,
                    cluster_id=cluster.id,
                    main_cidr=main_cidr,
                    is_ipv4=is_ipv4,
                    cluster_deployment=cluster_deployment,
                    tf=tf,
                )
                if not args.kube_api:
                    set_cluster_machine_cidr(
                        client=client,
                        cluster_id=cluster.id,
                        machine_net=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 and not args.kube_api:
                set_cluster_machine_cidr(client, cluster.id, machine_net)
            else:
                set_cluster_vips(client, cluster.id, machine_net)
        else:
            log.info("VIPs already configured")

        if args.kube_api:
            kubeapi_utils.set_agents_hostnames(
                cluster_deployment=cluster_deployment,
                is_ipv4=is_ipv4,
                static_network_mode=args.with_static_network_config,
                tf=tf,
                nodes_number=nodes_number,
            )
        else:
            set_hosts_roles(
                client=client,
                cluster=cluster,
                nodes_details=nodes_details,
                machine_net=machine_net,
                tf=tf,
                master_count=args.master_count,
                static_network_mode=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)

        if not args.kube_api:
            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:
            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,
                cluster_deployment=cluster_deployment,
                agent_cluster_install=agent_cluster_install,
                nodes_number=nodes_number,
            )
            # Validate DNS domains resolvability
            validate_dns(client, cluster.id)