Coder Social home page Coder Social logo

meallia / kubernetes_asyncio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomplus/kubernetes_asyncio

0.0 0.0 0.0 13.63 MB

Python asynchronous client library for Kubernetes http://kubernetes.io/

License: Apache License 2.0

Shell 0.11% Python 99.89%

kubernetes_asyncio's Introduction

Kubernetes Python Client

Build status PyPI version Docs codecov pypi supported versions Client Capabilities Client Support Level

Asynchronous (AsyncIO) client library for the Kubernetes API.

This library is created in the same way as official https://github.com/kubernetes-client/python but uses asynchronous version of OpenAPI generator. My motivation is described here: kubernetes-client/python#324

Installation

From PyPi directly:

pip install kubernetes_asyncio

It requires Python 3.6+

Example

To list all pods:

import asyncio
from kubernetes_asyncio import client, config
from kubernetes_asyncio.client.api_client import ApiClient


async def main():
    # Configs can be set in Configuration class directly or using helper
    # utility. If no argument provided, the config will be loaded from
    # default location.
    await config.load_kube_config()

    # use the context manager to close http sessions automatically
    async with ApiClient() as api:

        v1 = client.CoreV1Api(api)
        print("Listing pods with their IPs:")
        ret = await v1.list_pod_for_all_namespaces()

        for i in ret.items:
            print(i.status.pod_ip, i.metadata.namespace, i.metadata.name)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()

More complicated examples, like asynchronous multiple watch or tail logs from pods, you can find in examples/ folder.

Documentation

https://kubernetes-asyncio.readthedocs.io/

Compatibility

This library is generated in the same way as the official Kubernetes Python Library. It uses swagger-codegen and the same concepts like streaming, watching or reading configuration. Because of an early stage of this library some differences still exist:

synchronous library kubernetes-client/python this library
authentication method gcp-token, azure-token, user-token, oidc-token, user-password, in-cluster gcp-token (only via gcloud command), user-token, oidc-token, user-password, in-cluster
streaming data via websocket from PODs bidirectional read-only is already implemented

Microsoft Windows

In case this library is used against Kubernetes cluster using client-go credentials plugin, the default asyncio event loop is SelectorEventLoop. This event loop selector, however, does NOT support pipes and subprocesses, so exec_provider.py::ExecProvider is failing. In order to avoid failures the ProactorEventLoop has to be selected. The ProactorEventLoop can be enabled via WindowsProactorEventLoopPolicy.

Application's code needs to contain following code:

import asyncio

asyncio.set_event_loop_policy(
    asyncio.WindowsProactorEventLoopPolicy()
)

Versions

This library is versioned in the same way as the synchronous library. The schema version has been changed with version v18.20.0. Now, first two numbers from version are Kubernetes version (v.1.18.20). The last number is for changes in the library not directly connected with K8s.

Development

Install the development packages:

pip install -r requirements.txt
pip install -r test-requirements.txt

You can run the style checks and tests with

flake8 kubernetes_asyncio/
isort --diff kubernetes_asyncio/
py.test

kubernetes_asyncio's People

Contributors

tomplus avatar dependabot[bot] avatar olitheolix avatar glassofwhiskey avatar jacobhenner avatar jnschaeffer avatar multani avatar ak0nshin avatar shtlrs avatar bpicolo avatar bobh66 avatar consideratio avatar harryharpel avatar hubo1016 avatar hrichardlee avatar icamposrivera avatar jean-daniel avatar juliantaylor avatar mickours avatar lejmr avatar kexirong avatar evemorgen avatar mcreng avatar pidgeybe avatar wolph avatar videosystemstech avatar weltonrodrigo avatar wh1isper avatar epdhowwd avatar tkauf15k 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.