xconfig

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 37 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NodesConverter converters.Converter = TNodesConverter{}
	PeersConverter converters.Converter = TPeersConverter{}
)

NodesConverter and PeersConverter are the singletons the keyword definitions must reference. They are hosted here instead of the converters package because they depend on the node selector.

View Source
var (
	RegexpOperation = regexp.MustCompile(`(\$\(\(.+\)\))`)
	RegexpIndex     = regexp.MustCompile(`.+\[(?P<Index>[0-9]+)\]`)

	ErrExist                      = errors.New("configuration does not exist")
	ErrInfiniteDeferenceRecursion = errors.New("infinite dereference recursion")
	ErrNoKeyword                  = errors.New("keyword does not exist")
	ErrType                       = errors.New("type error")
	ErrUnknownReference           = errors.New("unknown reference")

	// ErrRefNotAvailable is the error of a strict evaluation naming a
	// reference its RefJudge refused.
	ErrRefNotAvailable = errors.New("reference not available")

	DriverGroups = set.New("ip", "volume", "disk", "fs", "share", "container", "app", "sync", "task")
)
View Source
var (
	// ErrConfigChanged is a write refused because the configuration file
	// is no longer the Base it was checked against.
	ErrConfigChanged = errors.New("the configuration changed while the write was checked")
)
View Source
var ErrUnknownType = errors.New("unknown type")

ErrUnknownType is the error of a write setting the type of a section to a driver om does not know.

Functions

func EvaluatedString

func EvaluatedString(v any) string

EvaluatedString renders an evaluated keyword value the way the configuration spells it.

Evaluating a keyword returns what its converter makes of it, and that is not always a string: a size is an *int64, a duration a *time.Duration, a list a []string. Asking for such a keyword as a string used to assert it was one, so declaring a converter on a keyword any of the many GetString callers happens to read took the process down with it.

A list joins on spaces, which is how a configuration writes one: fmt prints it inside brackets, and a value spelled "[a b]" matches neither a list of allowed values nor a shape a rule refuses. A pointer is followed, fmt printing the address rather than what a converter put behind it.

func InstallFile

func InstallFile(src, dst string) error

InstallFile replaces the configuration file at dst with the file at src, under the lock every writer of dst takes. It is how a configuration made elsewhere, as one fetched from a peer, is installed.

func ValidateReferrer

func ValidateReferrer(dst string, referrer Referrer) error

Types

type Alert

type Alert struct {
	Path    naming.Path `json:"path"`
	Level   AlertLevel  `json:"level"`
	Kind    AlertKind   `json:"kind"`
	Key     key.T       `json:"key"`
	Driver  driver.ID   `json:"driver"`
	Comment string      `json:"comment"`
}

func (Alert) Icon

func (t Alert) Icon() string

func (Alert) String

func (t Alert) String() string

func (Alert) StringWithoutMeta

func (t Alert) StringWithoutMeta() string

func (Alert) Unstructured

func (t Alert) Unstructured() map[string]any

type AlertKind

type AlertKind int

func (AlertKind) MarshalJSON

func (t AlertKind) MarshalJSON() ([]byte, error)

func (AlertKind) String

func (t AlertKind) String() string

func (*AlertKind) UnmarshalJSON

func (t *AlertKind) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type AlertLevel

type AlertLevel int

func (AlertLevel) MarshalJSON

func (t AlertLevel) MarshalJSON() ([]byte, error)

func (AlertLevel) String

func (t AlertLevel) String() string

func (*AlertLevel) UnmarshalJSON

func (t *AlertLevel) UnmarshalJSON(b []byte) error

UnmarshalJSON unmashals a quoted json string to the enum value

type Alerts

type Alerts []Alert

func ValidateFile

func ValidateFile(p string, ref Referrer) (Alerts, error)

func (Alerts) Error

func (t Alerts) Error() string

func (Alerts) Errors

func (t Alerts) Errors() Alerts

Errors are the alerts that make a configuration invalid, as opposed to the warnings that only have something to say about it.

func (Alerts) GetItems

func (t Alerts) GetItems() any

func (Alerts) HasError

func (t Alerts) HasError() bool

func (Alerts) HasWarn

func (t Alerts) HasWarn() bool

func (Alerts) String

func (t Alerts) String() string

func (Alerts) StringWithoutMeta

func (t Alerts) StringWithoutMeta() string

func (Alerts) Warns

