config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 30 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// AllNamespaceIndicator represents a keyword for allowing all Kubernetes Namespaces.
	AllNamespaceIndicator = ".*"
)

Variables

View Source
var ErrUnsupportedPlatform = errors.New("unsupported platform to persist data")

ErrUnsupportedPlatform is an error returned when a platform is not supported.

Functions

func FromEnvOrFlag added in v0.13.0

func FromEnvOrFlag() []string

FromEnvOrFlag resolves and returns paths for config files. It reads them the 'BOTKUBE_CONFIG_PATHS' env variable. If not found, then it uses '--config' flag.

func LoadWithDefaults added in v0.13.0

func LoadWithDefaults(getCfgPaths PathsGetter) (*Config, LoadWithDefaultsDetails, error)

LoadWithDefaults loads new configuration from files and environment variables.

func RegisterFlags added in v0.13.0

func RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers config related flags.

func WaitForWatcherSync added in v0.14.0

func WaitForWatcherSync(ctx context.Context, log logrus.FieldLogger, cfg CfgWatcher) error

WaitForWatcherSync delays startup until ConfigWatcher synchronizes at least one configuration file

Types

type AWSSigning added in v0.13.0

type AWSSigning struct {
	Enabled   bool   `yaml:"enabled"`
	AWSRegion string `yaml:"awsRegion"`
	RoleArn   string `yaml:"roleArn"`
}

AWSSigning contains AWS configurations

type Analytics added in v0.13.0

type Analytics struct {
	Disable bool `yaml:"disable"`
}

Analytics contains configuration parameters for analytics collection.

type BotBindings added in v0.13.0

type BotBindings struct {
	Sources   []string `yaml:"sources"`
	Executors []string `yaml:"executors"`
}

BotBindings contains configuration for possible Bot bindings.

type BotRuntimeState added in v0.14.0

type BotRuntimeState struct {
	Channels map[string]ChannelRuntimeState `yaml:"channels,omitempty"`

	// Teams integration only, ignored for other communication platforms.
	MSTeamsOnlyRuntimeState *ChannelRuntimeState `yaml:",inline,omitempty"`
}

BotRuntimeState represents the runtime state for a bot.

type BotStartupState added in v0.14.0

type BotStartupState struct {
	Channels map[string]ChannelStartupState `yaml:"channels"`
}

BotStartupState represents the startup state for a bot.

type CfgWatcher added in v0.14.0

type CfgWatcher struct {
	Enabled            bool          `yaml:"enabled"`
	InitialSyncTimeout time.Duration `yaml:"initialSyncTimeout"`
	TmpDir             string        `yaml:"tmpDir"`
}

CfgWatcher describes configuration for watching the configuration.

type ChannelBindingsByID added in v0.13.0

type ChannelBindingsByID struct {
	ID           string              `yaml:"id"`
	Notification ChannelNotification `yaml:"notification"` // TODO: rename to `notifications` later
	Bindings     BotBindings         `yaml:"bindings"`
}

ChannelBindingsByID contains configuration bindings per channel.

func (ChannelBindingsByID) Identifier added in v0.13.0

func (c ChannelBindingsByID) Identifier() string

Identifier returns ChannelBindingsByID identifier.

type ChannelBindingsByName added in v0.13.0

type ChannelBindingsByName struct {
	Name         string              `yaml:"name"`
	Notification ChannelNotification `yaml:"notification"` // TODO: rename to `notifications` later
	Bindings     BotBindings         `yaml:"bindings"`
}

ChannelBindingsByName contains configuration bindings per channel.

func (ChannelBindingsByName) Identifier added in v0.13.0

func (c ChannelBindingsByName) Identifier() string

Identifier returns ChannelBindingsByID identifier.

type ChannelNotification added in v0.14.0

type ChannelNotification struct {
	Disabled bool `yaml:"disabled"`
}

ChannelNotification contains notification configuration for a given platform.

type ChannelRuntimeBindings added in v0.14.0

