naming

package
v3.0.0-rc49 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NsRoot = "root"
	NsSys  = "system"
)
View Source
const (
	// Separator is the character separating a path's namespace, kind and name
	Separator = "/"
)

Variables

View Source
var (
	KindDataStore = []Kind{
		KindCfg,
		KindSec,
		KindUsr,
	}

	KindKeyStore = []Kind{
		KindSec,
		KindUsr,
	}

	KindAll = []Kind{
		KindSvc,
		KindVol,
		KindCfg,
		KindSec,
		KindUsr,
		KindCcfg,
		KindNscfg,
	}

	KindStrings = []string{
		string(KindSvc),
		string(KindVol),
		string(KindCfg),
		string(KindSec),
		string(KindUsr),
		string(KindCcfg),
		string(KindNscfg),
	}
)
View Source
var (
	Cluster = Path{Name: "cluster", Namespace: NsRoot, Kind: KindCcfg}
	SecCa   = Path{Name: "ca", Namespace: NsSys, Kind: KindSec}
	SecCert = Path{Name: "cert", Namespace: NsSys, Kind: KindSec}
	SecHb   = Path{Name: "hb", Namespace: NsSys, Kind: KindSec}

	// ErrInvalid is raised when the path allocator can not return a path
	// because one of the path element is not valid.
	ErrInvalid = errors.New("invalid path")
)
View Source
var (
	ErrPathPatternStars = errors.New("a name pattern holds one *")
)

Functions

func Abbrev

func Abbrev(names []string) []string

Abbrev shortens fully qualified names to the labels that tell them apart, for the column headers of a listing whose width the names would otherwise decide.

A label every name carries the same value at carries no information once the names are shown side by side, wherever in the name it sits. In a cluster of node1.prod.example.com and node2.prod.example.com only the first label differs, and the rest costs eighteen columns per node to say the same thing three times. Dropped labels are replaced by "..", so a shortened name is never mistaken for a name that is short, and so the reader can see that something stood where the marker is:

ip-xxx-xxx-xxx.commondomain1.eu-fr-paris.commondomain2.etc
ip-yyy-yyy-zzz.commondomain1.eu-fr-north.commondomain2.etc

abbreviates to

ip-xxx-xxx-xxx..eu-fr-paris..
ip-yyy-yyy-zzz..eu-fr-north..

A run of dropped labels is one marker, not one per label: the marker says that a name was cut here, and how many labels were cut is not something a column header is the place to count.

The labels the names do not share are kept, because they are what tells them apart: node1.paris.example.com and node1.lyon.example.com abbreviate to node1.paris.. and node1.lyon.., not to two identical node1.. columns.

The first label is kept even when every name shares it, because it is the name of the node, and a column headed "..paris.." names nothing an operator can act on.

Names are compared right to left, which is how a domain name is anchored: a position then means the same thing in every name, whatever their depths. A name with no domain has nothing to drop, and does not get a say in what the others share.

This generalises the abbrev() of OpenSVC v2, which dropped only the shared tail. v2 returns a.example.com and b.example.org untouched, having no shared tail to drop; this returns a..com and b..org, the shared label in the middle being no more informative for sitting there.

func IsPathPattern

func IsPathPattern(s string) bool

IsPathPattern says whether s names objects by a pattern of their name rather than one object.

func IsValidFQDN

func IsValidFQDN(s string) bool

IsValidFQDN verifies the string meets the RFC1123 requirements

func LogWithPath

func LogWithPath(l *plog.Logger, p Path) *plog.Logger

LogWithPath returns plog.Logger from existing logger with naming attrs sets

func Random

func Random() string

Types

type FQDN

type FQDN struct {
	Path    Path
	Cluster string
}

func NewFQDN

func NewFQDN(path Path, cluster string) *FQDN

func ParseFQDN

func ParseFQDN(s string) (*FQDN, error)

func (FQDN) Domain

func (t FQDN) Domain() string

Domain returns the domain part of the fqdn

func (FQDN) MarshalText

func (t FQDN) MarshalText() ([]byte, error)

MarshalText implements the json interface

func (FQDN) String

func (t FQDN) String() string

func (*FQDN) UnmarshalText

func (t *FQDN) UnmarshalText(b []byte) error

UnmarshalText implements the json interface

type Kind

type Kind string

Kind is opensvc object kind.

