kubernetes-client / python

Official Python client library for kubernetes
http://kubernetes.io/
Apache License 2.0
6.55k stars 3.24k forks source link

Implement base class for Kubernetes model classes #784

Open davidxia opened 5 years ago

davidxia commented 5 years ago

This is a feature request. Most of the Kubernetes objects have a set of fields in common:

Currently the various model classes all inherit from object. Is there a way to implement a base class for all k8s resources and have all the models extend that?

It'd also be nice to have utils.parse_from_yaml(yaml_file) that just parses a YAML file into the correct model (no API requests at all). I'm not sure how the models are generated, but I suspect it may be related to this analogous java client issue.

micw523 commented 5 years ago

These are two different feature requests. 1) This has to happen via swagger-codegen, although we're switching to another generator right now. 2) I'm not sure why you want a model object from a yaml file... can you potentially list some examples when it could be useful?

davidxia commented 5 years ago

@micw523, yes thanks for clarifying.

I'm not sure why you want a model object from a yaml file... can you potentially list some examples when it could be useful?

A lot of the tools I'm building on top of k8s involves validating and mutating k8s YAML files. The input to these tools are almost always an unknown number of YAML docs representing various k8s kinds. It'd be super useful to be able to parse them easily into a list of upstream k8s classes that make it easy to get or change attributes in a fluent or type-hinted way.

Here are some use cases.

validation

mutation

Let me know if I should create a separate issue for this feature request.

fejta-bot commented 5 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

davidxia commented 5 years ago

/remove-lifecycle stale

fejta-bot commented 4 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

davidxia commented 4 years ago

/remove-lifecycle stale

fejta-bot commented 4 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

davidxia commented 4 years ago

/remove-lifecycle stale

fejta-bot commented 4 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

palnabarun commented 4 years ago

/remove-lifecycle stale

palnabarun commented 4 years ago

/lifecycle frozen