type ChannelRuntimeBindings struct {
	Sources []string `yaml:"sources"`
}

ChannelRuntimeBindings represents the bindings for a channel.

type ChannelRuntimeState added in v0.14.0

type ChannelRuntimeState struct {
	Bindings ChannelRuntimeBindings `yaml:"bindings"`
}

ChannelRuntimeState represents the runtime state for a channel.

type ChannelStartupState added in v0.14.0

type ChannelStartupState struct {
	Notification NotificationStartupState `yaml:"notification"`
}

ChannelStartupState represents the startup state for a channel.

type CommPlatformIntegration added in v0.13.0

type CommPlatformIntegration string

CommPlatformIntegration defines integrations with communication platforms.

const (
	// SlackCommPlatformIntegration defines Slack integration.
	SlackCommPlatformIntegration CommPlatformIntegration = "slack"

	// SocketSlackCommPlatformIntegration defines Slack integration.
	SocketSlackCommPlatformIntegration CommPlatformIntegration = "socketSlack"

	// MattermostCommPlatformIntegration defines Mattermost integration.
	MattermostCommPlatformIntegration CommPlatformIntegration = "mattermost"

	// TeamsCommPlatformIntegration defines Teams integration.
	TeamsCommPlatformIntegration CommPlatformIntegration = "teams"

	// DiscordCommPlatformIntegration defines Discord integration.
	DiscordCommPlatformIntegration CommPlatformIntegration = "discord"

	//ElasticsearchCommPlatformIntegration defines Elasticsearch integration.
	ElasticsearchCommPlatformIntegration CommPlatformIntegration = "elasticsearch"

	// WebhookCommPlatformIntegration defines an outgoing webhook integration.
	WebhookCommPlatformIntegration CommPlatformIntegration = "webhook"
)

type Commands added in v0.13.0

type Commands struct {
	Verbs     []string `yaml:"verbs"`
	Resources []string `yaml:"resources"`
}

Commands allowed in bot

type Communications

type Communications struct {
	Slack         Slack         `yaml:"slack"`
	SocketSlack   SocketSlack   `yaml:"socketSlack"`
	Mattermost    Mattermost    `yaml:"mattermost"`
	Discord       Discord       `yaml:"discord"`
	Teams         Teams         `yaml:"teams"`
	Webhook       Webhook       `yaml:"webhook"`
	Elasticsearch Elasticsearch `yaml:"elasticsearch"`
}

Communications contains communication platforms that are supported.

type CommunicationsRuntimeState added in v0.14.0

type CommunicationsRuntimeState map[CommPlatformIntegration]BotRuntimeState

CommunicationsRuntimeState represents the runtime state for communication groups.

type CommunicationsStartupState added in v0.14.0

type CommunicationsStartupState map[CommPlatformIntegration]BotStartupState

CommunicationsStartupState represents the startup state for communication groups.

type Config

type Config struct {
	Sources        map[string]Sources        `yaml:"sources" validate:"dive"`
	Executors      map[string]Executors      `yaml:"executors" validate:"dive"`
	Communications map[string]Communications `yaml:"communications"  validate:"required,min=1,dive"`
	Filters        Filters                   `yaml:"filters"`

	Analytics     Analytics  `yaml:"analytics"`
	Settings      Settings   `yaml:"settings"`
	ConfigWatcher CfgWatcher `yaml:"configWatcher"`
}

Config structure of configuration yaml file

type Discord added in v0.13.0

type Discord struct {
	Enabled      bool                                 `yaml:"enabled"`
	Token        string                               `yaml:"token"`
	BotID        string                               `yaml:"botID"`
	Channels     IdentifiableMap[ChannelBindingsByID] `yaml:"channels"  validate:"required_if=Enabled true,omitempty,min=1"`
	Notification Notification                         `yaml:"notification,omitempty"`
}

Discord configuration for authentication and send notifications

type ELSIndex added in v0.13.0

