Skip to content

Commit

Permalink
Throw exception from create_from_dict
Browse files Browse the repository at this point in the history
This is instead of doing this in create_from_yaml
  • Loading branch information
oz123 committed Jun 20, 2019
1 parent 4fa0e87 commit 5c912f9
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,10 @@ def create_from_yaml(
yaml_file = StringIO(content.decode('utf-8'))

yml_document_all = yaml.safe_load_all(yaml_file)
# Load all documents from a single YAML file
fail_exceptions = []

for yml_document in yml_document_all:
exceptions = create_from_dict(k8s_client, yml_document, verbose,
**kwargs)
if exceptions:
fail_exceptions.extend(exceptions)

if fail_exceptions:
raise FailToCreateError(fail_exceptions)
create_from_dict(k8s_client, yml_document, verbose,
**kwargs)


def create_from_dict(k8s_client, data, verbose=False, **kwargs):
Expand All @@ -99,10 +92,9 @@ def create_from_dict(k8s_client, data, verbose=False, **kwargs):
verbose: If True, print confirmation from the create action.
Default is False.
Returns:
A list of `client.rest.ApiException` instances for each object that
failed to create. The user of this function can throw discard them.
Raises:
FailToCreateError which holds list of `client.rest.ApiException`
instances for each object that failed to create.
"""
# If it is a list type, will need to iterate its items
api_exceptions = []
Expand Down Expand Up @@ -132,7 +124,7 @@ def create_from_dict(k8s_client, data, verbose=False, **kwargs):

# In case we have exceptions waiting for us, raise them
if api_exceptions:
return api_exceptions
raise FailToCreateError(api_exceptions)


def create_from_yaml_single_item(
Expand Down

0 comments on commit 5c912f9

Please sign in to comment.