config

package
v3.5.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

The config package provides config inheritance for Typha.

It supports loading config from various sources, parsing and validating the config and merging the config according to the priority of the sources.

Usage

To use it, create a Config object with:

config.New()

Load some raw config using:

envConfig := config.LoadConfigFromEnvironment()
fileConfig, err := config.LoadConfigFile()

Then feed it to the config object:

changed, err := config.UpdateFrom(envConfig, config.EnvironmentVariable)
...
changed, err = config.UpdateFrom(fileConfig, config.ConfigFile)

Config inheritance

Config from higher-priority sources overrides config from lower-priority sources. The priorities, in increasing order of priority, are:

Default              // Default value of a parameter
DatastoreGlobal      // Cluster-wide config parameters from the datastore.
DatastorePerHost     // Per-host overrides from the datastore.
ConfigFile           // The local config file.
EnvironmentVariable  // Environment variables.

Index

Constants

View Source
const (
	Default = iota
	DatastoreGlobal
	DatastorePerHost
	ConfigFile
	EnvironmentVariable
)
View Source
const (
	MinIptablesMarkBits = 2
)

Variables

View Source
var (
	IfaceListRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,15}(,[a-zA-Z0-9_-]{1,15})*$`)
	AuthorityRegexp = regexp.MustCompile(`^[^:/]+:\d+$`)
	HostnameRegexp  = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
	StringRegexp    = regexp.MustCompile(`^.*$`)
)

Functions

func LoadConfigFile

func LoadConfigFile(filename string) (map[string]string, error)

func LoadConfigFileData

func LoadConfigFileData(data []byte) (map[string]string, error)

func LoadConfigFromEnvironment

func LoadConfigFromEnvironment(environ []string) map[string]string

LoadConfigFromEnvironment extracts raw config parameters (identified by case-insensitive prefix "typha_") from the given OS environment variables. An environment entry of "TYPHA_FOO=bar" is translated to "foo": "bar".

Types

type BoolParam

type BoolParam struct {
	Metadata
}

func (*BoolParam) Parse

func (p *BoolParam) Parse(raw string) (interface{}, error)

type Config

type Config struct {
	DatastoreType string `config:"oneof(kubernetes,etcdv3);etcdv3;non-zero,die-on-fail"`

	EtcdAddr      string   `config:"authority;127.0.0.1:2379;local"`
	EtcdScheme    string   `config:"oneof(http,https);http;local"`
	EtcdKeyFile   string   `config:"file(must-exist);;local"`
	EtcdCertFile  string   `config:"file(must-exist);;local"`
	EtcdCaFile    string   `config:"file(must-exist);;local"`
	EtcdEndpoints []string `config:"endpoint-list;;local"`

	LogFilePath string `config:"file;/var/log/calico/typha.log;die-on-fail"`

	LogSeverityFile   string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"`
	LogSeverityScreen string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"`
	LogSeveritySys    string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"`

	HealthEnabled bool   `config:"bool;false"`
	HealthHost    string `config:"string;localhost"`
	HealthPort    int    `config:"int(0,65535);9098"`

	PrometheusMetricsEnabled        bool `config:"bool;false"`
	PrometheusMetricsPort           int  `config:"int(0,65535);9093"`
	PrometheusGoMetricsEnabled      bool `config:"bool;true"`
	PrometheusProcessMetricsEnabled bool `config:"bool;true"`

	SnapshotCacheMaxBatchSize int `config:"int(1,);100"`

	ServerMaxMessageSize              int           `config:"int(1,);100"`
	ServerMaxFallBehindSecs           time.Duration `config:"seconds;90"`
	ServerMinBatchingAgeThresholdSecs time.Duration `config:"seconds;0.01"`
	ServerPingIntervalSecs            time.Duration `config:"seconds;10"`
	ServerPongTimeoutSecs             time.Duration `config:"seconds;60"`
	ServerPort                        int           `config:"port;0"`

	// Server-side TLS config for Typha's communication with Felix.  If any of these are
	// specified, they _all_ must be - except that either ClientCN or ClientURISAN may be left
	// unset - and Typha will then only accept secure (TLS) connections.  Each connecting client
	// (Felix) must present a certificate signed by a CA in CAFile, and with CN matching
	// ClientCN or URI SAN matching ClientURISAN.
	ServerKeyFile  string `config:"file(must-exist);;local"`
	ServerCertFile string `config:"file(must-exist);;local"`
	CAFile         string `config:"file(must-exist);;local"`
	ClientCN       string `config:"string;"`
	ClientURISAN   string `config:"string;"`

	DebugMemoryProfilePath  string `config:"file;;"`
	DebugDisableLogDropping bool   `config:"bool;false"`

	ConnectionRebalancingMode  string        `config:"oneof(none,kubernetes);none"`
	ConnectionDropIntervalSecs time.Duration `config:"seconds;1"`
	MaxConnectionsUpperLimit   int           `config:"int(1,);10000"`
	MaxConnectionsLowerLimit   int           `config:"int(1,);100"`
	K8sServicePollIntervalSecs time.Duration `config:"seconds;30"`
	K8sNamespace               string        `config:"string;kube-system"`
	K8sServiceName             string        `config:"string;calico-typha"`
	K8sPortName                string        `config:"string;calico-typha"`
	// contains filtered or unexported fields
}

