Closed
Description
create_from_yaml
should accept a string like object, like yaml.load
and safe_safe
do.
Then, it's the user's task to read the file.
To help users we can add a function create_from_file
which accept a file path. create_from_file
will than call create_from_yaml
.
The new signatures should be:
def create_from_yaml(k8s_client, yaml_str, verbose=False, **kwargs):
"""
load yaml string and apply using `create_from_map`
"""
stream = yaml.safe_load_all(yaml_str)
for obj in stream:
create_from_map(k8s_client, obj, verbos)
...
def create_from_file(k8s_client, path_str, verbose=False, **kwargs):
"""
read a file and continue with create_from_yaml
"""
...
Additionally, we should add:
def create_from_json(k8s_client, json_str, verbose=False, **kwargs):
"""
read a json like string and apply by using create_from_map
"""
...
def create_from_map(k8s_client, dict_like, verbose=False, **kwargs):
"""
does all the logic previously in create_from_file.
"""
This approach brings the python client a little bit closer to
kubectl create -f <filename>
which accepts either files and streams from stdin, file, formatted as json and yaml).
I will happily prepare patch for this.