func (t Alerts) Warns() Alerts

Warns are the alerts that only have something to say about a configuration, as opposed to the errors that make it invalid.

type Base

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

Base is the configuration file a write was checked against, as read before the checks.

A write is checked, by whoever writes, against the configuration read before it, and lands as a whole file. A file another writer changed in between is replaced by one checked against its predecessor, which puts back what the other write changed, without its checks. A write given a Base lands only if the file is still that Base.

func ReadBase

func ReadBase(p string) (Base, error)

ReadBase reads the configuration file at p as the Base of a write, before the write is checked. A file missing is a Base too: the write lands only if nobody created the file meanwhile.

func (Base) Exists

func (t Base) Exists() bool

Exists says whether the configuration file existed when the base was read.

func (Base) Landing

func (t Base) Landing(fn func() (done func(landed bool), err error)) Base

Landing returns the base with fn run as the write lands: under the lock of the file, once the file is found to be the base, before it is replaced. What fn does is then done by the write that lands alone, never by one refused, as one losing a race with another. An error of fn refuses the write. done, if any, is run once the write is over, saying whether the file was replaced, on an error of fn too, for what fn did before failing.

A base given several runs them in the order given, one failing refusing the write without the next run, and every done of those run is run.

type ErrPostponedRef

type ErrPostponedRef struct {
	Ref string
	RID string
}

func NewErrPostponedRef

func NewErrPostponedRef(ref string, rid string) ErrPostponedRef

func (ErrPostponedRef) Error

func (t ErrPostponedRef) Error() string

type Evaluated

type Evaluated struct {
	Value any
	Text  string
}

Evaluated is a value EvalAs answered, with its text: printed, it is the text a person reads, and in json the value a program reads.

func (Evaluated) MarshalJSON

func (t Evaluated) MarshalJSON() ([]byte, error)

func (Evaluated) Render

func (t Evaluated) Render() string

Render is the text as a command prints it, on a line of its own, and nothing for a value that is not set.

func (Evaluated) String

func (t Evaluated) String() string

type RefJudge

type RefJudge func(ref, val string, err error) error

RefJudge judges a reference a strict evaluation resolved: ref is the reference, without its braces, modifier or index, and val and err what it evaluated to. It returns the reason the evaluation must fail, or nil to go on with val, or err.

type Referrer

type Referrer interface {
	KeywordLookup(key.T, string) *keywords.Keyword
	IsVolatile() bool
	Config() *T
	ConfigData() any

	// for reference private to the referrer. ex: path for an object
	Dereference(string) (string, error)

	// for scoping
	Nodes() ([]string, error)
	DRPNodes() ([]string, error)
}

Referrer is the interface implemented by node and object to provide a reference resolver using their private attributes.

type T

type T struct {
	ConfigFilePath string
	Path           naming.Path
	Referrer       Referrer
	NodeReferrer   Referrer
	// contains filtered or unexported fields
}

T exposes methods to read and write configurations.

func NewObject

func NewObject(p string, sources ...any) (*T, error)

NewObject configures and returns a T instance pointer. The first argument is the path of the configuration file to write to.

The path must be repeated as one of the following sources to read it. Accepted sources are []byte in ini format or a configuration file path containing ini formatted data.

func (T) Changed

func (t T) Changed() bool

func (*T) Commit

func (t *T) Commit() error

func (*T) CommitData

func (t *T) CommitData(configData rawconfig.T) error

func (*T) CommitDataTo

func (t *T) CommitDataTo(configData rawconfig.T, configPath string) error

func (*T) CommitDataToInvalid

func (t *T) CommitDataToInvalid(configData rawconfig.T, configPath string) error

func (*T) CommitInvalid

func (t *T) CommitInvalid() error

func (*T) CommitTo

func (t *T) CommitTo(configPath string) error

func (*T) CommitToInvalid

func (t *T) CommitToInvalid(configPath string) error

func (*T) DeleteSections

func (t *T) DeleteSections(sections ...string) error

DeleteSections deletes sections from the config and commit changes

func (*T) DereferenceAs

func (t *T) DereferenceAs(ref, section, impersonate string) (string, error)

DereferenceAs returns the value of ref, a reference as a keyword value writes it between braces, evaluated in section for the node impersonate, and an error for a reference that resolves to nothing.

func (*T) DriverGroupSet

func (t *T) DriverGroupSet(op keyop.T) error

func (*T) Dump

