def _validate_namespace_argument()

in launcher/config_validator/value_validator.py [0:0]


def _validate_namespace_argument(config: DictConfig) -> None:
    """
    Check only valid kubectl namespace is provided
    Naming Convention of Kubernetes Namespaces is
    You can create a name with a maximum length of 253 characters using only alphanumeric characters and hyphens.
    Names cannot start with a hyphen and the alpha characters can only be lowercase.

    Parameters:
    config (DictConfig): Configuration dictionary
    """

    """
    Here's a breakdown of the regex pattern:

    ^ - Asserts the position at the start of the string.
    (?!-) - A negative lookahead assertion to ensure the string does not start with a hyphen.
    [a-z0-9-] - Matches any lowercase letter, digit, or hyphen.
    {1,253} - Specifies that the string must be between 1 and 253 characters long.
    $ - Asserts the position at the end of the string.
    This pattern will ensure the string is constructed using only lowercase alphanumeric characters and hyphens,
    is no longer than 253 characters, and does not start with a hyphen.
    """
    namespace_regex = r"^(?!-)[a-z0-9-]{1,253}$"
    namespace_argument_name = "cluster.cluster_config.namespace"
    namespace_argument = get_argument(config, namespace_argument_name)
    if namespace_argument is not None and not re.match(namespace_regex, namespace_argument):
        raise ValueError(
            "Provided namespace is not valid, Kindly provide Kubernetes Namespace "
            "with a maximum length of 253 characters using only alphanumeric characters and hyphens. "
            "Names cannot start with a hyphen and the alpha characters can only be lowercase."
        )