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

Function create_from_directory

kubernetes/utils/create_from_yaml.py:27–96  ·  view source on GitHub ↗

Perform an action from files from a directory. Pass True for verbose to print confirmation information. Input: k8s_client: an ApiClient object, initialized with the client args. yaml_dir: string. Contains the path to directory. verbose: If True, print confirmation from the

(
    k8s_client, yaml_dir=None, verbose=False, namespace="default", apply=False, **kwargs
)

Source from the content-addressed store, hash-verified

25
26
27def create_from_directory(
28 k8s_client, yaml_dir=None, verbose=False, namespace="default", apply=False, **kwargs
29):
30 """
31 Perform an action from files from a directory. Pass True for verbose to
32 print confirmation information.
33
34 Input:
35 k8s_client: an ApiClient object, initialized with the client args.
36 yaml_dir: string. Contains the path to directory.
37 verbose: If True, print confirmation from the create action.
38 Default is False.
39 namespace: string. Contains the namespace to create all
40 resources inside. The namespace must preexist otherwise
41 the resource creation will fail. If the API object in
42 the yaml file already contains a namespace definition
43 this parameter has no effect.
44 apply: bool. If True, use server-side apply for creating resources.
45
46 Available parameters for creating <kind>:
47 :param async_req bool
48 :param bool include_uninitialized: If true, partially initialized
49 resources are included in the response.
50 :param str pretty: If 'true', then the output is pretty printed.
51 :param str dry_run: When present, indicates that modifications
52 should not be persisted. An invalid or unrecognized dryRun
53 directive will result in an error response and no further
54 processing of the request.
55 Valid values are: - All: all dry run stages will be processed
56
57 Returns:
58 The list containing the created kubernetes API objects.
59
60 Raises:
61 FailToCreateError which holds list of `client.rest.ApiException`
62 instances for each object that failed to create.
63 """
64
65 if not yaml_dir:
66 raise ValueError("`yaml_dir` argument must be provided")
67 elif not os.path.isdir(yaml_dir):
68 raise ValueError("`yaml_dir` argument must be a path to directory")
69
70 files = [
71 os.path.join(yaml_dir, i)
72 for i in os.listdir(yaml_dir)
73 if os.path.isfile(os.path.join(yaml_dir, i))
74 ]
75 if not files:
76 raise ValueError("`yaml_dir` contains no files")
77
78 failures = []
79 k8s_objects_all = []
80
81 for file in files:
82 try:
83 k8s_objects = create_from_yaml(
84 k8s_client,

Callers

nothing calls this directly

Calls 2

create_from_yamlFunction · 0.70
FailToCreateErrorClass · 0.70

Tested by

no test coverage detected