watcher

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWatchChannelClosed = errors.New("watcher channel has closed")

ErrWatchChannelClosed should restart watcher

Functions

This section is empty.

Types

type Config

type Config struct {
	// ClusterScoped means control Chaos Object in cluster level(all namespace);
	ClusterScoped bool `envconfig:"CLUSTER_SCOPED" default:"true"`
	// TemplateNamespace is the namespace which holds the template configmap.
	// If controller-manager is running with in-cluster mode. If is set to empty string, it will be overwrite to namespace which the pod belongs.
	TemplateNamespace string `envconfig:"TEMPLATE_NAMESPACE" default:""`
	// TargetNamespace means configmaps in this namespace will be controlled by this controller.
	// It SHOULD be the same with TargetNamespace in config.ChaosControllerConfig while clusterScoped is false.
	TargetNamespace string `envconfig:"TARGET_NAMESPACE" default:""`
	// TemplateLabels is label pairs used to discover common templates in Kubernetes. These should be key1:value[,key2:val2,...]
	TemplateLabels map[string]string `envconfig:"TEMPLATE_LABELS"`
	// ConfigLabels is label pairs used to discover ConfigMaps in Kubernetes. These should be key1:value[,key2:val2,...]
	ConfigLabels map[string]string `envconfig:"CONFIGMAP_LABELS"`
}

Config is a configuration struct for the Watcher type

func NewConfig

func NewConfig() *Config

NewConfig returns a new initialized Config

func (*Config) Verify

func (c *Config) Verify() error

Verify will verify the parameter configuration is correct

type Event

type Event uint8

Event is what happened to the config (add/delete/update)

const (
	// EventAdd is a new ConfigMap
	EventAdd Event = iota
	// EventUpdate is an Updated ConfigMap
	EventUpdate
	// EventDelete is a deleted ConfigMap
	EventDelete
)

type K8sConfigMapWatcher

type K8sConfigMapWatcher struct {
	Config
	// contains filtered or unexported fields
}

K8sConfigMapWatcher is a struct that connects to the API and collects, parses, and emits sidecar configurations

func New

func New(cfg Config, metrics *metrics.ChaosCollector) (*K8sConfigMapWatcher, error)

New creates a new K8sConfigMapWatcher

func (*K8sConfigMapWatcher) GetConfigs

func (c *K8sConfigMapWatcher) GetConfigs() ([]*config.TemplateArgs, error)

GetConfigs returns the list of template args config

func (*K8sConfigMapWatcher) GetInjectionConfigs

func (c *K8sConfigMapWatcher) GetInjectionConfigs() (map[string][]*config.InjectionConfig, error)

GetInjectionConfigs fetches all matching ConfigMaps

func (*K8sConfigMapWatcher) GetTemplates

func (c *K8sConfigMapWatcher) GetTemplates() (map[string]string, error)

GetTemplates returns a map of common templates

func (*K8sConfigMapWatcher) Watch

func (c *K8sConfigMapWatcher) Watch(notifyMe chan<- interface{}, stopCh <-chan struct{}) error

Watch watches for events impacting watched ConfigMaps and emits their events across a channel

type Message

type Message struct {
	Event           Event
	InjectionConfig config.InjectionConfig
}

Message is a message that describes a change and payload to a sidecar configuration

Jump to

Keyboard shortcuts

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