MCPcopy Create free account
hub / github.com/kubernetes-client/python / create_from_yaml

Function create_from_yaml

kubernetes/aio/utils/create_from_yaml.py:24–79  ·  view source on GitHub ↗

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. k8s_client: an ApiClient object, initialized with the client args. verbose: If True, print confirmation from the create acti

(
        k8s_client,
        yaml_file,
        verbose=False,
        namespace="default",
        **kwargs)

Source from the content-addressed store, hash-verified

22
23
24async def create_from_yaml(
25 k8s_client,
26 yaml_file,
27 verbose=False,
28 namespace="default",
29 **kwargs):
30 """
31 Perform an action from a yaml file. Pass True for verbose to
32 print confirmation information.
33 Input:
34 yaml_file: string. Contains the path to yaml file.
35 k8s_client: an ApiClient object, initialized with the client args.
36 verbose: If True, print confirmation from the create action.
37 Default is False.
38 namespace: string. Contains the namespace to create all
39 resources inside. The namespace must preexist otherwise
40 the resource creation will fail. If the API object in
41 the yaml file already contains a namespace definition
42 this parameter has no effect.
43 Returns:
44 An k8s api object or list of apis objects created from YAML.
45 When a single object is generated, return type is dependent
46 on output_list.
47 Throws a FailToCreateError exception if creation of any object
48 fails with helpful messages from the server.
49 Available parameters for creating <kind>:
50 :param async_req bool
51 :param bool include_uninitialized: If true, partially initialized
52 resources are included in the response.
53 :param str pretty: If 'true', then the output is pretty printed.
54 :param str dry_run: When present, indicates that modifications
55 should not be persisted. An invalid or unrecognized dryRun
56 directive will result in an error response and no further
57 processing of the request.
58 Valid values are: - All: all dry run stages will be processed
59 """
60
61 with open(path.abspath(yaml_file)) as f:
62 yml_document_all = yaml.safe_load_all(f)
63 api_exceptions = []
64 k8s_objects = []
65 # Load all documents from a single YAML file
66 for yml_document in yml_document_all:
67 try:
68 created = await create_from_dict(k8s_client, yml_document,
69 verbose, namespace=namespace,
70 **kwargs)
71 k8s_objects.append(created)
72 except FailToCreateError as failure:
73 api_exceptions.append(failure)
74
75 # In case we have exceptions waiting for us, raise them
76 if api_exceptions:
77 raise FailToCreateError(api_exceptions)
78
79 return k8s_objects
80
81

Callers 1

test_create_from_yamlMethod · 0.90

Calls 2

create_from_dictFunction · 0.70
FailToCreateErrorClass · 0.70

Tested by 1

test_create_from_yamlMethod · 0.72