Config contains the best, parsed config values loaded from the various sources. We use tags to control the parsing and validation.

func New

func New() *Config

func (*Config) DatastoreConfig

func (config *Config) DatastoreConfig() apiconfig.CalicoAPIConfig

func (*Config) RawValues

func (config *Config) RawValues() map[string]string

func (*Config) UpdateFrom

func (config *Config) UpdateFrom(rawData map[string]string, source Source) (changed bool, err error)

Load parses and merges the rawData from one particular source into this config object. If there is a config value already loaded from a higher-priority source, then the new value will be ignored (after validation).

func (*Config) Validate

func (config *Config) Validate() (err error)

Validate() performs cross-field validation.

type EndpointListParam

type EndpointListParam struct {
	Metadata
}

func (*EndpointListParam) Parse

func (p *EndpointListParam) Parse(raw string) (result interface{}, err error)

type FileParam

type FileParam struct {
	Metadata
	MustExist  bool
	Executable bool
}

func (*FileParam) Parse

func (p *FileParam) Parse(raw string) (interface{}, error)

type FloatParam

type FloatParam struct {
	Metadata
}

func (*FloatParam) Parse

func (p *FloatParam) Parse(raw string) (result interface{}, err error)

type Int32Param

type Int32Param struct {
	Metadata
}

func (*Int32Param) Parse

func (p *Int32Param) Parse(raw string) (interface{}, error)

type IntParam

type IntParam struct {
	Metadata
	Min int
	Max int
}

func (*IntParam) Parse

func (p *IntParam) Parse(raw string) (interface{}, error)

type Ipv4Param

type Ipv4Param struct {
	Metadata
}

func (*Ipv4Param) Parse

func (p *Ipv4Param) Parse(raw string) (result interface{}, err error)

type MarkBitmaskParam

type MarkBitmaskParam struct {
	Metadata
}

func (*MarkBitmaskParam) Parse

func (p *MarkBitmaskParam) Parse(raw string) (interface{}, error)

type Metadata

type Metadata struct {
	Name              string
	Default           interface{}
	ZeroValue         interface{}
	NonZero           bool
	DieOnParseFailure bool
	Local             bool
}

func (*Metadata) GetMetadata

func (m *Metadata) GetMetadata() *Metadata

type OneofListParam

type OneofListParam struct {
	Metadata
	// contains filtered or unexported fields
}

func (*OneofListParam) Parse

func (p *OneofListParam) Parse(raw string) (result interface{}, err error)

type PortListParam

type PortListParam struct {
	Metadata
}

func (*PortListParam) Parse

func (p *PortListParam) Parse(raw string) (interface{}, error)

type PortParam

type PortParam struct {
	Metadata
}

func (*PortParam) Parse

func (p *PortParam) Parse(raw string) (interface{}, error)

type ProtoPort

type ProtoPort struct {
	Protocol string
	Port     uint16
}

type RegexpParam

type RegexpParam struct {
	Metadata
	Regexp *regexp.Regexp
	Msg    string
}

func (*RegexpParam) Parse

func (p *RegexpParam) Parse(raw string) (result interface{}, err error)

type SecondsParam

type SecondsParam struct {
	Metadata
}

func (*SecondsParam) Parse

func (p *SecondsParam) Parse(raw string) (result interface{}, err error)

type Source

type Source uint8

Source of a config value. Values from higher-numbered sources override those from lower-numbered sources. Note: some parameters (such as those needed to connect to the datastore) can only be set from a local source.

func (Source) Local

func (source Source) Local() bool

func (Source) String

func (source Source) String() string

Jump to

Keyboard shortcuts

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