def METHOD_NAME(
    pod, namespace, desired_state, desired_reason=None, label=None, timeout_insec=600
):
    """
    Wait for a a pod state. If you do not specify a pod name and you set instead a label
    only the first pod will be checked.
    """
    deadline = datetime.datetime.now() + datetime.timedelta(seconds=timeout_insec)
    while True:
        if datetime.datetime.now() > deadline:
            raise TimeoutError(
                "Pod {} not in {} after {} seconds.".format(pod, desired_state, timeout_insec)
            )
        cmd = "po {} -n {}".format(pod, namespace)
        if label:
            cmd += " -l {}".format(label)
        data = kubectl_get(cmd, timeout_insec)
        if pod == "":
            if len(data["items"]) > 0:
                status = data["items"][0]["status"]
            else:
                status = []
        else:
            status = data["status"]
        if "containerStatuses" in status:
            container_status = status["containerStatuses"][0]
            state, details = list(container_status["state"].items())[0]
            if desired_reason:
                reason = details.get("reason")
                if state == desired_state and reason == desired_reason:
                    break
            elif state == desired_state:
                break
        time.sleep(3)