config

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: EPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ShutdownPolicyLeaveRunning skips runtime drain on control-plane stop; MS reattach on start.
	ShutdownPolicyLeaveRunning = "leave-running"
	// ShutdownPolicyDrainAll stops managed MS containers during shutdown (embedded monolith / data-plane stop).
	ShutdownPolicyDrainAll = "drain-all"
)

Variables

View Source
var (
	ErrConfigNotLoaded    = errors.New("configuration not loaded")
	ErrProfileNotFound    = errors.New("profile not found")
	ErrInvalidConfig      = errors.New("invalid configuration")
	ErrConfigFileNotFound = errors.New("config file not found")
)
View Source
var AllowedArchValues = []string{"auto", "amd64", "arm64", "arm", "riscv64"}

AllowedArchValues are valid config arch settings (FogType source).

View Source
var ConfigParamMap = map[string]string{
	"d":    "diskLimit",
	"dl":   "diskDirectory",
	"m":    "memoryLimit",
	"p":    "cpuLimit",
	"a":    "controllerURL",
	"ac":   "controllerCert",
	"cu":   "containerEngineURL",
	"ce":   "containerEngine",
	"n":    "networkInterface",
	"l":    "logLimit",
	"ld":   "logDirectory",
	"lc":   "logFileCount",
	"ll":   "logLevel",
	"sf":   "statusFrequency",
	"cf":   "changeFrequency",
	"wd":   "watchdogEnabled",
	"egf":  "edgeGuardFrequency",
	"gps":  "gpsMode",
	"gpsc": "gpsCoordinates",
	"gpsd": "gpsDevice",
	"gpsf": "gpsScanFrequency",
	"ft":   "arch",
	"sec":  "secureMode",
	"pf":   "pruningFrequency",
	"dt":   "availableDiskThreshold",
	"uf":   "upgradeScanFrequency",
	"dev":  "devMode",
	"tz":   "timeZone",
}

ConfigParamMap maps command line parameter names to config fields

Functions

func ArchitectureCode

func ArchitectureCode(value string) int

ArchitectureCode maps arch config to Pot provision FogType (1=amd64, 2=arm64, 3=riscv64, 4=arm).

func DefaultContainerEngineURLForEngine

func DefaultContainerEngineURLForEngine(engine string) string

DefaultContainerEngineURLForEngine returns the platform default socket URL for an engine family.

func DefaultShutdownPolicy

func DefaultShutdownPolicy(containerEngine string) string

DefaultShutdownPolicy returns the engine-appropriate default when shutdownPolicy is unset.

func DisplayArch

func DisplayArch(value string) string

DisplayArch returns the architecture name shown in status/info (never "auto").

func FullReload

func FullReload(hooks ReloadHooks) error

FullReload reads config from disk, validates it, updates the logger, and notifies modules.

func InitConfig

func InitConfig(configPath string) (created bool, err error)

InitConfig writes the default config template when the target path is missing. If the file already exists, it is left unchanged and created is false.

func IsLastReloadSuccessful

func IsLastReloadSuccessful() bool

IsLastReloadSuccessful indicates if the most recent config reload succeeded.

func IsReloadSuppressedForDeprovision

func IsReloadSuppressedForDeprovision() bool

IsReloadSuppressedForDeprovision returns whether SIGHUP should be skipped.

func IsReloadSuppressedForInProcessMutation

func IsReloadSuppressedForInProcessMutation() bool

IsReloadSuppressedForInProcessMutation returns whether watcher SIGHUP should be skipped.

func LoadConfig

func LoadConfig(configPath string) error

LoadConfig loads configuration from YAML file

func ParseSecureMode

func ParseSecureMode(value string) bool

ParseSecureMode interprets secureMode config values. Only explicit off/false synonyms disable TLS verification; everything else enables secure mode.

func PatchKeysFromMap

func PatchKeysFromMap(configMap map[string]any) map[string]struct{}

PatchKeysFromMap converts a SetConfig map to short-code keys for classification.

func RefreshIPAddressExternal added in v1.1.0

func RefreshIPAddressExternal(ctx context.Context) error

RefreshIPAddressExternal sets IPAddressExternal from the public-address lookup. It does not change GPS coordinates and does not write the config file.

func ResolveArch

func ResolveArch(value string) string

ResolveArch maps config arch to a concrete architecture name (auto → runtime GOARCH).

func RestoreReloadAfterDeprovision

func RestoreReloadAfterDeprovision()

RestoreReloadAfterDeprovision clears the suppression flag.

func RestoreReloadAfterInProcessMutation

func RestoreReloadAfterInProcessMutation()

RestoreReloadAfterInProcessMutation clears in-process reload suppression.

func RunInProcessConfigMutation

func RunInProcessConfigMutation(fn func() error) error

RunInProcessConfigMutation suppresses file-watcher SIGHUP for fn (config save + reload).

