Skip to content

Commit 5c912f9

Browse files
committed
Throw exception from create_from_dict
This is instead of doing this in create_from_yaml
1 parent 4fa0e87 commit 5c912f9

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

kubernetes/utils/create_from_yaml.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,10 @@ def create_from_yaml(
7575
yaml_file = StringIO(content.decode('utf-8'))
7676

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

8179
for yml_document in yml_document_all:
82-
exceptions = create_from_dict(k8s_client, yml_document, verbose,
83-
**kwargs)
84-
if exceptions:
85-
fail_exceptions.extend(exceptions)
86-
87-
if fail_exceptions:
88-
raise FailToCreateError(fail_exceptions)
80+
create_from_dict(k8s_client, yml_document, verbose,
81+
**kwargs)
8982

9083

9184
def create_from_dict(k8s_client, data, verbose=False, **kwargs):
@@ -99,10 +92,9 @@ def create_from_dict(k8s_client, data, verbose=False, **kwargs):
9992
verbose: If True, print confirmation from the create action.
10093
Default is False.
10194
102-
Returns:
103-
A list of `client.rest.ApiException` instances for each object that
104-
failed to create. The user of this function can throw discard them.
105-
95+
Raises:
96+
FailToCreateError which holds list of `client.rest.ApiException`
97+
instances for each object that failed to create.
10698
"""
10799
# If it is a list type, will need to iterate its items
108100
api_exceptions = []
@@ -132,7 +124,7 @@ def create_from_dict(k8s_client, data, verbose=False, **kwargs):
132124

133125
# In case we have exceptions waiting for us, raise them
134126
if api_exceptions:
135-
return api_exceptions
127+
raise FailToCreateError(api_exceptions)
136128

137129

138130
def create_from_yaml_single_item(

0 commit comments

Comments
 (0)