Version: v1.1.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2019 License: Apache-2.0 Imports: 13 Imported by: 1


Kubernetes ConfigMap Source (configmap)

The configmap source reads config from a kubernetes configmap key/values

Kubernetes ConfigMap Format

The configmap source expects keys under a namespace default to default and a confimap default to micro

// we recommend to setup your variables from multiples files example:
$ kubectl create configmap micro --namespace default --from-file=./testdata

// verify if were set correctly with
$ kubectl get configmap micro --namespace default
    "apiVersion": "v1",
    "data": {
        "config": "host=\nport=1337",
        "mongodb": "host=\nport=27017\nuser=user\npassword=password",
        "redis": "url=redis://"
    "kind": "ConfigMap",
    "metadata": {
        "name": "micro",
        "namespace": "default",

Keys are split on \n and = this is because the way kubernetes saves the data is map[string][string].

// the example above "mongodb": "host=\nport=27017\nuser=user\npassword=password" will be accessible as:
conf.Get("mongodb", "host") //
conf.Get("mongodb", "port") // 27017

New Source

Specify source with data

configmapSource := configmap.NewSource(
	// optionally specify a namespace; default to default
	// optionally specify name for ConfigMap; defaults micro
    // optionally strip the provided path to a kube config file mostly used outside of a cluster, defaults to "" for in cluster support.

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load file source

Running Go Tests


Have a kubernetes cluster running (external or minikube) have a valid kubeconfig file.

// Setup testing configmaps feel free to remove them after testing.
$ cd source/configmap
$ kubectl create configmap micro --from-file=./testdata
$ kubectl create configmap micro --from-file=./testdata --namespace kube-public
$ kubectl create configmap micro-config --from-file=./testdata
$ kubectl create configmap micro-config --from-file=./testdata --namespace kube-public
$ go test -v -cover
// To clean up the testing configmaps
$ kubectl delete configmap micro --all-namespaces
$ kubectl delete configmap micro-config --all-namespaces


  • add more test cases including watchers
  • add support for prefixing either using namespace or a custom string passed as WithPrefix
  • a better way to test without manual setup from the user.
  • add test examples.
  • open to suggestions and feedback please let me know what else should I add.

stay tuned for kubernetes secret support as an source.



Package configmap config is an interface for dynamic configuration.



This section is empty.


View Source
var (
	DefaultName       = "micro"
	DefaultConfigPath = ""
	DefaultNamespace  = "default"


func NewSource

func NewSource(opts ...source.Option) source.Source

func WithConfigPath

func WithConfigPath(s string) source.Option

WithConfigPath option for setting a custom path to kubeconfig

func WithName

func WithName(s string) source.Option

func WithNamespace

func WithNamespace(s string) source.Option


This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL