def apply_static_network_config(cluster_name, kube_client):
    if not args.with_static_network_config:
        return None

    tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
    static_network_config = static_network.generate_static_network_data_from_tf(
        tf_folder)
    if args.kube_api:
        if args.master_count != 1:
            raise NotImplementedError(
                "At the moment, KubeAPI workflow supports only single-node clusters"
            )

        mac_to_interface = static_network_config[0]["mac_interface_map"]
        interfaces = [{
            "name": item["logical_nic_name"],
            "macAddress": item["mac_address"]
        } for item in mac_to_interface]

        nmstate_config = NMStateConfig(
            kube_api_client=kube_client,
            name=f"{cluster_name}-nmstate-config",
            namespace=args.namespace,
        )
        nmstate_config.apply(
            config=yaml.safe_load(static_network_config[0]["network_yaml"]),
            interfaces=interfaces,
            label=cluster_name,
        )

    return static_network_config
Пример #2
0
def delete_kube_api_resources_for_namespace(
    kube_api_client,
    name,
    namespace,
    *,
    secret_name=None,
    infraenv_name=None,
    nmstate_name=None,
    image_set_name=None,
):
    CoreV1Api.delete_namespaced_secret = suppress_not_found_error(
        fn=CoreV1Api.delete_namespaced_secret,
    )
    CustomObjectsApi.delete_namespaced_custom_object = suppress_not_found_error(
        fn=CustomObjectsApi.delete_namespaced_custom_object
    )

    cluster_deployment = ClusterDeployment(
        kube_api_client=kube_api_client,
        name=name,
        namespace=namespace,
    )

    for agent in cluster_deployment.list_agents():
        agent.delete()

    cluster_deployment.delete()

    Secret(
        kube_api_client=kube_api_client,
        name=secret_name or name,
        namespace=namespace,
    ).delete()

    InfraEnv(
        kube_api_client=kube_api_client,
        name=infraenv_name or f"{name}-infra-env",
        namespace=namespace,
    ).delete()

    NMStateConfig(
        kube_api_client=kube_api_client,
        name=nmstate_name or f"{name}-nmstate-config",
        namespace=namespace,
    ).delete()

    ClusterImageSet(
        kube_api_client=kube_api_client, name=image_set_name or f"{name}-image-set", namespace=namespace
    ).delete()