func (t *T) Dump() ([]byte, error)

func (*T) Eval

func (t *T) Eval(k key.T) (interface{}, error)

func (*T) EvalAs

func (t *T) EvalAs(k key.T, impersonate string) (interface{}, error)

EvalAs returns a key value,

  • contextualized for a node (by default the local node, customized by the impersonate option)
  • dereferenced
  • evaluated

func (*T) EvalKeywordAs

func (t *T) EvalKeywordAs(k key.T, kw *keywords.Keyword, impersonate string) (interface{}, error)

func (*T) EvalNoConv

func (t *T) EvalNoConv(k key.T) (string, error)

func (*T) EvalNoConvAs

func (t *T) EvalNoConvAs(k key.T, impersonate string) (string, error)

EvalNoConvAs is EvalNoConv as the node given evaluates it.

func (*T) EvalStrictAs

func (t *T) EvalStrictAs(k key.T, impersonate string, judge RefJudge) (interface{}, error)

EvalStrictAs returns the value of the key k as EvalAs does, and fails with ErrRefNotAvailable where judge refuses a reference the value names, rather than leave the reference, or what it evaluated to, in the value: a command is not run with a path left empty.

func (*T) EvaluatedText

func (t *T) EvaluatedText(k key.T, v any) string

EvaluatedText writes a value EvalAs answered for the key the way a configuration writes it: a duration as 2m, a size as 5g, a list as its words. The converter of the keyword writes it, so a value computed by an arithmetic, which is a count of bytes before it is converted, reads as a size too.

func (*T) Get

func (t *T) Get(k key.T) string

func (*T) GetBool

func (t *T) GetBool(k key.T) bool

func (*T) GetBoolStrict

func (t *T) GetBoolStrict(k key.T) (bool, error)

func (*T) GetDuration

func (t *T) GetDuration(k key.T) *time.Duration

func (*T) GetDurationStrict

func (t *T) GetDurationStrict(k key.T) (*time.Duration, error)

func (*T) GetInt

func (t *T) GetInt(k key.T) int

GetInt returns the evaluated integer value associated with a key k. On errors returns 0.

func (*T) GetIntStrict

func (t *T) GetIntStrict(k key.T) (int, error)

GetIntStrict returns the evaluated integer value associated with a key k. On errors returns 0 and an appropriate error.

func (*T) GetSet

func (t *T) GetSet(k key.T) *set.Set

func (*T) GetSetStrict

func (t *T) GetSetStrict(k key.T) (*set.Set, error)

func (*T) GetSize

func (t *T) GetSize(k key.T) *int64

func (*T) GetSizeStrict

func (t *T) GetSizeStrict(k key.T) (*int64, error)

func (*T) GetStrict

func (t *T) GetStrict(k key.T) (string, error)

func (*T) GetString

func (t *T) GetString(k key.T) string

func (*T) GetStringAs

func (t *T) GetStringAs(k key.T, impersonate string) string

func (*T) GetStringStrict

func (t *T) GetStringStrict(k key.T) (string, error)

func (*T) GetStringStrictAs

func (t *T) GetStringStrictAs(k key.T, impersonate string) (string, error)

func (*T) GetStrings

func (t *T) GetStrings(k key.T) []string

func (*T) GetStringsStrict

func (t *T) GetStringsStrict(k key.T) ([]string, error)

func (*T) HasKey

func (t *T) HasKey(k key.T) bool

HasKey returns true if the k exists

func (*T) HasKeyMatchingOp

func (t *T) HasKeyMatchingOp(kop keyop.T) bool

func (T) HasSectionString

func (t T) HasSectionString(s string) bool

func (*T) IsInDRPNodes

func (t *T) IsInDRPNodes(impersonate string) (bool, error)

func (*T) IsInEncapNodes

func (t *T) IsInEncapNodes(impersonate string) (bool, error)

func (*T) IsInNodes

func (t *T) IsInNodes(impersonate string) (bool, error)

func (T) KeyList

func (t T) KeyList() key.L

func (*T) Keys

func (t *T) Keys(section string) []string

Keys returns the key names available in a section

func (*T) LoadRaw

func (t *T) LoadRaw(configData rawconfig.T) error

func (*T) MaterializeDefaultSection

func (t *T) MaterializeDefaultSection()

MaterializeDefaultSection gives the DEFAULT section a header, so the configuration is written with the "[DEFAULT]" line and the keywords of that section are visibly grouped under it instead of floating above the first driver section header.

