Code Monkey home page Code Monkey logo

tiny-kubernetes's Introduction

tiny-kubernetes

tiny-kubernetes provides a thin wrapper on top of requests to make it easier to work with Kubernetes APIs.

Features

  • Automatic authentication ($KUBECONFIG)
  • Simplified response traversal (never['do']['this']['again'])
  • Sane exceptions
  • No crazy complex client-side APIs to deal with

Why?

The official kubernetes package is, uh, complex. While it does support all the advanced features the Kubernetes API offers (like WebSocket streaming) it is often non-trivial to work with. tiny-kubernetes aims to provide most of the same functionality with minimal overhead.

Installation

To manually install, run:

pip install git+https://github.com/monasca/tiny-kubernetes.git

To depend on tiny-kubernetes from requirements.txt, add the following:

-e git+https://github.com/monasca/tiny-kubernetes.git#egg=tiny-kubernetes

(note: requires pip 7.0 or greater)

You can depend on a specific commit too:

-e git+https://github.com/monasca/tiny-kubernetes.git@[GIT SHA]#egg=tiny-kubernetes

Usage

from tiny_kubernetes import KubernetesAPIClient

client = KubernetesAPIClient()
client.load_auto_config()

pods = client.get('/api/v1/namespaces/{}/pods', 'default')
for pod in pods['items']:
  print pod.metadata.name

Notice that you can access (almost) all parts of the Kubernetes API response using dot accessors (courtesy of DotMap). As .items() is a reserved name in dictionaries, it needs to be accessed more traditionally, but most other member names can use the shortened syntax.

The endpoint is formatted using str.format with the remaining positional arguments. All keyword arguments are passed through to requests's Session.request, so you can include a body with json={...} or URL parameters with params={...}.

A special json_patch method exists to help perform patches. It works around a few potential requests bugs automatically. For example, it can be used to append labels to a resource:

client.json_patch([
  'op': 'add',
  'path': '/metadata/labels/foo',
  'value': 'bar'
], '/api/v1/namespaces/{}/pods/{}', 'default', 'some-pod')

Notes

  • Temporary files may be created if using a local $KUBECONFIG with base64-encoded certificates. Due to limitations in python's SSL library these must be decoded and written to the filesystem to be used. They should be cleaned up when the interpreter exits.

tiny-kubernetes's People

Contributors

timothyb89 avatar

Watchers

James Cloos avatar Andrea Adams avatar

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.