func SaveConfig

func SaveConfig(configPath string) error

SaveConfig saves the configuration to YAML file

func SaveConfigWithYaml

func SaveConfigWithYaml(configPath string, yamlConfig *models.YamlConfig) error

SaveConfigWithYaml saves the provided YAML config to file (avoids lock acquisition)

func ScheduleIPAddressExternalRefresh added in v1.1.0

func ScheduleIPAddressExternalRefresh()

ScheduleIPAddressExternalRefresh looks up the public address in the background. A failed lookup leaves the previous address in place and does not block the caller.

func SetLastReloadSuccessful

func SetLastReloadSuccessful(ok bool)

SetLastReloadSuccessful updates the last reload result.

func SnapshotYAML

func SnapshotYAML(path string) ([]byte, error)

SnapshotYAML returns a copy of the on-disk YAML bytes for revert on failed warm reload.

func SuppressReloadForDeprovision

func SuppressReloadForDeprovision()

SuppressReloadForDeprovision sets a flag so the config watcher skips SIGHUP when the config file is written during deprovision. Prevents CLI timeout.

func SuppressReloadForInProcessMutation

func SuppressReloadForInProcessMutation()

SuppressReloadForInProcessMutation sets a flag so the config watcher skips SIGHUP while the daemon writes config and applies TriggerReloadCallback in-process (API PATCH).

func ValidateArch

func ValidateArch(value string) error

ValidateArch reports whether value is an allowed arch config setting.

func ValidateConfig

func ValidateConfig(cfg *Config) error

ValidateConfig validates the configuration

func ValidateProperty

func ValidateProperty(key, value string) error

ValidateProperty validates a single property value

Types

type ChangeClass

type ChangeClass int

ChangeClass describes how a config mutation affects the daemon.

const (
	ChangeClassHot ChangeClass = iota
	ChangeClassWarm
	ChangeClassCold
)

func ClassifyEngineConfigChange

func ClassifyEngineConfigChange(startupEngine, newEngine, startupURL, newURL string, _ map[string]struct{}) ChangeClass

ClassifyEngineConfigChange compares startup vs reloaded config.

type Config

type Config struct {

	// Directly configurable params
	IOFogUUID                       string
	PrivateKey                      string
	ControllerURL                   string
	ContainerEngine                 string
	ControllerCert                  string
	NetworkInterface                string
	ContainerEngineURL              string
	DiskLimit                       float64
	MemoryLimit                     float64
	DiskDirectory                   string
	CPULimit                        float64
	LogLimit                        float64
	LogDirectory                    string
	LogFileCount                    int
	LogLevel                        string
	StatusFrequency                 int
	ChangeFrequency                 int
	WatchdogEnabled                 bool
	EdgeGuardFrequency              int64
	GPSDevice                       string
	GPSScanFrequency                int64
	GPSCoordinates                  string
	GPSMode                         string
	Arch                            string
	SecureMode                      bool
	IPAddressExternal               string
	RouterUUID                      string
	IsRouterInterior                bool
	PruningFrequency                int64
	AvailableDiskThreshold          int64
	UpgradeScanFrequency            int
	DevMode                         bool
	TimeZone                        string
	Namespace                       string
	ShutdownGracePeriodSeconds      int
	ShutdownPolicy                  string
	ControllerRequestTimeoutSeconds int
	ControllerPingTimeoutSeconds    int

	// Automatic configurable params (calculated)
	StatusReportFreqSeconds            int
	PingControllerFreqSeconds          int
	MonitorContainersStatusFreqSeconds int
	// LogReconcileCycleEveryNTicks emits reconcile.cycle at Info when idle (no scheduling) every N monitor ticks.
	LogReconcileCycleEveryNTicks       int
	MonitorRegistriesStatusFreqSeconds int
	HealthcheckIntervalSeconds         int // Interval for exec-based healthcheck (iofog engine only)
	GetUsageDataFreqSeconds            int64
	DockerAPIVersion                   string
	SetSystemTimeFreqSeconds           int
	MonitorSSHTunnelStatusFreqSeconds  int

	// Debugging flag
	Debugging bool
	// contains filtered or unexported fields
}

Config represents the runtime configuration

func GetInstance

func GetInstance() *Config

GetInstance returns the singleton config instance

func (*Config) ApplyEngineDefaults

func (c *Config) ApplyEngineDefaults(engine string) error

ApplyEngineDefaults updates containerEngineUrl when containerEngine changes in-memory and YAML.

func (*Config) ConsumeReloadPriorContainerEngineURL

func (c *Config) ConsumeReloadPriorContainerEngineURL() (string, bool)

ConsumeReloadPriorContainerEngineURL returns and clears a reload snapshot if present.

func (*Config) FilterChangedConfigKeys

