configuration

package
v1.2.5-0...-764cd5e Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 53 Imported by: 0

README

HAProxy

HAProxy Data Plane API configuration file

documentation can be seen at doc

example can be seen yaml

full examples of configuration also can be seen at yaml

IMPORTANT information regarding migration from 2.x to 3.0 version

Some fields in dataplane configuration file are deprecated starting from version 3.0.

They are now moved to Data Plane API internal storage (dataplane_storage_dir): read here

Those fields are the one that were not really dataplane configuration attributes but dynamic data (cluster, users...). They are moved to a dataplane internal storage. Hence the dataplane configuration file is not any more updated with states and data and only contains configuration.

  • dataplaneapi.user (only cluster mode users, whose name are starting with dpapi-c are migrated)
  • cluster
  • service_discovery
  • status

Those data are moved to dataplane internal storage.

Migration from Dataplane API 2.x to 3.0 behavior

Data (user, cluster, service_discovery, status) that were in Dataplane API configuration file are automatically created in:

  • <dataplane_storage_dir>/service_discovery.json
  • <dataplane_storage_dir>/cluster.json

General behavior regarding the deprecated section

If some of those data are manually updated in Dataplane configuration file (this should not be done, fields are deprecated), or if it's the first start of a 3.0 dataplane API:

  • A warning log is issued (search for logs having "[CFG DEPRECATED]) with [SKIP] or [MIGRATE] and the category:
    • [User] or
    • [Cluster] or
    • [Consul] or
    • [AWS Region] or
    • [Status]

Below an an example for cluster users:

time="2024-07-22T09:12:09+02:00" level=warning msg="[CFG DEPRECATED] [SKIP] [User] [dpapi-c-Abr8s1V]: already migrated. Old location [/home/helene/go/src/gitlab.int.haproxy.com/dataplaneapi-ee/.test/etc/dataplaneapi-cluster.yml] New location [/home/helene/go/src/gitlab.int.haproxy.com/dataplaneapi-ee/.test/storage/dataplane/users.json]. Use only new location"
time="2024-07-22T09:12:09+02:00" level=warning msg="[CFG DEPRECATED] [MIGRATE] [User] [dpapi-c-8Mk2Z5UK]: migrating. Old location [/home/helene/go/src/gitlab.int.haproxy.com/dataplaneapi-ee/.test/etc/dataplaneapi-cluster.yml] New location [/home/helene/go/src/gitlab.int.haproxy.com/dataplaneapi-ee/.test/storage/dataplane/users.json]. Use only new location"
  • After migration, data are removed from the dataplane configuration file.
  • If a data is added again in the dataplane configuration file, and has already been migrated to the internal storage, then the value from the configuration file is ignored. Only the value from the storage is kept.

IMPORTANT NOTE: only cluster mode users, whose name are starting with dpapi- are migrated

Cluster Mode: deprecation

The dataplane api configuration field:

  • mode (values = single or cluster)

is now deprecated and this value is removed from dataplane api configuration file after migration.

The way cluster vs single is now handled is as following:

Mode <dataplane_storage_dir>/cluster.json content
Single cluster attribute is empty
Cluster cluster attribute is not empty

Documentation

Index

Constants

View Source
const (
	ModeCluster = "cluster"
	ModeSingle  = "single"
)
View Source
const (
	StatusActive       = "active"
	StatusUnconfigured = "unconfigured"
)
View Source
const (
	ReloadStratCustom  = "custom"
	ReloadStratS6      = "s6"
	ReloadStratSystemd = "systemd"
)
View Source
const DataplaneAPIType = "community"

Variables

This section is empty.

Functions

func AuthenticateUser

func AuthenticateUser(user string, pass string) (interface{}, error)

func CheckIfStorageDirIsOK

func CheckIfStorageDirIsOK(storageDir string, config *Configuration) error

func DecodeBootstrapKey

func DecodeBootstrapKey(key string) (map[string]string, error)

func HandlePIDFile

func HandlePIDFile(haproxyOptions HAProxyConfiguration)

func InitStorageNoticeFile

func InitStorageNoticeFile(storageDir string) error

func RemoveStorageFolder

func RemoveStorageFolder(storageDir string) error

Types

type APIConfiguration

type APIConfiguration struct {
	APIAddress string `long:"api-address" description:"Advertised API address" group:"advertised" yaml:"address" example:"10.2.3.4" save:"true"`
	APIPort    int64  `long:"api-port" description:"Advertised API port" group:"advertised" yaml:"port" example:"80" save:"true"`
}

type AtomicBool

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

func (*AtomicBool) Load

func (s *AtomicBool) Load() bool

func (AtomicBool) MarshalYAML

func (s AtomicBool) MarshalYAML() (interface{}, error)

func (*AtomicBool) Store

func (s *AtomicBool) Store(str bool)

func (*AtomicBool) String

func (s *AtomicBool) String() string

func (*AtomicBool) UnmarshalYAML

func (s *AtomicBool) UnmarshalYAML(unmarshal func(interface{}) error) error

type AtomicInt

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

func (*AtomicInt) Load

func (s *AtomicInt) Load() int

func (AtomicInt) MarshalYAML

func (s AtomicInt) MarshalYAML() (interface{}, error)

func (*AtomicInt) Store

func (s *AtomicInt) Store(str int)

func (*AtomicInt) String

func (s *AtomicInt) String() string

func (*AtomicInt) UnmarshalYAML

func (s *AtomicInt) UnmarshalYAML(unmarshal func(interface{}) error) error

type AtomicString

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

func (*AtomicString) Load

func (s *AtomicString) Load() string

func (AtomicString) MarshalYAML

func (s AtomicString) MarshalYAML() (interface{}, error)

func (*AtomicString) Store

func (s *AtomicString) Store(str string)

func (*AtomicString) String

func (s *AtomicString) String() string

func (*AtomicString) UnmarshalYAML

func (s *AtomicString) UnmarshalYAML(unmarshal func(interface{}) error) error

type ChanNotify

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

func NewChanNotify

func NewChanNotify() *ChanNotify

func (*ChanNotify) Notify

func (cn *ChanNotify) Notify()

func (*ChanNotify) NotifyWithRetry

func (cn *ChanNotify) NotifyWithRetry()

func (*ChanNotify) Subscribe

func (cn *ChanNotify) Subscribe(name string) chan struct{}

func (*ChanNotify) UnSubscribeAll

func (cn *ChanNotify) UnSubscribeAll()

type ClusterConfiguration

type ClusterConfiguration struct {
	APIRegisterPath    AtomicString               `yaml:"api_register_path,omitempty" group:"cluster" save:"true"`
	APIBasePath        AtomicString               `yaml:"api_base_path,omitempty" group:"cluster" save:"true"`
	ActiveBootstrapKey AtomicString               `yaml:"active_bootstrap_key,omitempty" group:"cluster" save:"true"`
	Token              AtomicString               `yaml:"token,omitempty" group:"cluster" save:"true"`
	ID                 AtomicString               `yaml:"id,omitempty" group:"cluster" save:"true"`
	Port               AtomicInt                  `yaml:"port,omitempty" group:"cluster" save:"true"`
	BootstrapKey       AtomicString               `yaml:"bootstrap_key,omitempty" group:"cluster" save:"true"`
	APINodesPath       AtomicString               `yaml:"api_nodes_path,omitempty" group:"cluster" save:"true"`
	URL                AtomicString               `yaml:"url,omitempty" group:"cluster" save:"true"`
	StorageDir         AtomicString               `yaml:"storage_dir,omitempty" group:"cluster" save:"true"`
	CertificateDir     AtomicString               `yaml:"cert_path,omitempty" group:"cluster" save:"true"`
	CertificateFetched AtomicBool                 `yaml:"cert_fetched,omitempty" group:"cluster" save:"true" example:"false"`
	Name               AtomicString               `yaml:"name,omitempty" group:"cluster" save:"true"`
	Description        AtomicString               `yaml:"description,omitempty" group:"cluster" save:"true"`
	ClusterID          AtomicString               `yaml:"cluster_id,omitempty" group:"cluster" save:"true"`
	ClusterLogTargets  []*models.ClusterLogTarget `yaml:"cluster_log_targets,omitempty" group:"cluster" save:"true"`
}

func (*ClusterConfiguration) Clear

func (c *ClusterConfiguration) Clear()

type ClusterSync

type ClusterSync struct {
	Context     context.Context
	ReloadAgent haproxy.IReloadAgent
	// contains filtered or unexported fields
}

ClusterSync fetches certificates for joining cluster

func (*ClusterSync) Monitor

func (c *ClusterSync) Monitor(cfg *Configuration, cli client_native.HAProxyClient)

type ConfigWatcher

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

func NewConfigWatcher

func NewConfigWatcher(params ConfigWatcherParams) (*ConfigWatcher, error)

func (*ConfigWatcher) Listen

func (w *ConfigWatcher) Listen()

type ConfigWatcherParams

type ConfigWatcherParams struct {
	Ctx      context.Context
	Callback func()
	FilePath string
	Version  string
}

type Configuration

type Configuration struct {
	Cluster ClusterConfiguration `yaml:"-"`
	Notify  NotifyConfiguration  `yaml:"-"`
	Mode    AtomicString         `yaml:"mode" default:"single"`

	Name                   AtomicString `yaml:"name" example:"famous_condor"`
	Cmdline                AtomicString `yaml:"-"`
	Status                 AtomicString `yaml:"status,omitempty"`
	DeprecatedBootstrapKey AtomicString `yaml:"bootstrap_key,omitempty" deprecated:"true"`

	MapSync                 *MapSync             `yaml:"-"`
	Syslog                  log.SyslogOptions    `yaml:"-"`
	Logging                 log.LoggingOptions   `yaml:"-"`
	RuntimeData             RuntimeData          `yaml:"-"`
	ServiceDiscovery        ServiceDiscovery     `yaml:"-"`
	Users                   []User               `yaml:"-"`
	APIOptions              APIConfiguration     `yaml:"-"`
	LogTargets              log.Targets          `yaml:"log_targets,omitempty" group:"log"`
	HAProxy                 HAProxyConfiguration `yaml:"-"`
	FlagLoadDapiStorageData bool                 `yaml:"-"`
	// contains filtered or unexported fields
}

func Get

func Get() *Configuration

Get returns pointer to configuration

func (*Configuration) GetClusterCertDir

func (c *Configuration) GetClusterCertDir() string

func (*Configuration) GetClusterModeStorage

func (c *Configuration) GetClusterModeStorage() storage.ClusterModeStorage

func (*Configuration) GetStorageData

func (c *Configuration) GetStorageData() *StorageDataplaneAPIConfiguration

func (*Configuration) GetUsers

func (c *Configuration) GetUsers() storagetype.Users

func (*Configuration) InitSignalHandler

func (c *Configuration) InitSignalHandler()

func (*Configuration) Load

func (c *Configuration) Load() ([]string, error)

func (*Configuration) LoadDataplaneStorageConfig

func (c *Configuration) LoadDataplaneStorageConfig() ([]string, error)

func (*Configuration) LoadRuntimeVars

func (c *Configuration) LoadRuntimeVars(swaggerJSON json.RawMessage, host string, port int) error

func (*Configuration) Save

func (c *Configuration) Save() error

func (*Configuration) SaveAWS

func (c *Configuration) SaveAWS(aws []*models.AwsRegion) error

func (*Configuration) SaveClusterModeData

func (c *Configuration) SaveClusterModeData() error

func (*Configuration) SaveConsuls

func (c *Configuration) SaveConsuls(consuls []*models.Consul) error

func (*Configuration) SaveSDAWSRegions

func (c *Configuration) SaveSDAWSRegions() error

func (*Configuration) SaveSDConsuls

func (c *Configuration) SaveSDConsuls() error

func (*Configuration) StopSignalHandler

func (c *Configuration) StopSignalHandler()

func (*Configuration) UnSubscribeAll

func (c *Configuration) UnSubscribeAll()

type HAProxyConfiguration

type HAProxyConfiguration struct {
	SpoeDir              string        `long:"spoe-dir" description:"Path to SPOE directory." default:"/etc/haproxy/spoe" group:"resources"`
	ServiceName          string        `long:"service" description:"Name of the HAProxy service" group:"reload"`
	HAProxy              string        `short:"b" long:"haproxy-bin" description:"Path to the haproxy binary file" default:"haproxy" group:"haproxy"`
	UserListFile         string        `` /* 191-byte string literal not displayed */
	ReloadCmd            string        `short:"r" long:"reload-cmd" description:"Reload command" group:"reload"`
	RestartCmd           string        `short:"s" long:"restart-cmd" description:"Restart command" group:"reload"`
	StatusCmd            string        `long:"status-cmd" description:"Status command" group:"reload"`
	NodeIDFile           string        `` /* 154-byte string literal not displayed */
	PIDFile              string        `` /* 136-byte string literal not displayed */
	ReloadStrategy       string        `long:"reload-strategy" description:"Either systemd, s6 or custom" default:"custom" group:"reload"`
	TransactionDir       string        `short:"t" long:"transaction-dir" description:"Path to the transaction directory" default:"/tmp/haproxy" group:"transaction"`
	ValidateCmd          string        `long:"validate-cmd" description:"Executes a custom command to perform the HAProxy configuration check" group:"reload"`
	BackupsDir           string        `long:"backups-dir" description:"Path to directory in which to place backup files" group:"transaction"`
	MapsDir              string        `` /* 137-byte string literal not displayed */
	SpoeTransactionDir   string        `` /* 126-byte string literal not displayed */
	DataplaneConfig      string        `short:"f" description:"Path to the dataplane configuration file" default:"/etc/haproxy/dataplaneapi.yaml" yaml:"-"`
	ConfigFile           string        `` /* 132-byte string literal not displayed */
	Userlist             string        `` /* 147-byte string literal not displayed */
	MasterRuntime        string        `short:"m" long:"master-runtime" description:"Path to the master Runtime API socket" group:"haproxy"`
	SSLCertsDir          string        `long:"ssl-certs-dir" description:"Path to SSL certificates directory" default:"/etc/haproxy/ssl" group:"resources"`
	GeneralStorageDir    string        `long:"general-storage-dir" description:"Path to general storage directory" default:"/etc/haproxy/general" group:"resources"`
	ClusterTLSCertDir    string        `` /* 163-byte string literal not displayed */
	DataplaneStorageDir  string        `` /* 138-byte string literal not displayed */
	PreferredTimeSuffix  string        `` /* 167-byte string literal not displayed */
	UpdateMapFilesPeriod int64         `` /* 135-byte string literal not displayed */
	ReloadDelay          int           `short:"d" long:"reload-delay" description:"Minimum delay between two reloads (in s)" default:"5" group:"reload"`
	MaxOpenTransactions  int64         `long:"max-open-transactions" description:"Limit for active transaction in pending state" default:"20" group:"transaction"`
	BackupsNumber        int           `` /* 184-byte string literal not displayed */
	ReloadRetention      int           `` /* 128-byte string literal not displayed */
	UID                  int           `long:"uid" description:"User id value to set on start" group:"dataplaneapi" example:"1000"`
	GID                  int           `long:"gid" description:"Group id value to set on start" group:"dataplaneapi" example:"1000"`
	UpdateMapFiles       bool          `long:"update-map-files" description:"Flag used for syncing map files with runtime maps values" group:"resources"`
	ShowSystemInfo       bool          `short:"i" long:"show-system-info" description:"Show system info on info endpoint" group:"dataplaneapi"`
	MasterWorkerMode     bool          `long:"master-worker-mode" description:"Flag to enable helpers when running within HAProxy" group:"haproxy"`
	DisableInotify       bool          `long:"disable-inotify" description:"Disables inotify watcher for the configuration file" group:"dataplaneapi"`
	DebugSocketPath      string        `long:"debug-socket-path" description:"Unix socket path for the debugging command socket" group:"dataplaneapi"`
	DelayedStartMax      time.Duration `` /* 136-byte string literal not displayed */
	DelayedStartTick     time.Duration `` /* 138-byte string literal not displayed */
}

type MapSync

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

func NewMapSync

func NewMapSync() *MapSync

func (*MapSync) Stop

func (ms *MapSync) Stop()

Stop stops maps syncing

func (*MapSync) Sync

func (ms *MapSync) Sync(mp *models.Map, client client_native.HAProxyClient) (bool, error)

Sync syncs one map file to runtime entries

func (*MapSync) SyncAll

func (ms *MapSync) SyncAll(client client_native.HAProxyClient)

SyncAll sync maps file entries with runtime maps entries for all configured files. Missing runtime entries are appended to the map file

type Node

type Node struct {
	Facts       map[string]string `json:"facts"`
	Address     string            `json:"address"`
	APIBasePath string            `json:"api_base_path"`
	APIPassword string            `json:"api_password"`
	APIUser     string            `json:"api_user"`
	Certificate string            `json:"certificate,omitempty"`
	Description string            `json:"description,omitempty"`
	ID          string            `json:"id,omitempty"`
	Name        string            `json:"name"`
	Status      string            `json:"status"`
	Type        string            `json:"type"`
	Port        int64             `json:"port,omitempty"`
}

Node is structure required for connection to cluster

type NotifyConfiguration

type NotifyConfiguration struct {
	BootstrapKeyChanged *ChanNotify `yaml:"-"`
	ServerStarted       *ChanNotify `yaml:"-"`
	CertificateRefresh  *ChanNotify `yaml:"-"`
	Reload              *ChanNotify `yaml:"-"`
	Shutdown            *ChanNotify `yaml:"-"`
}

type RuntimeData

type RuntimeData struct {
	Host        string
	APIBasePath string
	Port        int
}

type ServiceDiscovery

type ServiceDiscovery struct {
	Consuls    []*models.Consul    `yaml:"consuls" group:"service_discovery" save:"true"`
	AWSRegions []*models.AwsRegion `yaml:"aws-regions" group:"service_discovery" save:"true"`
	// contains filtered or unexported fields
}

type Storage

type Storage interface {
	Load(filename string) error
	Get() *StorageDataplaneAPIConfiguration
	Set(cfg *StorageDataplaneAPIConfiguration)
	SaveAs(filename string) error
	Save() error
}

type StorageDataplaneAPIConfiguration

type StorageDataplaneAPIConfiguration struct {
	Version                    *int                        `yaml:"config_version,omitempty"`
	Name                       *string                     `yaml:"name,omitempty"`
	DeprecatedMode             *string                     `yaml:"mode,omitempty"`
	DeprecatedBootstrapKey     *string                     `yaml:"bootstrap_key,omitempty"`
	DeprecatedStatus           *string                     `yaml:"status,omitempty"`
	Dataplaneapi               *configTypeDataplaneapi     `yaml:"dataplaneapi,omitempty"`
	Haproxy                    *configTypeHaproxy          `yaml:"haproxy,omitempty"`
	DeprecatedCluster          *storagetype.Cluster        `yaml:"cluster,omitempty"`
	DeprecatedServiceDiscovery *storagetypeerviceDiscovery `yaml:"service_discovery,omitempty"`
	Log                        *configTypeLog              `yaml:"log,omitempty"`
	LogTargets                 *dpapilog.Targets           `yaml:"log_targets,omitempty"`
}

type StorageDummy

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

func (*StorageDummy) Get

func (*StorageDummy) Load

func (s *StorageDummy) Load(filename string) error

func (*StorageDummy) Save

func (s *StorageDummy) Save() error

func (*StorageDummy) SaveAs

func (s *StorageDummy) SaveAs(filename string) error

func (*StorageDummy) Set

type StorageYML

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

func (*StorageYML) Get

func (*StorageYML) Load

func (s *StorageYML) Load(filename string) error

func (*StorageYML) Save

func (s *StorageYML) Save() error

func (*StorageYML) SaveAs

func (s *StorageYML) SaveAs(filename string) error

func (*StorageYML) Set

type User

type User struct {
	Name     string `long:"name" description:"User name" group:"user" example:"admin"`
	Password string `long:"password" description:"password" group:"user" example:"adminpwd"`
	Insecure bool   `long:"insecure" description:"insecure password" group:"user" example:"true"`
}

type Users

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

func GetUsersStore

func GetUsersStore() *Users

func (*Users) AddUser

func (u *Users) AddUser(user types.User) error

func (*Users) GetUsers

func (u *Users) GetUsers() []types.User

func (*Users) Init

func (u *Users) Init() error

func (*Users) RemoveUser

func (u *Users) RemoveUser(user types.User) error

Jump to

Keyboard shortcuts

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