@@ -52,6 +52,9 @@ def create_from_yaml(
52
52
processing of the request.
53
53
Valid values are: - All: all dry run stages will be processed
54
54
55
+ Returns:
56
+ The created kubernetes API objects.
57
+
55
58
Raises:
56
59
FailToCreateError which holds list of `client.rest.ApiException`
57
60
instances for each object that failed to create.
@@ -60,16 +63,20 @@ def create_from_yaml(
60
63
yml_document_all = yaml .safe_load_all (f )
61
64
62
65
failures = []
66
+ k8s_objects = []
63
67
for yml_document in yml_document_all :
64
68
try :
65
- create_from_dict (k8s_client , yml_document , verbose ,
66
- namespace = namespace ,
67
- ** kwargs )
69
+ created = create_from_dict (k8s_client , yml_document , verbose ,
70
+ namespace = namespace ,
71
+ ** kwargs )
72
+ k8s_objects .append (created )
68
73
except FailToCreateError as failure :
69
74
failures .extend (failure .api_exceptions )
70
75
if failures :
71
76
raise FailToCreateError (failures )
72
77
78
+ return k8s_objects
79
+
73
80
74
81
def create_from_dict (k8s_client , data , verbose = False , namespace = 'default' ,
75
82
** kwargs ):
@@ -88,12 +95,16 @@ def create_from_dict(k8s_client, data, verbose=False, namespace='default',
88
95
the yaml file already contains a namespace definition
89
96
this parameter has no effect.
90
97
98
+ Returns:
99
+ The created kubernetes API objects.
100
+
91
101
Raises:
92
102
FailToCreateError which holds list of `client.rest.ApiException`
93
103
instances for each object that failed to create.
94
104
"""
95
105
# If it is a list type, will need to iterate its items
96
106
api_exceptions = []
107
+ k8s_objects = []
97
108
98
109
if "List" in data ["kind" ]:
99
110
# Could be "List" or "Pod/Service/...List"
@@ -106,23 +117,26 @@ def create_from_dict(k8s_client, data, verbose=False, namespace='default',
106
117
yml_object ["apiVersion" ] = data ["apiVersion" ]
107
118
yml_object ["kind" ] = kind
108
119
try :
109
- create_from_yaml_single_item (
120
+ created = create_from_yaml_single_item (
110
121
k8s_client , yml_object , verbose , namespace = namespace ,
111
122
** kwargs )
123
+ k8s_objects .append (created )
112
124
except client .rest .ApiException as api_exception :
113
125
api_exceptions .append (api_exception )
114
126
else :
115
127
# This is a single object. Call the single item method
116
128
try :
117
- create_from_yaml_single_item (
129
+ created = create_from_yaml_single_item (
118
130
k8s_client , data , verbose , namespace = namespace , ** kwargs )
131
+ k8s_objects .append (created )
119
132
except client .rest .ApiException as api_exception :
120
133
api_exceptions .append (api_exception )
121
134
122
135
# In case we have exceptions waiting for us, raise them
123
136
if api_exceptions :
124
137
raise FailToCreateError (api_exceptions )
125
138
139
+ return k8s_objects
126
140
127
141
def create_from_yaml_single_item (
128
142
k8s_client , yml_object , verbose = False , ** kwargs ):
@@ -160,6 +174,7 @@ def create_from_yaml_single_item(
160
174
if hasattr (resp , 'status' ):
161
175
msg += " status='{0}'" .format (str (resp .status ))
162
176
print (msg )
177
+ return resp
163
178
164
179
165
180
class FailToCreateError (Exception ):
0 commit comments