import re


def convert_to_millicores(value):
    """
    Convert values from k8s like 1, 100m, 1000000n etc to millicores
    """
    factors = {
        None: 1000,
        "m": 1,
        "n": 1e-6,
    }
    res = re.match(r"^([^\smn]+)\s*([mn]*)?$", value.strip())
    if res is None:
        raise ValueError(f"Cannot convert value {value} to millicores.")
    value, unit = res.groups()
    if unit not in factors.keys():
        raise ValueError(
            f"Cannot convert value {value} to millicores because unit {unit} is not known."
        )
    return float(value) * factors[unit]