Documentation
¶
Overview ¶
Package convert provides YAML conversion for CAPMOX v1alpha1→v1alpha2 and CAPI v1beta1→v1beta2 resources.
Index ¶
- Constants
- func Convert(input []byte, opts Options) ([]byte, error)
- func ConvertCAPI(yamlDoc []byte, id ResourceID, filename string, indent int, warn WarnFunc, ...) ([]byte, error)
- func ConvertCAPMOX(yamlDoc []byte, id ResourceID, filename string, indent int, warn WarnFunc, ...) ([]byte, error)
- func DetectResource(yamlDoc []byte) (ResourceID, ConverterType)
- func GraftComments(src, dst *yaml.Node, filename string, warn WarnFunc)
- func PruneDefaults(node *yaml.Node, resourceKind string)
- func Restore(yamlText string, entries []SentinelEntry) string
- func RestoreNode(node *yaml.Node, entries []SentinelEntry)
- func StripStatus(node *yaml.Node, filename string, warn WarnFunc)
- type ConverterType
- type Options
- type ResourceID
- type SentinelEntry
- type WarnFunc
- type Warning
Constants ¶
const ( KindProxmoxCluster = "ProxmoxCluster" KindProxmoxMachine = "ProxmoxMachine" KindProxmoxMachineTemplate = "ProxmoxMachineTemplate" KindProxmoxClusterTemplate = "ProxmoxClusterTemplate" )
CAPMOX resource kind constants.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert processes a multi-document YAML text, converting each document through the appropriate converter pipeline. Warnings are emitted immediately via opts.Warn as they are discovered.
func ConvertCAPI ¶
func ConvertCAPI(yamlDoc []byte, id ResourceID, filename string, indent int, warn WarnFunc, entries []SentinelEntry) ([]byte, error)
ConvertCAPI converts a CAPI v1beta1 resource to v1beta2 using native ConvertTo methods. Warnings are emitted immediately via warn.
func ConvertCAPMOX ¶
func ConvertCAPMOX(yamlDoc []byte, id ResourceID, filename string, indent int, warn WarnFunc, entries []SentinelEntry) ([]byte, error)
ConvertCAPMOX converts a CAPMOX v1alpha1 resource to v1alpha2 using typed conversion. Warnings are emitted immediately via warn.
func DetectResource ¶
func DetectResource(yamlDoc []byte) (ResourceID, ConverterType)
DetectResource partially unmarshals a YAML document to determine its resource type and returns the appropriate converter type.
func GraftComments ¶
GraftComments copies comments from src yaml.Node tree to dst yaml.Node tree, matching nodes by structure. Emits warnings immediately via warn for any comments in src that could not be grafted to dst.
func PruneDefaults ¶
PruneDefaults removes key-value pairs from the yaml.Node tree where the value matches a known default that should be omitted for the given resource kind.
func Restore ¶
func Restore(yamlText string, entries []SentinelEntry) string
Restore reverses sentinel replacement in raw YAML text. Used for array sentinels (structural text replacement) and as a fallback. Prefer RestoreNode for string/bool/int sentinels — it handles block scalar content correctly.
func RestoreNode ¶
func RestoreNode(node *yaml.Node, entries []SentinelEntry)
RestoreNode replaces sentinels in a yaml.Node tree by operating on each scalar's Value directly. This correctly handles block scalars where " chars are literal content — a plain substring replace leaves them intact. Array sentinels (which expand to sequence nodes) are left for Restore.
Types ¶
type ConverterType ¶
type ConverterType int
ConverterType indicates which conversion path to use.
const ( ConverterPassthrough ConverterType = iota ConverterCAPMOX ConverterCAPI )
Converter types for routing documents to the correct conversion pipeline.
type Options ¶
type Options struct {
Filename string // filename for warning context (default: "<stdin>")
Warn WarnFunc // callback for warnings; if nil, warnings are discarded
Indent int // output indentation; 0 = auto-detect from input (default 2)
}
Options configures the conversion.
type ResourceID ¶
ResourceID identifies a Kubernetes resource by apiVersion and kind.
type SentinelEntry ¶
type SentinelEntry struct {
Original string // "${NUM_SOCKETS:=2}"
Sentinel string // "99900001"
Type string // typeString, typeInt, typeBool, typeArray
}
SentinelEntry maps an envsubst expression to its sentinel replacement.
func ScanAndReplace ¶
func ScanAndReplace(yamlText string) (string, []SentinelEntry, error)
ScanAndReplace finds all ${...} expressions in yamlText, replaces them with type-appropriate sentinel values, and returns the modified text plus the mapping.
type WarnFunc ¶
type WarnFunc func(Warning)
WarnFunc is a callback invoked immediately when a warning is produced.
type Warning ¶
type Warning struct {
File string // filename or "<stdin>"
Line int // 1-based line number in input (0 if unknown)
Kind string // "lost-comment", "passthrough", "lossy-conversion"
Message string // human-readable description
Old string // quoted old field/value/comment (if applicable)
New string // quoted new field/value (if applicable)
}
Warning represents a structured warning emitted during conversion.