Skip to main content

Wrapper around kubernetes-clients/python

Project description

Build Status Code style: black Type checker: mypy Packaging: poetry Packaging: poetry codecov

Tulips

A small wrapper around https://github.com/kubernetes-client/python which understands Kubernetes charts.

Why

I needed something simple that would read Helm charts and push them to the Kubernetes cluster and be extensible. So something like helm+kubectl with ability to write you own tools around them.

Supported CRDS aka Kubernetes resources

  • Deployment
  • Service
  • Ingress
  • Secret
  • Issuer (cert-manager)
  • PersistentVolumeClaim

Example use

import yaml
from tulips.resources import ResourceRegistry
from kubernetes import client as k8s
from kubernetes import config


client = config.new_client_from_config('kube.conf')

spec = yaml.load('ingress.yaml')

ingress_cls = ResourceRegistry.get_cls(spec['kind'])
ingress = ingress_cls(config.client, namespace='default', spec)
ingress.create()  # Create Ingress resource
ingress.delete()  # Delete Ingress resource

Adding new resource

In order to add support for new Kubernetes resource, one needs to create class that inherits from tulips.resources.Resource class.

Example resource

import tulips.resources.Resource

class ClusterIssuer(Resource):
    """A `cert-manager` ClusterIssuer resource."""

    version = "v1alpha1"
    group = "certmanager.k8s.io"
    plural = "clusterissuers"

    def delete(self, body: k8s.V1DeleteOptions):
        return k8s.CustomObjectsApi(
            self.client
        ).delete_namespaced_custom_object(
            body=body,
            namespace=self.namespace,
            version=self.version,
            group=self.group,
            plural=self.plural,
            name=self.name,
        )

    def create(self):
        return k8s.CustomObjectsApi(
            self.client
        ).create_namespaced_custom_object(
            body=self.resource,
            namespace=self.namespace,
            version=self.version,
            group=self.group,
            plural=self.plural,
        )

It will be registered into the ResourceRegistry and can be fetched via ResourceRegistry.get_cls method.

Tulip

Tulip is a sample client that emulates Helm but without tiller.

$ python tulips push --help                                    06/25/18 -  9:49
Usage: tulips push [OPTIONS] CHART

  You can pass chart variables via foo=bar, for example '$ tulip push
  app.yaml foo=bar'

Options:
  --namespace TEXT   Kubernetes namespace
  --release TEXT     Name of the release
  --kubeconfig PATH  Path to kubernetes config
  --help             Show this message and exit.

Example client

Let's say that I want to deploy a Secret and Ingress

apiVersion: v1
kind: Secret
metadata:
  name: {{ release }}-secrets
type: Opaque
data:
  password: {{ @pwd }}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ release }}-web-ingress
  labels:
    app: woocart-{{ release }}
  annotations:
    nginx.ingress.kubernetes.io/limit-connections: "100"
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: {{ domain }}
    http:
      paths:
        - path: /
          backend:
            serviceName: {{ release }}-web
            servicePort: 80

If one runs `tulip --release test push --kubeconf kube.conf app.yaml domain=test.tld'

Spec file is inspected and all {{ variables }} are replaced with real values. Also special {{ @pwd }} will generate strong password using passlib library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tulips-1.2.7.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

tulips-1.2.7-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file tulips-1.2.7.tar.gz.

File metadata

  • Download URL: tulips-1.2.7.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.11.5 CPython/3.7.0 Linux/4.18.0-13-generic

File hashes

Hashes for tulips-1.2.7.tar.gz
Algorithm Hash digest
SHA256 b7913f310c446a41c284eb498c6ed3d7ffe87b86d66a04d59314dfc0353b93f3
MD5 a29f55e136453fc1bdbc5fb277d4c30e
BLAKE2b-256 0b4e43f7066f253b76c1a34411d1f6bd994148244835b6a3016f105590ef7d54

See more details on using hashes here.

File details

Details for the file tulips-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: tulips-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.11.5 CPython/3.7.0 Linux/4.18.0-13-generic

File hashes

Hashes for tulips-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fb87e5f73e4f6772ddb9d4739f0ce76b77e7a223aa615580c7cc9d8aa00f3a1f
MD5 3d5b7304dd17f4b92cdf90d9922fc621
BLAKE2b-256 b1cf8cad90e9462a95e7ef0347555dde105522e3c9b0f8cc0e6854b90ab57a33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page