Skip to content

gustavolaux/k8s-configmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k8s-configmap

npm version install size language npm

A simple yet complete kubernetes' configmap watcher

Installation

npm i -S k8s-configmap

Preconfiguration

I'm considering that you alread read the official guide on mapping configmap as volumes and it's working. If not, here it is https://kubernetes.io/docs/concepts/configuration/configmap/#using-configmaps-as-files-from-a-pod

Usage

I'll use this configmap for this tutorial

The exported class expects the root configmap folder (specified in your deployment configuration as mentioned in the above doc), an array of keys to use and an optional options object

const ConfigMap = require('k8s-configmap');

const CONFIGMAP_ROOT_PATH = '/configmap';

const CONFIGMAP_KEYS = {
    GAME_PROPERTIES: 'game.properties',
    CONFIG: 'config.json',
};

const configmap = new ConfigMap(CONFIGMAP_NAME, [
    ConfigMap.Key(CONFIGMAP_KEYS.GAME_PROPERTIES),
    ConfigMap.Key(CONFIGMAP_KEYS.CONFIG, JSON.parse),
], { debug: true });

(async () => {
    for (const key of Object.keys(CONFIGMAP_KEYS)) {
        const current = await configmap.read(CONFIGMAP_KEYS[key]);

        console.log(`initial value from ${key}: [${typeof current}]`, current);

        configmap.on(CONFIGMAP_KEYS[key], (updated) => {
            console.log(`${key} changed`, updated);
        });
    }
})();

Roadmap

  • add built-in parsers for common files (json, key-values, etc)

Why still on beta

Im not sure if im really happy with this code, but it works

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published