const (
	KindInvalid Kind = ""

	// KindSvc is the kind of objects containing app, containers, or volumes resources.
	KindSvc Kind = "svc"

	// KindVol is the kind of objects containing fs, disk resources. Allocated from Pools.
	KindVol Kind = "vol"

	// KindCfg is the kind of objects containing unencrypted key/val pairs used to abstract Svc configurations
	KindCfg Kind = "cfg"

	// KindSec is the kind of objects containing encrypted key/val pairs used to abstract Svc configurations
	KindSec Kind = "sec"

	// KindUsr is the kind of objects containing a API user grants and credentials
	KindUsr Kind = "usr"

	// KindCcfg is the kind of objects containing the cluster configuration
	KindCcfg Kind = "ccfg"

	// KindNscfg is the kind of objects containing a namespace configuration
	KindNscfg Kind = "nscfg"
)

func ParseKind

func ParseKind(s string) Kind

ParseKind returns a Kind from its string representation.

func (Kind) Or

func (t Kind) Or(kinds ...Kind) Kinds

func (Kind) String

func (t Kind) String() string

type Kinds

type Kinds map[Kind]any

Kinds is the result of a binary Or on Kind values

func NewKinds

func NewKinds(kinds ...Kind) Kinds

func ParseKinds

func ParseKinds(kinds ...string) Kinds

func (Kinds) Clone

func (t Kinds) Clone() Kinds

func (Kinds) Has

func (t Kinds) Has(kind Kind) bool

func (Kinds) Or

func (t Kinds) Or(kinds ...Kind) Kinds

func (Kinds) String

func (t Kinds) String() string

String renders the set, in a stable order. A set has no order of its own, and this is read by a human and compared from one release to the next.

type M

type M map[string]interface{}

M is a map indexed by path string representation.

func (M) Has

func (t M) Has(s string) bool

func (M) HasPath

func (t M) HasPath(path Path) bool

type Metadata

type Metadata struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Kind      Kind   `json:"kind"`
}

Metadata is the parsed representation of a path, used by api handlers to ease dumb clients access to individual path fields.

type Path

type Path struct {
	// Name is the name part of the path
	Name string
	// Namespace is the namespace part of the path
	Namespace string
	// Kind is the kind part of the path
	Kind Kind
}

Path represents an opensvc object path-like identifier. Ex: ns1/svc/svc1

func ConfigFilePath

func ConfigFilePath(filename string) (Path, error)

ConfigFilePath return the object path owning the config file pass as argument.

e.g. * /etc/opensvc/namespace.conf => path.T{Namespace: "root", Kind: KindNscfg, Name: "namespace"} * /etc/opensvc/sec/namespace.conf => path.T{Namespace: "root", Kind: KindSec, Name: "namespace"} * /etc/opensvc/namespaces/test/namespace.conf => path.T{Namespace: "test", Kind: KindNscfg, Name: "namespace"} * /etc/opensvc/namespaces/test/svc/namespace.conf => path.T{Namespace: "test", Kind: KindSvc, Name: "namespace"}

func NewPath

func NewPath(namespace string, kind Kind, name string) (Path, error)

NewPath allocates a new path type from its elements

func NewPathFromStrings

func NewPathFromStrings(namespace, kind, name string) (Path, error)

func ParsePath

func ParsePath(s string) (Path, error)

ParsePath returns a new path struct from a path string representation

func ParsePathRel

func ParsePathRel(s, ns string) (Path, error)

func (Path) ConfigFile

func (t Path) ConfigFile() string

ConfigFile returns the object configuration file path on the local filesystem.

func (Path) Equal

func (t Path) Equal(o Path) bool

func (Path) Exists

func (t Path) Exists() bool

Exists returns true if the object configuration file exists.

func (Path) FQN

func (t Path) FQN() string

func (Path) FrozenFile

func (t Path) FrozenFile() string

FrozenFile returns the path of the flag file blocking orchestrations and resource restart.

func (Path) Initd

func (t Path) Initd() string

Initd returns a path-private directory that can contain app scripts.

func (Path) IsZero

func (t Path) IsZero() bool

func (Path) LogDir

func (t Path) LogDir() string

LogDir returns the directory on the local filesystem where the object stores its temporary files.

func (Path) LogFile

func (t Path) LogFile() string

LogFile returns the object log file path on the local filesystem.

func (Path) MarshalText

func (t Path) MarshalText() ([]byte, error)

MarshalText implements the json interface

func (Path) Match

func (t Path) Match(pattern string) bool

Match returns true if the object matches the pattern, using a fnmatch matching algorithm with a few special cases to mask the root namespace tricks and the svc object kind as default.

Trick: The 'f*' pattern matches all svc objects in the root namespace. The '*' pattern matches all svc objects in all namespaces.

