Documentation ¶
Overview ¶
The config package provides config inheritance for Felix.
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:
config.UpdateFrom(envConfig, config.EnvironmentVariable) config.UpdateFrom(fileConfig, config.ConfigFile)
The UpdateFrom() method returns an error, but, as a convenience, it also stores the error in config.Err.
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
- Variables
- func LoadConfigFile(filename string) (map[string]string, error)
- func LoadConfigFileData(data []byte) (map[string]string, error)
- func LoadConfigFromEnvironment(environ []string) map[string]string
- type BoolParam
- type Config
- func (config *Config) DatastoreConfig() api.ClientConfig
- func (config *Config) EndpointReportingDelay() time.Duration
- func (config *Config) RawValues() map[string]string
- func (config *Config) UpdateFrom(rawData map[string]string, source Source) (changed bool, err error)
- func (config *Config) Validate() (err error)
- type EndpointListParam
- type FileParam
- type FloatParam
- type Int32Param
- type IntParam
- type Ipv4Param
- type MarkBitmaskParam
- type Metadata
- type OneofListParam
- type PortListParam
- type RegexpParam
- type Source
Constants ¶
const ( Default = iota DatastoreGlobal DatastorePerHost ConfigFile EnvironmentVariable )
const (
MinIptablesMarkBits = 2
)
Variables ¶
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(`^.*$`) )
var SourcesInDescendingOrder = []Source{EnvironmentVariable, ConfigFile, DatastorePerHost, DatastoreGlobal}
Functions ¶
func LoadConfigFromEnvironment ¶
LoadConfigFromEnvironment extracts raw config parameters (identified by case-insensitive prefix "felix_") from the given OS environment variables. An environment entry of "FELIX_FOO=bar" is translated to "foo": "bar".
Types ¶
type Config ¶
type Config struct { DataplaneDriver string `config:"file(must-exist,executable);calico-iptables-plugin;non-zero,die-on-fail,skip-default-validation"` DatastoreType string `config:"oneof(kubernetes,etcdv2);etcdv2;non-zero,die-on-fail"` FelixHostname string `config:"hostname;;local,non-zero"` 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"` Ipv6Support bool `config:"bool;true"` IgnoreLooseRPF bool `config:"bool;false"` StartupCleanupDelay int `config:"int;30"` PeriodicResyncInterval int `config:"int;3600"` HostInterfacePollInterval int `config:"int;10"` IptablesRefreshInterval int `config:"int;60"` MetadataAddr string `config:"hostname;127.0.0.1;die-on-fail"` MetadataPort int `config:"int(0,65535);8775;die-on-fail"` InterfacePrefix string `config:"iface-list;cali;non-zero,die-on-fail"` DefaultEndpointToHostAction string `config:"oneof(DROP,RETURN,ACCEPT);DROP;non-zero,die-on-fail"` DropActionOverride string `config:"oneof(DROP,ACCEPT,LOG-and-DROP,LOG-and-ACCEPT);DROP;non-zero,die-on-fail"` LogFilePath string `config:"file;/var/log/calico/felix.log;die-on-fail"` EtcdDriverLogFilePath string `config:"file;/var/log/calico/felix-etcd.log"` 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"` IpInIpEnabled bool `config:"bool;false"` IpInIpMtu int `config:"int;1440;non-zero"` IpInIpTunnelAddr net.IP `config:"ipv4;"` ReportingIntervalSecs int `config:"int;30"` ReportingTTLSecs int `config:"int;90"` EndpointReportingEnabled bool `config:"bool;false"` EndpointReportingDelaySecs float64 `config:"float;1.0"` MaxIpsetSize int `config:"int;1048576;non-zero"` IptablesMarkMask uint32 `config:"mark-bitmask;0xff000000;non-zero,die-on-fail"` PrometheusMetricsEnabled bool `config:"bool;false"` PrometheusMetricsPort int `config:"int(0,65535);9091"` DataplaneDriverPrometheusMetricsPort int `config:"int(0,65535);9092"` FailsafeInboundHostPorts []int `config:"port-list;22;die-on-fail"` FailsafeOutboundHostPorts []int `config:"port-list;2379,2380,4001,7001;die-on-fail"` UsageReportingEnabled bool `config:"bool;true"` ClusterGUID string `config:"string;baddecaf"` ClusterType string `config:"string;"` Err error // 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 (*Config) DatastoreConfig ¶
func (config *Config) DatastoreConfig() api.ClientConfig
func (*Config) EndpointReportingDelay ¶
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).
type EndpointListParam ¶
type EndpointListParam struct {
Metadata
}
func (*EndpointListParam) Parse ¶
func (p *EndpointListParam) Parse(raw string) (result interface{}, err 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 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 ¶
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 RegexpParam ¶
func (*RegexpParam) Parse ¶
func (p *RegexpParam) Parse(raw string) (result interface{}, err error)