frankkkkk / pykorm Goto Github PK
View Code? Open in Web Editor NEWA python 🐍 kubernetes ☸️ ORM 🚀. Very useful when writing operators for your CRDs with Kopf.
License: MIT License
A python 🐍 kubernetes ☸️ ORM 🚀. Very useful when writing operators for your CRDs with Kopf.
License: MIT License
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:
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)
, ...).
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
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.
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 [] !
Very useful tool!
Was wondering whether it would be useful to have a utility that takes a CRD definition in yaml format and produces the necessary pykorm models.
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'
Some CRDs may have a status
element at their root. Thus we need a corresponding field
The method would compare the uid
and each individual field with the other model
May be related with @YiannisGkoufas issue
We can speedup the filter_by
method on Namespaced
objects when filtering by a specific namespace instead of crawling all the namespaces.
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
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?
Lines 4 to 20 in a38a9ae
If that is the case I'd propose to build these models & then create a PR to merge them into this lib
The source code should be further documented in order to generate an autodoc
A watch
function implemented as a generator would be really nice to have
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')
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.