Skip to content

Commit

Permalink
Set namespace from method parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer committed Mar 25, 2019
1 parent 259715b commit 4c846b0
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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)

0 comments on commit 4c846b0

Please sign in to comment.