This is what the create codepaths do, so a new object configuration looks like the OpenSVC v2 ones. A configuration that already has the header is left untouched.

func (T) ModTime

func (t T) ModTime() time.Time

func (T) NewAlertCandidates

func (t T) NewAlertCandidates(k key.T, did driver.ID, comment string) Alert

func (T) NewAlertCapabilities

func (t T) NewAlertCapabilities(k key.T, did driver.ID) Alert

func (T) NewAlertConfigure

func (t T) NewAlertConfigure(section string, did driver.ID, err error, disabled bool) Alert

NewAlertConfigure says the resource of section refused its configuration when the object loaded it, by a check its driver makes beyond the keywords, as a network no cni configuration and no cluster network names: the resource is not configured, its status is undef, and its start is refused. A disabled resource is never started, so it is a warning.

func (T) NewAlertDeprecated

func (t T) NewAlertDeprecated(k key.T, did driver.ID, release, replacedBy string) Alert

func (T) NewAlertDeprecatedValue

func (t T) NewAlertDeprecatedValue(k key.T, did driver.ID, comment string) Alert

NewAlertDeprecatedValue says a keyword holds a value om still accepts and no longer recommends, and what to write instead.

It is not the keyword that is deprecated, which is what the alert beside it says: the keyword is the one to use, and one of the forms it takes is on its way out.

func (T) NewAlertEval

func (t T) NewAlertEval(k key.T, did driver.ID, comment string) Alert

func (T) NewAlertIgnoredKeyword

func (t T) NewAlertIgnoredKeyword(k key.T, did driver.ID, comment string) Alert

NewAlertIgnoredKeyword says a keyword is set where a condition it depends on does not hold, as a flex_min of a failover service: what reads it does not, and the value is ignored.

func (T) NewAlertInvalidSection

func (t T) NewAlertInvalidSection(section string, err error) Alert

NewAlertUnknownSection says a section is neither a resource nor a section an object reads, so nothing uses it: the status has no resource to show it by, and the validation is the only place it is reported. NewAlertInvalidSection says a section is named with a character no resource id is made of. Its resource is not configured, and it is an error, so a write naming it is refused rather than ignored.

func (T) NewAlertKeySource

func (t T) NewAlertKeySource(k key.T, did driver.ID, comment string) Alert

NewAlertKeySource says a keyword names a key of a datastore with a source the object can not seed it from: a key another keyword seeds from another source, or a key of a datastore of another namespace.

func (T) NewAlertMissingKeyword

func (t T) NewAlertMissingKeyword(k key.T, did driver.ID, comment string) Alert

NewAlertMissingKeyword says a section following a strategy misses a keyword the strategy requires, as a static address naming no device of the node.

func (T) NewAlertMissingStrategy

func (t T) NewAlertMissingStrategy(k key.T, did driver.ID, comment string) Alert

NewAlertMissingStrategy says a section follows none of the strategies of a group it must follow one of, as an ip naming neither an address nor a network: no start can build it.

func (T) NewAlertMoved

func (t T) NewAlertMoved(k key.T, did driver.ID, comment string) Alert

NewAlertMoved says a keyword is one a driver no longer reads, and what to write for om to do again what it did.

It is not an unknown keyword, which is what the alert beside it says of a keyword nothing has ever heard of: this one was read once, and what it asked for is written elsewhere now.

func (T) NewAlertReferenceGroup

func (t T) NewAlertReferenceGroup(k key.T, did driver.ID, comment string) Alert

NewAlertReferenceGroup says a keyword names a resource of a driver group it does not take, as a netns naming a fs: no section of that name can ever be what the keyword asks for.

func (T) NewAlertScoping

func (t T) NewAlertScoping(k key.T, did driver.ID) Alert

func (T) NewAlertStrategies

func (t T) NewAlertStrategies(k key.T, did driver.ID, comment string) Alert

NewAlertStrategies says a section sets keywords of two strategies of a group of keywords that exclude each other, as an address and the network to draw one from: one of the two is not used as its writer expects.

It is a warning, the resource doing with the keywords what its driver does.

func (T) NewAlertUnknown

func (t T) NewAlertUnknown(k key.T, did driver.ID, comment string) Alert

func (T) NewAlertUnknownDriver

func (t T) NewAlertUnknownDriver(k key.T, did driver.ID) Alert

func (T) NewAlertUnknownResource

