convert

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package convert provides YAML conversion for CAPMOX v1alpha1→v1alpha2 and CAPI v1beta1→v1beta2 resources.

Index

Constants

View Source
const (
	KindProxmoxCluster         = "ProxmoxCluster"
	KindProxmoxMachine         = "ProxmoxMachine"
	KindProxmoxMachineTemplate = "ProxmoxMachineTemplate"
	KindProxmoxClusterTemplate = "ProxmoxClusterTemplate"
)

CAPMOX resource kind constants.

Variables

This section is empty.

Functions

func Convert

func Convert(input []byte, opts Options) ([]byte, error)

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

func GraftComments(src, dst *yaml.Node, filename string, warn WarnFunc)

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

func PruneDefaults(node *yaml.Node, resourceKind string)

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.

func StripStatus

func StripStatus(node *yaml.Node, filename string, warn WarnFunc)

StripStatus removes the top-level "status" key from a YAML document node. If the status block contains any non-zero scalar values, it is kept and a warning is emitted instead.

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

type ResourceID struct {
	APIVersion string `yaml:"apiVersion"`
	Kind       string `yaml:"kind"`
}

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.

func (Warning) String

func (w Warning) String() string

String formats the warning for stderr output.

Jump to

Keyboard shortcuts

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