All Projects β†’ Frankkkkk β†’ pykorm

Frankkkkk / pykorm

Licence: MIT license
A python 🐍 kubernetes ☸️ ORM πŸš€. Very useful when writing operators for your CRDs with Kopf.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to pykorm

ECS-CommunityEdition
ECS Community Edition "Free & Frictionless"
Stars: ✭ 125 (+123.21%)
Mutual labels:  object
kubereplay
Seamless integration of goReplay and Kubernetes
Stars: ✭ 30 (-46.43%)
Mutual labels:  crd
KazukoBot
An anime themed telegram group management bot based on sqlalchemy database running on python3.
Stars: ✭ 25 (-55.36%)
Mutual labels:  sqlalchemy
sqlconstruct
Functional approach to query database using SQLAlchemy
Stars: ✭ 22 (-60.71%)
Mutual labels:  sqlalchemy
timely-beliefs
Model data as beliefs (at a certain time) about events (at a certain time).
Stars: ✭ 15 (-73.21%)
Mutual labels:  sqlalchemy
FastAPI-Full-Stack-Samples
The API Application Development using Python FastAPI, including interactive API documentation
Stars: ✭ 61 (+8.93%)
Mutual labels:  sqlalchemy
viaduct
CMS for via. Moved to https://gitlab.com/studieverenigingvia/viaduct
Stars: ✭ 16 (-71.43%)
Mutual labels:  sqlalchemy
prototyped.js
Some common Typescript prototypes
Stars: ✭ 22 (-60.71%)
Mutual labels:  object
flask-celery-sqlalchemy
An example app to show how to get Flask, Celery, and SQLAlchemy working together
Stars: ✭ 33 (-41.07%)
Mutual labels:  sqlalchemy
fast-api-sqlalchemy-template
Dockerized web application on FastAPI, sqlalchemy1.4, PostgreSQL
Stars: ✭ 25 (-55.36%)
Mutual labels:  sqlalchemy
expand-hash
Recursively expands property keys with dot-notation into objects.
Stars: ✭ 25 (-55.36%)
Mutual labels:  object
kaos
Kinda Chaos Monkey for Kubernetes
Stars: ✭ 18 (-67.86%)
Mutual labels:  crd
object-keys
Object.keys shim
Stars: ✭ 41 (-26.79%)
Mutual labels:  object
Apollo
A basic Application with multiple functionalities built with FastAPI aim to help Users Buy New Items Provided using PaypalAPI πŸš€
Stars: ✭ 22 (-60.71%)
Mutual labels:  sqlalchemy
rename-keys
Modify/rename the keys of the own enumerable properties of an object.
Stars: ✭ 28 (-50%)
Mutual labels:  object
object-book
Study Object book Content Repository / 쑰영호 λ‹˜μ˜ 였브젝트 책을 ν•™μŠ΅ν•˜κ³  μ •λ¦¬ν•œ Repoμž…λ‹ˆλ‹€.
Stars: ✭ 30 (-46.43%)
Mutual labels:  object
sqlalchemy-enum34
SQLAlchemy type to store standard enum.Enum values
Stars: ✭ 47 (-16.07%)
Mutual labels:  sqlalchemy
FinanceCenter
Fetching Financial Data (US/ChinaοΌ‰
Stars: ✭ 26 (-53.57%)
Mutual labels:  sqlalchemy
pydbantic
A single model for shaping, creating, accessing, storing data within a Database
Stars: ✭ 137 (+144.64%)
Mutual labels:  sqlalchemy
flask-db
A Flask CLI extension to help migrate and manage your SQL database.
Stars: ✭ 56 (+0%)
Mutual labels:  sqlalchemy

pykorm - Python Kubernetes Object-relational mapping (ORM)

pykorm is a simple library that links your models to their kubernetes counterpart.

Each model and instance on your code is thus directly linked to your kubernetes cluster and modifications are thus reflected both ways.

Examples

Namespaced Custom Resource

Setup

First of all, you need to have Custom Resource Definitions on your cluster.
This README will use the following Namespaced resource. You can apply it on your cluster with kubectl.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: peaches.pykorm.infomaniak.com
spec:
  group: pykorm.infomaniak.com
  names:
    kind: Peach
    listKind: PeachList
    plural: peaches
    singular: peach
  scope: Namespaced
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              variety:
                type: string
            required:
              - variety


    additionalPrinterColumns:
    - name: Variety
      type: string
      description: The variety of the peach
      jsonPath: .spec.variety

Class definition

In order to link a python class to a kubernetes CustomResourceDefinition, you need to inherit the class from pykorm's NamespacedModel or ClusterModel and annotate it with the kubernetes CRD information like so:

import pykorm

@pykorm.k8s_custom_object('pykorm.infomaniak.com', 'v1', 'peaches')
class Peach(pykorm.NamespacedModel):
    variety: str = pykorm.fields.Spec('variety')

Notice that a class inheriting from pykorm.NamespacedModel already has the name and namespace fields setup.

Create a CR

In order to create a kubernetes custom resource from python, you just have to instantiate the class and save it with Pykorm.save():

import pykorm
pk = pykorm.Pykorm()

cake_peach = Peach(namespace='default', name='cake-peach', variety='Frost')
pk.save(cake_peach)  # We save the resource

as you can see, the model is instantly ensured in kubernetes:

$ kubectl get peach -n default
NAME         VARIETY
cake-peach   Frost

List resources

Pykorm can also list resources from kubernetes

>>> all_peaches = Peach.query.all()
>>> for peach in all_peaches:
>>>  print(peach)
<Peach namespace=default, name=cake-peach, variety=Frost>

# Filter by namespace
>>> Peach.query.filter_by(namespace='default').filter_by(variety='Frost').all()

You can even filter resources by some criterion:

>>> Peach.query.filter_by(name='cake-peach').all()
[<Peach namespace=default, name=cake-peach, variety=Frost>]
>>> Peach.query.filter_by(namespace='kube-system').all()
[]

Delete resources

You can delete a resource with pykorm too:

pk.delete(peach)
$ kubectl get peach
No resources found in default namespace.

More examples

For more examples, don't hesitate to look into the examples/ directory

Is pykorm stable ?

pykorm is still very young and very naive. It's also missing quite a lot of features (relationships, etc.). It was originally created because a lot of boilerplate code was written each time a kubernetes custom object had to be interfaced with python code.

Work on pykorm is actually on the way. Don't hesitate to contribute to the project if you have the energy for it !

Equivalences

Python Kubernetes
Class CustomResourceDefinition
Instance CustomResource
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].