python icon indicating copy to clipboard operation
python copied to clipboard

Implement base class for Kubernetes model classes

Open davidxia opened this issue 6 years ago • 11 comments
trafficstars

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

  • kind
  • apiVersion
  • metadata
  • spec

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.

davidxia avatar Mar 18 '19 22:03 davidxia

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?

micw523 avatar Mar 19 '19 05:03 micw523

@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

  • only allow certain k8s kinds. e.g. allow Deployments but not DaemonSets
  • check resource has a required annotation or label, e.g. namespace has an annotation indicating the team that owns it
  • check ResourceQuota values are valid, e.g. a team isn't requesting an excessive amount of resources for their namespace

mutation

  • add labels or annotations to resources, e.g. add an annotation to a Deployment indicating who/what applied it
  • adding a sidecar container or env vars that are needed by all Pods

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

davidxia avatar Mar 19 '19 15:03 davidxia

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

fejta-bot avatar Jun 17 '19 15:06 fejta-bot

/remove-lifecycle stale

davidxia avatar Jun 17 '19 17:06 davidxia

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

fejta-bot avatar Sep 15 '19 17:09 fejta-bot

/remove-lifecycle stale

davidxia avatar Sep 15 '19 17:09 davidxia

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

fejta-bot avatar Dec 14 '19 18:12 fejta-bot

/remove-lifecycle stale

davidxia avatar Dec 14 '19 18:12 davidxia

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

fejta-bot avatar Mar 13 '20 19:03 fejta-bot

/remove-lifecycle stale

palnabarun avatar Mar 25 '20 21:03 palnabarun

/lifecycle frozen

palnabarun avatar Mar 25 '20 21:03 palnabarun