Perform an action from a yaml file. Pass True for verbose to print confirmation information. Input: yaml_file: string. Contains the path to yaml file. data: a dictionary holding valid kubernetes objects verbose: If True, print confirmation from the create action. Def
(
k8s_client,
data,
verbose=False,
namespace="default",
**kwargs)
| 80 | |
| 81 | |
| 82 | async def create_from_dict( |
| 83 | k8s_client, |
| 84 | data, |
| 85 | verbose=False, |
| 86 | namespace="default", |
| 87 | **kwargs): |
| 88 | """ |
| 89 | Perform an action from a yaml file. Pass True for verbose to |
| 90 | print confirmation information. |
| 91 | Input: |
| 92 | yaml_file: string. Contains the path to yaml file. |
| 93 | data: a dictionary holding valid kubernetes objects |
| 94 | verbose: If True, print confirmation from the create action. |
| 95 | Default is False. |
| 96 | namespace: string. Contains the namespace to create all |
| 97 | resources inside. The namespace must preexist otherwise |
| 98 | the resource creation will fail. If the API object in |
| 99 | the yaml file already contains a namespace definition |
| 100 | this parameter has no effect. |
| 101 | Returns: |
| 102 | An k8s api object or list of apis objects created from dict. |
| 103 | When a single object is generated, return type is dependent |
| 104 | on output_list. |
| 105 | Throws a FailToCreateError exception if creation of any object |
| 106 | fails with helpful messages from the server. |
| 107 | Available parameters for creating <kind>: |
| 108 | :param async_req bool |
| 109 | :param bool include_uninitialized: If true, partially initialized |
| 110 | resources are included in the response. |
| 111 | :param str pretty: If 'true', then the output is pretty printed. |
| 112 | :param str dry_run: When present, indicates that modifications |
| 113 | should not be persisted. An invalid or unrecognized dryRun |
| 114 | directive will result in an error response and no further |
| 115 | processing of the request. |
| 116 | Valid values are: - All: all dry run stages will be processed |
| 117 | """ |
| 118 | api_exceptions = [] |
| 119 | k8s_objects = [] |
| 120 | |
| 121 | # If it is a list type, will need to iterate its items |
| 122 | if "List" in data["kind"]: |
| 123 | # Could be "List" or "Pod/Service/...List" |
| 124 | # This is a list type. iterate within its items |
| 125 | kind = data["kind"].replace("List", "") |
| 126 | for yml_object in data["items"]: |
| 127 | # Mitigate cases when server returns a xxxList object |
| 128 | # See kubernetes-client/python#586 |
| 129 | if kind != "": |
| 130 | yml_object["apiVersion"] = data["apiVersion"] |
| 131 | yml_object["kind"] = kind |
| 132 | try: |
| 133 | created = await create_from_yaml_single_item( |
| 134 | k8s_client, yml_object, verbose, namespace, **kwargs) |
| 135 | k8s_objects.append(created) |
| 136 | except client.rest.ApiException as api_exception: |
| 137 | api_exceptions.append(api_exception) |
| 138 | else: |
| 139 | # This is a single object. Call the single item method |