func (c *Config) FilterChangedConfigKeys(configMap map[string]any) map[string]any

FilterChangedConfigKeys returns only entries whose normalized value differs from the current in-memory config. Used when applying full controller config snapshots so unchanged keys are not re-written or validated as mutations.

func (*Config) GetConfigPath

func (c *Config) GetConfigPath() string

GetConfigPath returns the config file path (thread-safe)

func (*Config) GetConfigReport

func (c *Config) GetConfigReport() string

GetConfigReport returns a formatted config report string (for info endpoint) Uses IPAddressExternal from config

func (*Config) GetConfigReportWithIP

func (c *Config) GetConfigReportWithIP(ipAddress string) string

GetConfigReportWithIP returns a formatted config report string with provided IP address

func (*Config) GetCurrentProfile

func (c *Config) GetCurrentProfile() utils.ConfigSwitcherState

GetCurrentProfile returns the current profile (thread-safe)

func (*Config) GetIPAddressExternal added in v1.1.0

func (c *Config) GetIPAddressExternal() string

GetIPAddressExternal returns the in-memory public address.

func (*Config) GetProperty

func (c *Config) GetProperty(key string) string

GetProperty gets a property from the current profile

func (*Config) GetYamlConfig

func (c *Config) GetYamlConfig() *models.YamlConfig

GetYamlConfig returns the YAML config (thread-safe)

func (*Config) LeaveRunningOnControlStop

func (c *Config) LeaveRunningOnControlStop() bool

LeaveRunningOnControlStop reports whether control-plane stop should skip runtime drain.

func (*Config) NotifyModulesOfConfigChange

func (c *Config) NotifyModulesOfConfigChange() error

NotifyModulesOfConfigChange notifies modules when configuration changes This should be called after SetConfig to update modules like FieldAgent

func (*Config) RevertContainerEngineURL

func (c *Config) RevertContainerEngineURL(containerEngineURL string) error

RevertContainerEngineURL restores containerEngineUrl in memory and YAML after a failed warm reload.

func (*Config) SetConfig

func (c *Config) SetConfig(configMap map[string]any) map[string]string

SetConfig sets configuration values from a map of command line parameters Returns a map of errors keyed by parameter name

func (*Config) SetConfigPath

func (c *Config) SetConfigPath(path string)

SetConfigPath sets the config file path (thread-safe)

func (*Config) SetCurrentProfile

func (c *Config) SetCurrentProfile(profile utils.ConfigSwitcherState)

SetCurrentProfile sets the current profile (thread-safe)

func (*Config) SetGPSConfigCallback

func (c *Config) SetGPSConfigCallback(cb func() error)

SetGPSConfigCallback sets the callback for GPS configuration updates.

func (*Config) SetProperty

func (c *Config) SetProperty(key, value string) error

SetProperty sets a property in the current profile

func (*Config) SetReloadCallback

func (c *Config) SetReloadCallback(cb func() error)

SetReloadCallback sets the callback for configuration reload

func (*Config) SetRouterInterior

func (c *Config) SetRouterInterior(v bool)

func (*Config) SetRouterUUID

func (c *Config) SetRouterUUID(uuid string)

func (*Config) SetYamlConfig

func (c *Config) SetYamlConfig(yc *models.YamlConfig)

SetYamlConfig sets the YAML config (thread-safe)

func (*Config) ShutdownDrainTimeout

func (c *Config) ShutdownDrainTimeout() int

ShutdownDrainTimeout returns the configured runtime drain deadline for maintenance/data-plane stops.

func (*Config) SnapshotForReload

func (c *Config) SnapshotForReload()

SnapshotForReload records containerEngineUrl before an in-process config mutation (API PATCH).

func (*Config) SwitchProfile

func (c *Config) SwitchProfile(profile utils.ConfigSwitcherState) error

SwitchProfile sets active configuration profile and persists currentProfile.

func (*Config) TriggerGPSConfigCallback

func (c *Config) TriggerGPSConfigCallback() error

TriggerGPSConfigCallback triggers the GPS configuration update callback.

func (*Config) TriggerReloadCallback

func (c *Config) TriggerReloadCallback() error

TriggerReloadCallback triggers the configuration reload callback

type ReloadHooks

type ReloadHooks struct {
	ConfigPath    string
	BeginReload   func()
	NotifyModules func() error
}

ReloadHooks supplies supervisor-specific steps for a full config reload.

type Watcher

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

Watcher watches for configuration file changes

func GetWatcher

func GetWatcher() *Watcher

GetWatcher returns the singleton watcher instance

func (*Watcher) Close

func (w *Watcher) Close() error

Close closes the watcher

func (*Watcher) OnChange

func (w *Watcher) OnChange(callback func())

OnChange registers a callback to be called when config changes

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, configPath string) error

Watch starts watching the configuration file for changes

Jump to

Keyboard shortcuts

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