type ELSIndex struct {
	Name     string `yaml:"name"`
	Type     string `yaml:"type"`
	Shards   int    `yaml:"shards"`
	Replicas int    `yaml:"replicas"`

	Bindings SinkBindings `yaml:"bindings"`
}

ELSIndex settings for ELS

type Elasticsearch added in v0.13.0

type Elasticsearch struct {
	Enabled       bool                `yaml:"enabled"`
	Username      string              `yaml:"username"`
	Password      string              `yaml:"password"`
	Server        string              `yaml:"server"`
	SkipTLSVerify bool                `yaml:"skipTLSVerify"`
	AWSSigning    AWSSigning          `yaml:"awsSigning"`
	Indices       map[string]ELSIndex `yaml:"indices"  validate:"required_if=Enabled true,omitempty,min=1"`
}

Elasticsearch config auth settings

type EventType added in v0.8.0

type EventType string

EventType to watch

const (
	// CreateEvent when resource is created
	CreateEvent EventType = "create"
	// UpdateEvent when resource is updated
	UpdateEvent EventType = "update"
	// DeleteEvent when resource deleted
	DeleteEvent EventType = "delete"
	// ErrorEvent on errors in resources
	ErrorEvent EventType = "error"
	// WarningEvent for warning events
	WarningEvent EventType = "warning"
	// NormalEvent for Normal events
	NormalEvent EventType = "normal"
	// InfoEvent for insignificant Info events
	InfoEvent EventType = "info"
	// AllEvent to watch all events
	AllEvent EventType = "all"
)

func (EventType) String added in v0.8.0

func (eventType EventType) String() string

type Executors added in v0.13.0

type Executors struct {
	Kubectl Kubectl `yaml:"kubectl"`
}

Executors contains executors configuration parameters.

type Filters added in v0.14.0

type Filters struct {
	Kubernetes KubernetesFilters `yaml:"kubernetes"`
}

Filters contains configuration for built-in filters.

type Identifiable added in v0.13.0

type Identifiable interface {
	Identifier() string
}

Identifiable exports an Identifier method.

type IdentifiableMap added in v0.13.0

type IdentifiableMap[T Identifiable] map[string]T

IdentifiableMap provides an option to construct an indexable map for identifiable items.

func (IdentifiableMap[T]) GetByIdentifier added in v0.13.0

func (t IdentifiableMap[T]) GetByIdentifier(val string) (T, bool)

GetByIdentifier gets an item from a map by identifier.

type IngressRecommendations added in v0.13.0

type IngressRecommendations struct {
	// BackendServiceValid notifies about Ingress resources with invalid backend service reference.
	BackendServiceValid *bool `yaml:"backendServiceValid,omitempty"`

	// TLSSecretValid notifies about Ingress resources with invalid TLS secret reference.
	TLSSecretValid *bool `yaml:"tlsSecretValid,omitempty"`
}

IngressRecommendations contains configuration for ingress recommendations.

type IntegrationType added in v0.13.0

type IntegrationType string

IntegrationType describes the type of integration with a communication platform.

const (
	// BotIntegrationType describes two-way integration.
	BotIntegrationType IntegrationType = "bot"

	// SinkIntegrationType describes one-way integration.
	SinkIntegrationType IntegrationType = "sink"
)

type K8sResourceRef added in v0.14.0

type K8sResourceRef struct {
	Name      string `yaml:"name,omitempty"`
	Namespace string `yaml:"namespace,omitempty"`
}

K8sResourceRef holds the configuration for a Kubernetes resource.

type Kubectl added in v0.13.0

type Kubectl struct {
	Namespaces       Namespaces `yaml:"namespaces,omitempty"`
	Enabled          bool       `yaml:"enabled"`
	Commands         Commands   `yaml:"commands,omitempty"`
	DefaultNamespace string     `yaml:"defaultNamespace,omitempty"`
	RestrictAccess   *bool      `yaml:"restrictAccess,omitempty"`
}

Kubectl configuration for executing commands inside cluster

type KubernetesFilters added in v0.14.0

