Skip to main content

CircleCI 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.

Release files for tulips 1.5.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tulips 1.5.10
File Size Uploaded
tulips-1.5.10.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tulips 1.5.10
File Interpreter ABI Platform
tulips-1.5.10-py3-none-any.whl Python 3 none any Details

Total release size:23.2 kB

Release files / tulips-1.5.10.tar.gz

Download URL tulips-1.5.10.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9cbbf487cc9d7f43ef5c4be0c5970b2d5bde8013f47cfda921482268fcbc1850
BLAKE2b-256 checksum
How to use checksums
2faeb53c04568a612784acef97854640f80c7e103f3581cd02b38bc58ca39712
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.0 CPython/3.8.7 Linux/5.13.0-20-generic

Release files / tulips-1.5.10-py3-none-any.whl

Download URL tulips-1.5.10-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
262a1bcdfbe7f37724084e75a5d609217742678ec0b25d9c6fc7f182a377443f
BLAKE2b-256 checksum
How to use checksums
7f74b4fbbe6b99bc10f894419a341adccb7c1d8f789c1264bbcbb3f70ce51b2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.0 CPython/3.8.7 Linux/5.13.0-20-generic

Release history Release notifications | RSS feed

This release

1.5.10 This release

2 release files

1.5.9

2 release files

1.5.8

2 release files

1.5.7

2 release files

1.5.6

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.24

2 release files

1.1.20

2 release files

1.1.19

2 release files

1.1.18

2 release files

1.1.17

2 release files

1.1.16

2 release files

1.1.15

2 release files

1.1.14

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page