Giter VIP home page Giter VIP logo

pykorm's Issues

Add object relationships

We should add a Relationship field whose role is to reference another resource.

However, how to deal with references to other namespaces ? We could support:

  • ClusterResource → ClusterResource
  • NamespacedResource(ns n) → NamespacedResource(ns n)
  • NamespacedResource(ns n) → Cluster resource

Support `status` subresource

In most cases the status field in the root is a subresource and can't be updated with the same api as spec or metadata. There are separate APIs like create_namespaced_pod_status, patch_namespaced_custom_object_status, etc.

I've worked around this by creating a mixin that I add to all model classes and provides a method that calls the relevant *_status variant of the APIs but it would be nice if this could be supported by pykorm directly. Either by calling both on save()/apply() if there is a Status field in the model or even a separate way (pk.status().save(obj), pk.save_status(obj), ...).

Make pykorm faster on large number of objects

Pykorm is rather slow when dealing with a large number of objects. In my case, at ~850 objects, an .all() query takes around 20s !

>>> a = time.time() ; len(list(MyCRD.query.all())); print(time.time() - a)
851
21.512641668319702

in comparison, kubectl takes only 1s:

$ time kl get MyCRD.p6k.ch -A 
real	0m1.392s
user	0m0.536s
sys	0m0.182s

Dont send to k8s None fields

When creating aand saving a model with some empty (non mandatory) fields, it will fail because of the default value which will be None.

We should skip this attribute.

Field default attributes are not copied on object instantiation

CRDs fields can have default values:

@pykorm.k8s_custom_object('pykorm.infomaniak.com', 'v1', 'foo')
class Foo(ScoreMixin, pykorm.NamespacedModel):
    colours: list = pykorm.fields.Spec('colours', [])

However, the default value of the field is not copied on object instantiation. This results in bugs like these:

f1 = Foo(...)
f1.colours = ['foo']

f2 = Foo(...)
print(f2.colours)  # -> ['foo'] . Should return [] !

DictNestedField field wrongly inited

Models using DictNestedField fields are wrongly inited and can't be used for writing:

Example (from XXX):

class Score(pykorm.models.Nested):
    exterior: int = pykorm.fields.DataField('exterior')
    delicious: int = pykorm.fields.DataField('delicious', 10)


@pykorm.k8s_custom_object('pykorm.infomaniak.com', 'v1', 'peaches')
class Peach(pykorm.NamespacedModel):
    variety: str = pykorm.fields.Spec('variety', default='default-variety')
    price: str = pykorm.fields.Spec('price', default=1)
    colours: list = pykorm.fields.Spec('colours', default=[])
    score: Score = pykorm.fields.DictNestedField(Score, path=['spec', 'score'])

Results in the following error when writing to p.score.delicious:

>       p.score.exterior = 42
E       AttributeError: 'NoneType' object has no attribute 'exterior'

filter_by: add namespace speedup

We can speedup the filter_by method on Namespaced objects when filtering by a specific namespace instead of crawling all the namespaces.

Add k8s_batchv1 et al

Pykorm supports CRDs, as well as core objects and apps/v1 objects. But many are missing (e.g. batch/v1 for example). We should add them too

Provide pre-built models for all core k8s resource

I'm currently looking into using pykorm for a small project that I'm building with kopf. So far I've been using pykube but I'm not really happy with it's API.
pykorm looks very promising as it allows to properly map my CRD & core k8s resource to python objects.

One thing that are not clear to me or maybe might be missing are default models within pykorm for all the existing core resources.
Based on the example below i assume that i would need to build the models on my own?

@pykorm.pykorm.k8s_core(kind='Event')
class Event(pykorm.models.NamespacedModel):
action: str = pykorm.fields.DataField('action')
reason: str = pykorm.fields.DataField('reason')
type: str = pykorm.fields.DataField('type')
message: str = pykorm.fields.DataField('message')
@pykorm.pykorm.k8s_core(kind='Pod')
class Pod(pykorm.models.NamespacedModel):
_conditions: list = pykorm.fields.Status('conditions')
_containerStatuses: list = pykorm.fields.Status('containerStatuses', default=[])
_containers: list = pykorm.fields.Spec('containers', default=[])
_init_containers: list = pykorm.fields.Spec('initContainers', default=[])
_initContainerStatuses: list = pykorm.fields.Spec('initContainerStatuses', default=[])
phase: str = pykorm.fields.Status('phase')

If that is the case I'd propose to build these models & then create a PR to merge them into this lib

Add nested fields

AnyISalIn's MR #11 introduced nested fields. It wasn't merged in #13 because some tests didn't pass and the change would've been too big.

However the idea was really good and they should be inttroduced into pykorm

Document the code

The source code should be further documented in order to generate an autodoc

Add selection of kubeconfig to use

We should add the ability to choose a specific kubeconfig (when connecting to different cluster for example).

pk = pykorm.Pykorm(kubeconfig_file='foo/bar.yaml')

Allow the modification of readonly fields

Read only fields were meant to be read only. However sometimes these fields must be set (in the case of an operator managing these resources for example).

We should add a mean to edit these fields with a context manager for example:

with pykorm.fields.UnlockReadOnly:
  obj.read_only = 42

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.