type KubernetesFilters struct {
	// ObjectAnnotationChecker enables support for `botkube.io/disable` and `botkube.io/channel` resource annotations.
	ObjectAnnotationChecker bool `yaml:"objectAnnotationChecker"`

	// NodeEventsChecker filters out Node-related events that are not important.
	NodeEventsChecker bool `yaml:"nodeEventsChecker"`
}

KubernetesFilters contains configuration for Kubernetes-related filters.

func (*KubernetesFilters) SetEnabled added in v0.14.0

func (f *KubernetesFilters) SetEnabled(name string, enabled bool) error

SetEnabled enables or disables a given filter.

type KubernetesResourceEvents added in v0.13.0

type KubernetesResourceEvents []EventType

KubernetesResourceEvents contains events to watch for a resource.

func (*KubernetesResourceEvents) Contains added in v0.13.0

func (e *KubernetesResourceEvents) Contains(eventType EventType) bool

Contains checks if event is contained in the events slice. If the slice contains AllEvent, then the result is true.

type KubernetesSource added in v0.13.0

type KubernetesSource struct {
	Recommendations Recommendations          `yaml:"recommendations"`
	Events          KubernetesResourceEvents `yaml:"events"`
	Resources       []Resource               `yaml:"resources" validate:"dive"`
	Namespaces      Namespaces               `yaml:"namespaces"`
}

KubernetesSource contains configuration for Kubernetes sources.

func (*KubernetesSource) IsAllowed added in v0.14.0

func (r *KubernetesSource) IsAllowed(resourceName, namespace string, eventType EventType) bool

IsAllowed checks if a given resource event is allowed according to the configuration.

type Level added in v0.13.0

type Level string

Level type to store event levels

const (
	// Info level
	Info Level = "info"
	// Warn level
	Warn Level = "warn"
	// Debug level
	Debug Level = "debug"
	// Error level
	Error Level = "error"
	// Critical level
	Critical Level = "critical"
)

type LifecycleServer added in v0.14.0

type LifecycleServer struct {
	Enabled    bool           `yaml:"enabled"`
	Port       int            `yaml:"port"` // String for consistency
	Deployment K8sResourceRef `yaml:"deployment"`
}

LifecycleServer contains configuration for the server with app lifecycle methods.

type LoadWithDefaultsDetails added in v0.13.0

type LoadWithDefaultsDetails struct {
	ValidateWarnings error
}

LoadWithDefaultsDetails holds the LoadWithDefaults function details.

type Mattermost added in v0.7.0

type Mattermost struct {
	Enabled      bool                                   `yaml:"enabled"`
	BotName      string                                 `yaml:"botName"`
	URL          string                                 `yaml:"url"`
	Token        string                                 `yaml:"token"`
	Team         string                                 `yaml:"team"`
	Channels     IdentifiableMap[ChannelBindingsByName] `yaml:"channels"  validate:"required_if=Enabled true,omitempty,min=1"`
	Notification Notification                           `yaml:"notification,omitempty"`
}

Mattermost configuration to authentication and send notifications

type Namespaces added in v0.13.0

type Namespaces struct {
	// Include contains a list of allowed Namespaces.
	// It can also contain a regex expressions:
	//  - ".*" - to specify all Namespaces.
	Include []string `yaml:"include"`

	// Exclude contains a list of Namespaces to be ignored even if allowed by Include.
	// It can also contain a regex expressions:
	//  - "test-.*" - to specif all Namespaces with `test-` prefix.
	Exclude []string `yaml:"exclude,omitempty"`
}

Namespaces provides an option to include and exclude given Namespaces.

func (*Namespaces) IsAllowed added in v0.13.0

func (n *Namespaces) IsAllowed(givenNs string) bool

IsAllowed checks if a given Namespace is allowed based on the config.

func (*Namespaces) IsConfigured added in v0.13.0

func (n *Namespaces) IsConfigured() bool

IsConfigured checks whether the Namespace has any Include/Exclude configuration.

type Notification added in v0.13.0

type Notification struct {
	Type NotificationType
}

Notification holds notification configuration.