func (Path) ModTime

func (t Path) ModTime() (time.Time, error)

func (Path) Path

func (t Path) Path() Path

Path implements the Pather interface

func (Path) ScalerSliceIndex

func (t Path) ScalerSliceIndex() int

ScalerSliceIndex returns the <i> int from a scaler slice name like <i>.<scalerName> Return -1 if not a scaler slice.

func (Path) StoppedFile

func (t Path) StoppedFile() string

StoppedFile returns the path of the flag file saying the instance was stopped on purpose, so the daemon does not start it back on its own.

This is a flag file, and not a monitor state, because the decision has to survive a daemon restart and a reboot: a node that comes back up must not start what an operator asked to be down.

func (Path) String

func (t Path) String() string

func (Path) TmpDir

func (t Path) TmpDir() string

TmpDir returns the directory on the local filesystem where the object stores its temporary files.

func (Path) ToMetadata

func (t Path) ToMetadata() *Metadata

ToMetadata returns the parsed representation of the path

func (*Path) UnmarshalText

func (t *Path) UnmarshalText(b []byte) error

UnmarshalText implements the json interface

func (Path) VarDir

func (t Path) VarDir() string

VarDir returns the directory on the local filesystem where the object variable persistent data is stored as files.

type PathPattern

type PathPattern struct {
	Namespace string
	Kind      Kind
	Name      string
}

PathPattern is the objects of a namespace and a kind a pattern of their name names, as "./sec/haproxy-*": the name holds one *, which matches one character or more, the part of the name it matches telling the objects apart.

func ParsePathPatternRel

func ParsePathPatternRel(s, ns string) (PathPattern, error)

ParsePathPatternRel parses the objects s names by a pattern of their name, relative to the namespace ns as ParsePathRel parses a path: "./sec/haproxy-*", "ns1/cfg/web-*", "sec/ca-*" in the root namespace.

func (PathPattern) InstalledPaths

func (t PathPattern) InstalledPaths() Paths

InstalledPaths returns the objects the pattern names whose configuration is installed on the node, sorted.

func (PathPattern) Match

func (t PathPattern) Match(name string) (string, bool)

Match returns the part of the name the * of the pattern matches, none when the name does not match it. The part is not empty: a * matching nothing would tell no object apart.

func (PathPattern) MatchPath

func (t PathPattern) MatchPath(p Path) bool

MatchPath says whether the pattern names the object at p.

func (PathPattern) String

func (t PathPattern) String() string

type Paths

type Paths []Path

Paths is a list of object paths.

func InstalledPaths

func InstalledPaths() (Paths, error)

InstalledPaths returns a list of every object path with a locally installed configuration file.

func ParsePaths

func ParsePaths(l ...string) (Paths, error)

ParsePaths returns a new naming.Paths from a []string path list.

func (Paths) Existing

func (t Paths) Existing() Paths

func (Paths) Filter

func (t Paths) Filter(pattern string) Paths

func (Paths) Merge

func (t Paths) Merge(other Paths) Paths

func (Paths) Namespaces

func (t Paths) Namespaces() []string

Namespaces return the list of unique namespaces in Paths

func (Paths) StrMap

func (t Paths) StrMap() M

StrMap converts Paths into a map indexed by path string representation. This format is useful for fast Has(string) bool functions.

func (Paths) StrSlice

func (t Paths) StrSlice() []string

StrSlice converts Paths into a string slice. This format is useful to prepare api handlers parameters.

func (Paths) String

func (t Paths) String() string

type Relation

type Relation string

Relation is an object path or an instance path (path@node).

func (Relation) Node

func (t Relation) Node() string

func (Relation) Path

func (t Relation) Path() (Path, error)

func (Relation) Split

func (t Relation) Split() (Path, string, error)

func (Relation) String

func (t Relation) String() string

type Relations

type Relations []Relation

Relations is a slice of Relation

func ParseRelations

func ParseRelations(l []string, ns string) Relations

ParseRelations resolves test/svc/svc1 relations with a local-centric policy.

Explicitely local:

children = ./svc/svc2    => test/svc/svc2

Implicitely local:

children = svc3          => test/svc/svc3

Explicitely foreign:

children = root/svc/svc2 => root/svc/svc2

Implicitely local with scope:

children svc4@n1         => test/svc/svc4@n1

func (Relations) HasPath

func (relations Relations) HasPath(path Path) (bool, error)

func (Relations) Strings

func (relations Relations) Strings() []string

Jump to

Keyboard shortcuts

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