8000 Rename yml_document paramter and update documentation · abhinavcoder/python@f6566ee · GitHub
[go: up one dir, main page]

Skip to content

Commit f6566ee

Browse files
committed
Rename yml_document paramter and update documentation
Renaming `yml_document` in `create_from_dict` to data. This is a bit clearer that this it a data item and not a string (usually document read from the file system). Also update the documentation to describe better what the functions `create_from_dict` and `create_from_yaml` do.
1 parent 139848e commit f6566ee

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

kubernetes/utils/create_from_yaml.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def create_from_yaml(
3939
verbose: If True, print confirmation from the create action.
4040
Default is False.
4141
42-
Returns:
43-
An k8s api object or list of apis objects created from YAML.
44-
When a single object is generated, return type is dependent
45-
on output_list.
46-
4742
Throws a FailToCreateError exception if creation of any object
4843
fails with helpful messages from the server.
4944
@@ -80,19 +75,34 @@ def create_from_yaml(
8075
raise FailToCreateError(fail_exceptions)
8176

8277

83-
def create_from_dict(k8s_client, yml_document, verbose=False, **kwargs):
78+
def create_from_dict(k8s_client, data, verbose=False, **kwargs):
79+
"""
80+
Perform an action from a dictionary containing one or more valid kubernetes
81+
objects
82+
83+
Input:
84+
k8s_client: an ApiClient object, initialized with the client args.
85+
data: a dictionary holding valid kubernetes objects
86+
verbose: If True, print confirmation from the create action.
87+
Default is False.
88+
89+
Returns:
90+
A list of `client.rest.ApiException` instances for each object that
91+
failed to create. The user of this function can throw discard them.
92+
93+
"""
8494
# If it is a list type, will need to iterate its items
8595
api_exceptions = []
8696

87-
if "List" in yml_document["kind"]:
97+
if "List" in data["kind"]:
8898
# Could be "List" or "Pod/Service/...List"
8999
# This is a list type. iterate within its items
90-
kind = yml_document["kind"].replace("List", "")
91-
for yml_object in yml_document["items"]:
100+
kind = data["kind"].replace("List", "")
101+
for yml_object in data["items"]:
92102
# Mitigate cases when server returns a xxxList object
93103
# See kubernetes-client/python#586
94104
if kind is not "":
95-
yml_object["apiVersion"] = yml_document["apiVersion"]
105+
yml_object["apiVersion"] = data["apiVersion"]
96106
yml_object["kind"] = kind
97107
try:
98108
create_from_yaml_single_item(
@@ -103,7 +113,7 @@ def create_from_dict(k8s_client, yml_document, verbose=False, **kwargs):
103113
# This is a single object. Call the single item method
104114
try:
105115
create_from_yaml_single_item(
106-
k8s_client, yml_document, verbose, **kwargs)
116+
k8s_client, data, verbose, **kwargs)
107117
except client.rest.ApiException as api_exception:
108118
api_exceptions.append(api_exception)
109119

0 commit comments

Comments
 (0)
0