Version: v1.17.0 Latest Latest

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0


Kubernetes (K8s) ConfigMap support

This package allows you to use ConfigMap objects in Kubernetes to drive the update of dynamic dflag at runtime of your service.


The Updater is optionally split into two phases:

  • Initialize() - used on server startup which allows both static and dynamic flags to be updated from values stored in a ConfigMap
  • Start() - kicking off a an fsnotify Go-routine which watches for updates of values in the ConfigMap. To avoid races, this allows only to update dynamic flags.

Or you can do all at once Setup()

Code example

// First parse the flags from the command line, as normal.
// Setup watcher and start watching for change (including initial read)
u, err := configmap.Setup(flag.CommandLine, "/etc/dflag", logger)
if err != nil {
  logger.Fatalf("failed setting up: %v", err)

In a nutshell

You define a ConfigMap with values for your flags.

kind: ConfigMap
apiVersion: v1
  creationTimestamp: 2016-09-09T09:14:38Z
  name: example-config
  namespace: default
  example_my_dynamic_string: something
  example_my_dynamic_int: 20
  example_my_dynamic_json: |-
      "policy": "allow",
      "rate": 50

Then you just push it to your Kubernetes cluster:

# kubectl replace -f example.yaml

And all your jobs referencing this ConfigMap via a volume mount will see updates dflag updates to keys in your data. For an end to end example see server_kube.

Sample pod using a volume configmap:

apiVersion: v1
kind: Pod
  name: debug
    - name: shell
      image: ubuntu:latest
      command: [ "/bin/bash" ]
      args: [ "-c", "while true; do date; sleep 60; done" ]
        - name: config-volume
          mountPath: /etc/dflag
    - name: config-volume
        name: example-config




This section is empty.


This section is empty.


This section is empty.


type Updater

type Updater struct {
	// contains filtered or unexported fields

Updater is the encapsulation of the directory watcher. TODO: hide details, just return opaque interface.

func New

func New(flagSet *flag.FlagSet, dirPath string) (*Updater, error)

New creates an Updater for the directory.

func Setup

func Setup(flagSet *flag.FlagSet, dirPath string) (*Updater, error)

Setup is a combination/shortcut for New+Initialize+Start.

func (*Updater) Initialize

func (u *Updater) Initialize() error

Initialize reads the values from the directory for the first time.

func (*Updater) Start

func (u *Updater) Start() error

Start kicks off the go routine that watches the directory for updates of values.

func (*Updater) Stop

func (u *Updater) Stop() error

Stop stops the auto-updating go-routine.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL