Skip to content

The Project Syn Kubernetes Cluster and Tenants Inventory API

License

Notifications You must be signed in to change notification settings

zugao/lieutenant-api

 
 

Repository files navigation

Project Syn: Lieutenant API

Rest API to provide services like inventory, cluster registry, tenant management and GitOps helper.

Please note that this project is in it's early stages and under active development.

OpenAPI Spec

The API is specified in OpenAPI 3 format. It's available in the file openapi.yaml in the root folder of this project.

Run API locally

To run the API on your local workstation, follow these steps:

export KUBECONFIG=~/.kube/myconfig
export NAMESPACE=syn-lieutenant
make run

The kubeconfig must grant access to the cluster.

Check with curl localhost:8080/healthz if the API is responding.

Example queries

Done with HTTPie, but also works with plain curl.

Create Tenant

http localhost:8080/tenants Authorization:"Bearer $(kubectl get secrets test-token-zzzzz -o json | jq ".data.token" -r | base64 --decode)" displayName="Syn Corp"

Query Tenants

http localhost:8080/tenants Authorization:"Bearer $(kubectl get secrets test-token-zzzzz -o json | jq ".data.token" -r | base64 --decode)"
  • test-token-zzzzz is the token of a ServiceAccount with all the needed RBAC rights on the underlying Kubernetes cluster

Development

API Versioning

There is no API versioning exposed. Internally the "API Evolution" approach is used which is described in this excellent blog post: API Versioning Has No "Right Way".

API Mocking

To test the API before writing actual code, API mocking can be used. One cool tool to do that is Prism. Example:

docker run --init --rm -p 4010:4010 -v $(pwd):/tmp stoplight/prism:3 mock -h 0.0.0.0 "/tmp/openapi.yaml"

curl http://localhost:4010/tenants

Code Generation

As the API spec is written with OpenAPI, the OpenAPI Generator is used to generate the Go boilerplate code.

Object Name Generation

Some API endpoints store data in Kubernetes objects. These objects must be named like this:

pwgen -A -B 6 1

Links

Some good links which help with OpenAPI development:

About

The Project Syn Kubernetes Cluster and Tenants Inventory API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 95.2%
  • Makefile 4.0%
  • Dockerfile 0.8%