Documentation
¶
Index ¶
- Constants
- Variables
- func Abbrev(names []string) []string
- func IsPathPattern(s string) bool
- func IsValidFQDN(s string) bool
- func LogWithPath(l *plog.Logger, p Path) *plog.Logger
- func Random() string
- type FQDN
- type Kind
- type Kinds
- type M
- type Metadata
- type Path
- func (t Path) ConfigFile() string
- func (t Path) Equal(o Path) bool
- func (t Path) Exists() bool
- func (t Path) FQN() string
- func (t Path) FrozenFile() string
- func (t Path) Initd() string
- func (t Path) IsZero() bool
- func (t Path) LogDir() string
- func (t Path) LogFile() string
- func (t Path) MarshalText() ([]byte, error)
- func (t Path) Match(pattern string) bool
- func (t Path) ModTime() (time.Time, error)
- func (t Path) Path() Path
- func (t Path) ScalerSliceIndex() int
- func (t Path) StoppedFile() string
- func (t Path) String() string
- func (t Path) TmpDir() string
- func (t Path) ToMetadata() *Metadata
- func (t *Path) UnmarshalText(b []byte) error
- func (t Path) VarDir() string
- type PathPattern
- type Paths
- type Relation
- type Relations
Constants ¶
const ( NsRoot = "root" NsSys = "system" )
const (
// Separator is the character separating a path's namespace, kind and name
Separator = "/"
)
Variables ¶
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), } )
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") )
var (
ErrPathPatternStars = errors.New("a name pattern holds one *")
)
Functions ¶
func Abbrev ¶
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 ¶
IsPathPattern says whether s names objects by a pattern of their name rather than one object.
func IsValidFQDN ¶
IsValidFQDN verifies the string meets the RFC1123 requirements
func LogWithPath ¶
LogWithPath returns plog.Logger from existing logger with naming attrs sets
Types ¶
type FQDN ¶
func (FQDN) MarshalText ¶
MarshalText implements the json interface
func (*FQDN) UnmarshalText ¶
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" )
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 ¶
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 NewPathFromStrings ¶
func ParsePathRel ¶
func (Path) ConfigFile ¶
ConfigFile returns the object configuration file path on the local filesystem.
func (Path) FrozenFile ¶
FrozenFile returns the path of the flag file blocking orchestrations and resource restart.
func (Path) LogDir ¶
LogDir returns the directory on the local filesystem where the object stores its temporary files.
func (Path) MarshalText ¶
MarshalText implements the json interface
func (Path) Match ¶
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) ScalerSliceIndex ¶
ScalerSliceIndex returns the <i> int from a scaler slice name like <i>.<scalerName> Return -1 if not a scaler slice.
func (Path) StoppedFile ¶
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) TmpDir ¶
TmpDir returns the directory on the local filesystem where the object stores its temporary files.
func (Path) ToMetadata ¶
ToMetadata returns the parsed representation of the path
func (*Path) UnmarshalText ¶
UnmarshalText implements the json interface
type PathPattern ¶
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 ¶
InstalledPaths returns a list of every object path with a locally installed configuration file.
func ParsePaths ¶
ParsePaths returns a new naming.Paths from a []string path list.
func (Paths) Namespaces ¶
Namespaces return the list of unique namespaces in Paths
func (Paths) StrMap ¶
StrMap converts Paths into a map indexed by path string representation. This format is useful for fast Has(string) bool functions.
type Relations ¶
type Relations []Relation
Relations is a slice of Relation
func ParseRelations ¶
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