Home

Awesome

REST Layer Kubernetes ConfigMap Backend

A backend to REST Layer that stores configuration in a Kubernetes ConfigMap.

Further reading about ConfigMaps:

See examples/main.go for usage example.

Feature overview

Building

If you're using the GB build tool, you can fetch all dependencies using the following commands:

gb vendor fetch github.com/justinas/alice
gb vendor fetch github.com/rs/cors
gb vendor fetch github.com/rs/rest-layer/resource
gb vendor fetch github.com/rs/rest-layer/rest
gb vendor fetch github.com/rs/zerolog
gb vendor fetch github.com/rs/zerolog/hlog
gb vendor fetch github.com/rs/zerolog/log
gb vendor fetch github.com/segence/rest-layer-kubernetes-configmap

Kubernetes namespaces

The library can access any Kubernetes namespace as long as it has permissions (which can be controlled through RBAC, for example).

The client has to be configred with a default Kubernetes namespace, like in the following code example:

kHandler := configmap.NewHandler(*kubernetesClient, "some-default-namespace-name")

However, the library can access ConfigMaps in other namespaces.

Creating or updating a ConfigMap in another namespace

Add the namespace field into the payload, e.g.:

{
	"id": "test-config-map",
	"namespace": "my-namespace",
	"data": {
		...
	}
}

Querying or deleting a ConfigMap in another namespace

Add the ?filter= query parameter to the end of the URL.

E.g.: /api/config-map/test-config-map?filter={namespace:"my-namespace"}

REST end-points:

OperationHTTP methodURLExample payload
Create new ConfigMapPOST/api/config-map{{"id": "test-config-map", "data": {"config_value": "Hello"}}}
Update existing ConfigMapPUT/api/config-map/test-config-map{{"id": "test-config-map", "data": {"config_value": "Hello2"}}}
Delete existing ConfigMapDELETE/api/config-map/test-config-mapNone
Find existing ConfigMapGET/api/config-map/test-config-mapNone

REST call examples are also available in Postman format here. Make sure to override the {{configmap-handler}} variable to the actual host where the application is running, e.g. http://localhost:8080.

Testing

The functionality can be easily tested by running Minikube locally and using the out of cluster Kubernetes client configuration.