Skip to content

Commit 4c846b0

Browse files
committed
Set namespace from method parameter
1 parent 259715b commit 4c846b0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

kubernetes/utils/create_from_yaml.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def create_namespaced_from_yaml(
2727
k8s_client,
2828
yaml_file,
2929
verbose=False,
30-
namespace=None,
30+
namespace="default",
3131
**kwargs):
3232
"""
3333
Perform an action from a yaml file. Pass True for verbose to
@@ -62,16 +62,11 @@ def create_namespaced_from_yaml(
6262
kind = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', kind)
6363
kind = re.sub('([a-z0-9])([A-Z])', r'\1_\2', kind).lower()
6464

65-
# If a namespace is defined overwrite it
66-
if namespace is not None:
67-
yml_object["metadata"]["namespace"] = namespace
68-
else:
69-
# Decide which namespace we are going to put the object in,
70-
# if any
71-
if "namespace" in yml_object["metadata"]:
72-
namespace = yml_object["metadata"]["namespace"]
73-
else:
74-
namespace = "default"
65+
# Decide which namespace we are going to put the object in,
66+
# if any is specified in the yaml file use this one
67+
# otherwise use the namespace given as parameter (default)
68+
if "namespace" in yml_object["metadata"]:
69+
namespace = yml_object["metadata"]["namespace"]
7570

7671
# Expect the user to create namespaced objects more often
7772
if hasattr(k8s_api, "create_namespaced_{0}".format(kind)):
@@ -100,4 +95,4 @@ def create_from_yaml(k8s_client, yaml_file, verbose=False, **kwargs):
10095
: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
10196
"""
10297
return create_namespaced_from_yaml(
103-
k8s_client, yaml_file, verbose, None, **kwargs)
98+
k8s_client, yaml_file, verbose=False, namespace="default", **kwargs)

0 commit comments

Comments
 (0)