def drain(event: NodeEvent):
    """
    Drain, taints a node as unschedulable, and evicts all pods from the node.
    DaemonSets pods are skipped, as they tolerant unschedulable nodes by default.
    """
    cordon(event)

    node = event.get_node()
    api = client.CoreV1Api()
    try:
        pods: V1PodList = api.list_pod_for_all_namespaces(
            watch=False, field_selector=f"spec.nodeName={node.metadata.name}"
        )
    except Exception as e:
        uncordon(event)
        raise ActionException(
            ErrorCodes.ACTION_UNEXPECTED_ERROR, f"Failed to list pods for drain action Uncordoning.\n{e}"
        )

    msg = ""
    evicting = skipping = deleting = errors = 0
    for pod in pods.items:
        name = pod.metadata.name
        namespace = pod.metadata.namespace

        owner_list: List[V1OwnerReference] = pod.metadata.owner_references if pod.metadata.owner_references else []
        if any(owner.kind == "DaemonSet" for owner in owner_list):
            msg += f"Skipping {namespace}/DaemonSet/{name}\n"
            skipping += 1
            continue

        try:
            body = client.V1Eviction(metadata=client.V1ObjectMeta(name=name, namespace=namespace))
            api.create_namespaced_pod_eviction(name, namespace, body, pretty="True")
            action = "Evicting"
            if owner_list:
                evicting += 1
            else:
                action = "Deleting"
                deleting += 1

            msg += f"{action} {namespace}/Pod/{name}\n"
        except Exception as e:
            msg += f"Error evicting {namespace}/Pod/{name} {e}\n"
            errors += 1
            continue

    event.add_enrichment(
        [
            MarkdownBlock(
                f"Drain node {node.metadata.name} \nEvicting {evicting} pod(s), deleting {deleting} pod(s), skipping {skipping} pod(s) and {errors} Error(s)."
            ),
            FileBlock(
                filename=f"Drain {node.metadata.name} report.log",
                contents=f"drain node {node.metadata.name} \n\n{msg}".encode(),
            ),
        ]
    )

    Drain, taints a node as unschedulable, and evicts all pods from the node.
    DaemonSets pods are skipped, as they tolerant unschedulable nodes by default.
    
playbooks/robusta_playbooks/node_actions.py