Skip to content

Models <-> Json/Yaml #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paultiplady opened this issue Dec 13, 2016 · 2 comments · Fixed by #108
Closed

Models <-> Json/Yaml #63

paultiplady opened this issue Dec 13, 2016 · 2 comments · Fixed by #108
Assignees

Comments

@paultiplady
Copy link

In addition to fully wrapping the k8s client and replacing kubectl, I've found it very useful to be able to generate raw JSON/YAML for objects created using the swagger generated schema models.

This makes a few other deployment methods easier, such as Spread or Helm.

Thoughts on whether it's worth adding to this project, and where the cleanest place would be? Seems like it should likely be some utility functions in the model layer, rather than patching the client (unless there's a built-in way of doing this with the swagger-codegen client).

@mbohlool
Copy link
Contributor

mbohlool commented Dec 14, 2016

I think converting models to JSON/Yaml and vice versa are both useful.

Converting models to json should be easy. Each model has a to_dict method:

import json
from kubernetes.models import V1Pod

v1Pod = ... # read it from somewhere
dic = v1Pod.to_dict()
print (json.dumps(dic))

Converting json to swagger model though is not straightforward I guess, we need to develop a utility method to do it with an interface like this:

from kubernetes import util  # maybe we would find better name than util

v1Pod = util.load(dict=v1_pod_dict)

The load method may support other parameters such as json, json_string, yaml, yaml_string, etc. to load from other sources. The util package can also have a dump or save method as an easy alternative to the above code (using to_dict)

@mbohlool mbohlool changed the title Dry-run command/method Models <-> Json/Yaml Jan 3, 2017
@mbohlool
Copy link
Contributor

Look like we should be able to pass a loaded json dic to an API call without any change. I will add an example for this, and if it worked, we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants