Documentation
¶
Index ¶
- Variables
- func CloneNode(n *yaml.Node) *yaml.Node
- func EnsureKeyWithComment(root *yaml.Node, path []string, comment string)
- func MigrateNode(user *yaml.Node, from, to string, chain []MigrationStep) (*yaml.Node, error)
- func MigrateYaml(logger iface.Logger, path string, latestVersion string, ...) error
- func ResolveNode(root *yaml.Node, path []string) *yaml.Node
- type Always
- type IfUnchanged
- type MigrationStep
- type PatchCondition
- type PatchEngine
- type PatchRule
- type VersionComparator
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyUpToDate = errors.New("already up to date")
Known errors which we can ignore
Functions ¶
func EnsureKeyWithComment ¶
EnsureKeyWithComment adds “# comment\nkey:” (with an empty sequence value) if key missing
func MigrateNode ¶
MigrateNode runs all MigrationStep from 'from' to 'to' on the provided user YAML AST, returning the migrated AST
func MigrateYaml ¶
func MigrateYaml(logger iface.Logger, path string, latestVersion string, migrationChain []MigrationStep) error
Run all migrations after current version upto latestVersion according to migrationChain
Types ¶
type IfUnchanged ¶
type IfUnchanged struct{}
func (IfUnchanged) ShouldApply ¶
func (IfUnchanged) ShouldApply(userNode, oldNode *yaml.Node) bool
IfUnchanged applies only if userNode equals oldNode
type MigrationStep ¶
type MigrationStep struct {
From string
To string
Apply func(user, oldDef, newDef *yaml.Node) (*yaml.Node, error)
OldYAML []byte
NewYAML []byte
}
MigrationStep represents one version-to-version migration
type PatchCondition ¶
type PatchCondition interface {
// ShouldApply returns true if the userNode should be patched based on oldNode
ShouldApply(userNode, oldNode *yaml.Node) bool
}
PatchCondition defines a node-level condition
type PatchEngine ¶
PatchEngine applies a set of PatchRule against a user YAML AST preserving order, comments, and anchors
func (*PatchEngine) Apply ¶
func (e *PatchEngine) Apply() error
Apply walks each rule, and when Condition is met, either removes the node or replaces it with a (transformed) copy
type PatchRule ¶
type PatchRule struct {
// Path: sequence of map keys or sequence indices (as strings)
Path []string
// Condition: returns true if the patch should apply
Condition PatchCondition
// Transform: optional node-level transformation on the new node
Transform func(newNode *yaml.Node) *yaml.Node
// Remove: if true, delete the node instead of patching
Remove bool
}
PatchRule defines a YAML node patch rule
type VersionComparator ¶
VersionGreaterThan uses semantic dot-separated compare for strings