Code Monkey home page Code Monkey logo

openapi-collector's Introduction

Kubernetes OpenAPI Spec Collector

Build Status Coverage Status

Kubernetes OpenAPI Spec Collector aggregates (collects) all specifications exposed by services inside a Kubernetes Cluster, into a single UI for quick exploration.

By processing annotated Services, the UI is automatically updated with new specifications as they are added or evolve, and is an excellent way to explore APIs.

This project was heavily inspired in style and implementation by hjacobs/kube-janitor.

Design

Architecture Diagram

The OpenAPI Collector Pod consists of 4 containers; ui, router, proxy and collector. Two ConfigMaps (one for the ui config, one for the router config) are also required. These ConfigMaps are automatically updated by the collector container, which polls the Kubernetes API to find Services exposing OpenAPI Specs.

Containers

  • ui

    This is a plain swagger-ui container, that is configured to retrieve its configuration from a local /swagger-config.json endpoint (served by the router). This UI should be accessed via the router.

  • router

    This container is one half of the brain of the OpenAPI Collector. It is powered by nginx and all requests flow through this. Requests are then fanned out accordingly to either the ui, proxy or backend services directly.

  • proxy

    This container is a small Flask application that augments the OpenAPI spec that is collected, to insert a new, fake, server that will be used to route requests correctly via the router.

  • collector

    This container is the other half of the brain of the OpenAPI Collector, and polls the Kubernetes API looking for Services that expose OpenAPI Specs. These found Services are then used to update the ui and router configuration.

Usage

Deploy the collector into your cluster:

$ kubectl apply -f deploy/

To see the collector in action, deploy an app that exposes an OpenAPI spec, and annotate the service that points to the app.

$ # deploy app
$ kubectl annotate service app openapi/collect=true
$ kubectl annotate service app openapi/port=80  # port name or number that the spec is accessible at
$ kubectl annotate service app openapi/path=/  # base path of specification

You should be able to then connect to the collector Pod and see the specification in the UI. NOTE: This may take some time to appear, dependent on the poll interval of the collector, and also the Kubelet sync period.

Configuration

The OpenAPI Spec Collector is configured via command line args and Kubernetes annotations.

Kubernetes Annotations:

  • openapi/collect

    Annotate Service resource with value ”true” to mark the Service as one exposing an OpenAPI spec, and one that should be collected.

  • openapi/port

    Annotate Service resource with the port number or name that the OpenAPI spec will be exposed at.

  • openapi/path

    Annotate Service resource with the base path of the OpenAPI spec, i.e. use the value ”/“ if the spec is available at /openapi.json.

Command line args:

  • --debug

    Print more information.

  • --interval

    Loop interval (default 30s).

Contributing

The best way to contribute is to provide feedback. I’d love to hear what you like and what could be better. PRs and Issues more than welcome!

Local Development

You can run the collector against your current kubeconfig context like this:

$ pip install poetry
$ poetry install
$ poetry run python -m openapi_collector

To run tests:

$ make test

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

openapi-collector's People

Contributors

dependabot-preview[bot] avatar dlmiddlecote avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

openapi-collector's Issues

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Creating virtualenv openapi-collector-Eakx5F0G-py3.9 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

  PackageNotFound

  Package pytest-kind (20.10.0) not found.

  at /usr/local/.pyenv/versions/3.9.0/lib/python3.9/site-packages/poetry/repositories/pool.py:144 in package
      140│                     self._packages.append(package)
      141│ 
      142│                     return package
      143│ 
    → 144│         raise PackageNotFound("Package {} ({}) not found.".format(name, version))
      145│ 
      146│     def find_packages(
      147│         self, dependency,
      148│     ):

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Add e2e test(s)

This is required to be able to test the full interaction between the 4 containers in the pod.

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Creating virtualenv openapi-collector-TJcLt1ft-py3.8 in /home/dependabot/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies...

[PackageNotFound]
Package pytest-kind (20.1.0) not found.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

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.