type NotificationStartupState added in v0.14.0

type NotificationStartupState struct {
	Disabled bool `yaml:"disabled"`
}

NotificationStartupState represents the startup state for a notification.

type NotificationType added in v0.13.0

type NotificationType string

NotificationType to change notification type

const (
	// ShortNotification is the default NotificationType
	ShortNotification NotificationType = "short"
	// LongNotification for short events notification
	LongNotification NotificationType = "long"
)

type PartialPersistentConfig added in v0.14.0

type PartialPersistentConfig struct {
	FileName  string         `yaml:"fileName"`
	ConfigMap K8sResourceRef `yaml:"configMap"`
}

PartialPersistentConfig contains configuration for persistent storage of a given type.

type PathsGetter added in v0.13.0

type PathsGetter func() []string

PathsGetter returns the list of absolute paths to the config files.

type PersistenceManager added in v0.14.0

type PersistenceManager struct {
	// contains filtered or unexported fields
}

PersistenceManager manages persistence of the configuration.

func NewManager added in v0.14.0

NewManager creates a new PersistenceManager instance.

func (*PersistenceManager) PersistFilterEnabled added in v0.14.0

func (m *PersistenceManager) PersistFilterEnabled(ctx context.Context, name string, enabled bool) error

PersistFilterEnabled persists status for a given filter. While this method updates the Botkube ConfigMap, it doesn't reload Botkube itself.

func (*PersistenceManager) PersistNotificationsEnabled added in v0.14.0

func (m *PersistenceManager) PersistNotificationsEnabled(ctx context.Context, commGroupName string, platform CommPlatformIntegration, channelAlias string, enabled bool) error

PersistNotificationsEnabled persists notifications state for a given channel. While this method updates the Botkube ConfigMap, it doesn't reload Botkube itself.

func (*PersistenceManager) PersistSourceBindings added in v0.14.0

func (m *PersistenceManager) PersistSourceBindings(ctx context.Context, commGroupName string, platform CommPlatformIntegration, channelAlias string, sourceBindings []string) error

PersistSourceBindings persists source bindings configuration for a given channel in a given platform.

type PersistentConfig added in v0.14.0

type PersistentConfig struct {
	Startup PartialPersistentConfig `yaml:"startup"`
	Runtime PartialPersistentConfig `yaml:"runtime"`
}

PersistentConfig contains configuration for persistent storage.

type PodRecommendations added in v0.13.0

type PodRecommendations struct {
	// NoLatestImageTag notifies about Pod containers that use `latest` tag for images.
	NoLatestImageTag *bool `yaml:"noLatestImageTag,omitempty"`

	// LabelsSet notifies about Pod resources created without labels.
	LabelsSet *bool `yaml:"labelsSet,omitempty"`
}

PodRecommendations contains configuration for pods recommendations.

type Recommendations added in v0.13.0

type Recommendations struct {
	Ingress IngressRecommendations `yaml:"ingress"`
	Pod     PodRecommendations     `yaml:"pod"`
}

Recommendations contains configuration for various recommendation insights.

type Resource

type Resource struct {
	Name          string                   `yaml:"name"`
	Namespaces    Namespaces               `yaml:"namespaces"`
	Events        KubernetesResourceEvents `yaml:"events"`
	UpdateSetting UpdateSetting            `yaml:"updateSetting"`
}

Resource contains resources to watch

type RuntimeState added in v0.14.0

type RuntimeState struct {
	Communications map[string]CommunicationsRuntimeState `yaml:"communications,omitempty"`
}

RuntimeState represents the runtime state.

func (RuntimeState) MarshalToMap added in v0.14.0

func (s RuntimeState) MarshalToMap(cfg PartialPersistentConfig) (map[string]string, error)

MarshalToMap marshals the runtime state to a string map.

type Settings added in v0.2.0