func (t T) NewAlertUnknownResource(k key.T, did driver.ID, comment string) Alert

NewAlertUnknownResource says a keyword names a resource the configuration has no section of, as a netns naming a container not configured: the resource using it fails its action.

It is a warning, as a configuration may be written in steps, the resource named added after the one naming it.

func (T) NewAlertUnknownSection

func (t T) NewAlertUnknownSection(section string) Alert

func (T) NewAlertUnsupportedSection

func (t T) NewAlertUnsupportedSection(section, sectionType string) Alert

NewAlertUnsupportedSection says a section is a resource of a driver group this agent does not have, in the words the instance status says it: the status warns of a resource it ignores, and the validation of the configuration is where what to fix is looked for.

The section has no driver to name in the alert, so the group it names is in the comment.

func (*T) NewEvaluated

func (t *T) NewEvaluated(k key.T, v any) Evaluated

NewEvaluated returns the value EvalAs answered for the key, with its text.

func (T) Ops

func (t T) Ops() []string

Ops returns the list of <section>.<option>[@<scope>]=<value> This format is used by the volume pools framework.

func (*T) PrepareDeleteSections

func (t *T) PrepareDeleteSections(sections ...string) error

PrepareDeleteSections deletes sections from the config without committing changes.

func (*T) PrepareSet

func (t *T) PrepareSet(kops ...keyop.T) error

PrepareSet applies key operations to config without committing changes.

func (*T) PrepareUnset

func (t *T) PrepareUnset(ks ...key.T) error

PrepareUnset unsets keywords from config without committing changes.

func (*T) PrepareUpdate

func (t *T) PrepareUpdate(deleteSections []string, unsetKeys []key.T, keyOps []keyop.T) error

PrepareUpdate applies:

1- delete sections
2- unset keywords
3- apply key operations

without committing changes.

func (T) Raw

func (t T) Raw() rawconfig.T

func (T) RawEvaluated

func (t T) RawEvaluated() (rawconfig.T, error)

func (T) RawEvaluatedAs

func (t T) RawEvaluatedAs(impersonate string) (rawconfig.T, error)

func (*T) Recommit

func (t *T) Recommit() error

func (*T) RecommitInvalid

func (t *T) RecommitInvalid() error

func (*T) RegisterPostCommit

func (t *T) RegisterPostCommit(fn func() error)

func (T) Reload

func (t T) Reload() error

func (T) SectionMap

func (t T) SectionMap(section string) map[string]string

func (T) SectionMapStrict

func (t T) SectionMapStrict(section string) (map[string]string, error)

func (T) SectionSig

func (t T) SectionSig(section string) string

func (T) SectionStrings

func (t T) SectionStrings() []string

SectionStrings returns list of section names.

func (*T) SectionType

func (t *T) SectionType(k key.T) string

func (*T) Set

func (t *T) Set(ops ...keyop.T) error

func (*T) SetBase

func (t *T) SetBase(base Base)

SetBase makes the next write of the configuration land only over base, and fail with ErrConfigChanged otherwise.

func (*T) Unset

func (t *T) Unset(ks ...key.T) error

func (*T) UnsetRecorded

func (t *T) UnsetRecorded()

Unset deletes keys and commits. UnsetRecorded drops the keywords that name what this configuration was made with, which a configuration copied to make another thing must not carry: the id the object was created with, the uuid of an md array it holds.

They are written again, for the copy, when the copy makes what they name.

func (*T) Update

func (t *T) Update(deleteSections []string, unsetKeys []key.T, keyOps []keyop.T) error

Update applies:

1- delete sections
2- unset keywords
3- apply key operations

and commit changes.

func (T) Validate

func (t T) Validate() (Alerts, error)

type TNodesConverter

type TNodesConverter struct{}

TNodesConverter is the type of converter used for the nodes keyword, which makes sure the local nodename is in the resulting []string.

func (TNodesConverter) Convert

func (t TNodesConverter) Convert(s string) (interface{}, error)

func (TNodesConverter) String

func (t TNodesConverter) String() string

type TPeersConverter

type TPeersConverter struct{}

TPeersConverter is the type of converter used for the drpnodes and encapnodes keyword, which accepts to return an empty list.

func (TPeersConverter) Convert

func (t TPeersConverter) Convert(s string) (interface{}, error)

func (TPeersConverter) String

func (t TPeersConverter) String() string

Jump to

Keyboard shortcuts

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