configmap

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 1 Imported by: 0

README

configmap

A simple watcher for handling updates to your Kubernetes ConfigMap files.

Installing

go get github.com/codykaup/configmap

Usage

The goal is to build a Watcher struct with simple names to easily determine what will happen when the ConfigMap updates or gets an error.

import (
	"fmt"

	"github.com/codykaup/configmap"
)

func main() {
	w := &configmap.Watcher{
		FilePath: "path/to/configmap",
		OnUpdate: func() {
			fmt.Println("configmap updated")
		},
		OnError: func(err error) {
			fmt.Println("error found")
		},
		OnFatal: func(err error) {
			panic("fatal error found")
		},
	}

	go w.Run()
	// or
	w.RunInBackground()
}

Keep in mind, OnFatal means the Watcher failed to get started and, thus, the ConfigMap is not being watched. You'll likely want to handle this error or fatal out as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	// Holds the location in which the config file lives
	FilePath string

	// The function to run when an update on the ConfigMap is applied
	OnUpdate func()

	// The function to run when an error occurs
	OnError func(error)

	// The function to run when a fatal error occurs
	// When fatal errors occur, the Watcher is NOT running. Therefore, any ConfigMap updates
	// will be missed.
	OnFatal func(error)
}

Watcher holds details required to watch for ConfigMap updates

func New

func New(filePath string, onUpdate func(), onError, onFatal func(error)) *Watcher

New generates and returns a new Watcher

func (*Watcher) Run

func (w *Watcher) Run()

Run starts watching for updates to a ConfigMap file

You'll want to call this method in a goroutine or it will block your main thread. RunInBackground is also available for just this purpose.

func (*Watcher) RunInBackground

func (w *Watcher) RunInBackground()

RunInBackground starts the Watcher in a new thread

Jump to

Keyboard shortcuts

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