diff --git a/kubernetes/utils/create_from_yaml.py b/kubernetes/utils/create_from_yaml.py index 81cb9bea92..f3f8b939f7 100644 --- a/kubernetes/utils/create_from_yaml.py +++ b/kubernetes/utils/create_from_yaml.py @@ -27,7 +27,7 @@ def create_namespaced_from_yaml( k8s_client, yaml_file, verbose=False, - namespace=None, + namespace="default", **kwargs): """ Perform an action from a yaml file. Pass True for verbose to @@ -62,16 +62,11 @@ def create_namespaced_from_yaml( kind = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', kind) kind = re.sub('([a-z0-9])([A-Z])', r'\1_\2', kind).lower() - # If a namespace is defined overwrite it - if namespace is not None: - yml_object["metadata"]["namespace"] = namespace - else: - # Decide which namespace we are going to put the object in, - # if any - if "namespace" in yml_object["metadata"]: - namespace = yml_object["metadata"]["namespace"] - else: - namespace = "default" + # Decide which namespace we are going to put the object in, + # if any is specified in the yaml file use this one + # otherwise use the namespace given as parameter (default) + if "namespace" in yml_object["metadata"]: + namespace = yml_object["metadata"]["namespace"] # Expect the user to create namespaced objects more often if hasattr(k8s_api, "create_namespaced_{0}".format(kind)): @@ -100,4 +95,4 @@ def create_from_yaml(k8s_client, yaml_file, verbose=False, **kwargs): :param str dry_run: When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed """ return create_namespaced_from_yaml( - k8s_client, yaml_file, verbose, None, **kwargs) + k8s_client, yaml_file, verbose=False, namespace="default", **kwargs)