type Settings struct {
	ClusterName      string           `yaml:"clusterName"`
	UpgradeNotifier  bool             `yaml:"upgradeNotifier"`
	SystemConfigMap  K8sResourceRef   `yaml:"systemConfigMap"`
	PersistentConfig PersistentConfig `yaml:"persistentConfig"`
	MetricsPort      string           `yaml:"metricsPort"`
	LifecycleServer  LifecycleServer  `yaml:"lifecycleServer"`
	Log              struct {
		Level         string `yaml:"level"`
		DisableColors bool   `yaml:"disableColors"`
	} `yaml:"log"`
	InformersResyncPeriod time.Duration `yaml:"informersResyncPeriod"`
	Kubeconfig            string        `yaml:"kubeconfig"`
}

Settings contains Botkube's related configuration.

type SinkBindings added in v0.13.0

type SinkBindings struct {
	Sources []string `yaml:"sources"`
}

SinkBindings contains configuration for possible Sink bindings.

type Slack

type Slack struct {
	Enabled      bool                                   `yaml:"enabled"`
	Channels     IdentifiableMap[ChannelBindingsByName] `yaml:"channels"  validate:"required_if=Enabled true,omitempty,min=1"`
	Notification Notification                           `yaml:"notification,omitempty"`
	Token        string                                 `yaml:"token,omitempty"`
}

Slack configuration to authentication and send notifications

type SocketSlack added in v0.14.0

type SocketSlack struct {
	Enabled      bool                                   `yaml:"enabled"`
	Channels     IdentifiableMap[ChannelBindingsByName] `yaml:"channels"  validate:"required_if=Enabled true,omitempty,min=1"`
	Notification Notification                           `yaml:"notification,omitempty"`
	BotToken     string                                 `yaml:"botToken,omitempty"`
	AppToken     string                                 `yaml:"appToken,omitempty"`
}

SocketSlack configuration to authentication and send notifications

type Sources added in v0.13.0

type Sources struct {
	DisplayName string           `yaml:"displayName"`
	Kubernetes  KubernetesSource `yaml:"kubernetes"`
}

Sources contains configuration for Botkube app sources.

type StartupState added in v0.14.0

type StartupState struct {
	Communications map[string]CommunicationsStartupState `yaml:"communications,omitempty"`
	Filters        Filters                               `yaml:"filters,omitempty"`
}

StartupState represents the startup state.

func (StartupState) MarshalToMap added in v0.14.0

func (s StartupState) MarshalToMap(cfg PartialPersistentConfig) (map[string]string, error)

MarshalToMap marshals the startup state to a string map.

type Teams added in v0.13.0

type Teams struct {
	Enabled     bool   `yaml:"enabled"`
	BotName     string `yaml:"botName,omitempty"`
	AppID       string `yaml:"appID,omitempty"`
	AppPassword string `yaml:"appPassword,omitempty"`
	Port        string `yaml:"port"`
	MessagePath string `yaml:"messagePath,omitempty"`
	// TODO: Be consistent with other communicators when MS Teams support multiple channels
	//Channels     IdentifiableMap[ChannelBindingsByName] `yaml:"channels"`
	Bindings     BotBindings  `yaml:"bindings"`
	Notification Notification `yaml:"notification,omitempty"`
}

Teams creds for authentication with MS Teams

type UpdateSetting added in v0.13.0

type UpdateSetting struct {
	Fields      []string `yaml:"fields"`
	IncludeDiff bool     `yaml:"includeDiff"`
}

UpdateSetting struct defines updateEvent fields specification

type ValidateResult added in v0.13.0

type ValidateResult struct {
	Criticals *multierror.Error
	Warnings  *multierror.Error
}

ValidateResult holds the validation results.

func ValidateStruct added in v0.13.0

func ValidateStruct(in any) (ValidateResult, error)

ValidateStruct validates a given struct based on the `validate` field tag.

type Webhook added in v0.13.0

type Webhook struct {
	Enabled bool   `yaml:"enabled"`
	URL     string `yaml:"url"`
	// TODO: not used yet.
	Bindings SinkBindings
}

Webhook configuration to send notifications

Jump to

Keyboard shortcuts

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