Skip to main content

Module merge

Module merge 

Source
Expand description

Port of internal/kubeconfig/merge.go: merges a cluster’s self-contained kubeconfig into a user’s existing kubeconfig, renaming the context, cluster and user entries to a stable name, and round-tripping everything else (comments included) untouched.

The Go implementation manipulates a gopkg.in/yaml.v3 node tree directly to preserve comments and formatting outside the entries it owns; serde_yaml::Value has no comment-preserving CST equivalent. This port instead operates on the destination as text lines: src (a driver-generated kubeconfig, never hand-edited, so nothing worth preserving) is fully parsed and re-rendered through serde_yaml, but dst (the user’s own kubeconfig, which may carry comments and keys Caproni does not model) is only ever spliced at the exact line ranges of the clusters/contexts/users list entries and the current-context scalar this module owns — every other byte of dst passes through untouched, including comments. This assumes each of those keys appears in the plain block form kubectl and every cluster driver in this codebase emits (key: on its own line, followed by - -prefixed block-sequence items); a flow-style clusters: [...] in a hand-edited kubeconfig would not be recognized. See PORT_NOTES.md.

Structs§

InstallEntries
Port of kubeconfig.installEntries: holds the three renamed list entries install merges into the destination, each already rendered as the lines of a single - -prefixed block-sequence item ready to splice into a clusters/contexts/users section.

Enums§

MergeError
Port of kubeconfig.ErrNoContext, ErrAmbiguousContext, ErrNotMapping.

Constants§

KEY_CLUSTERS
Port of the kubeconfig top-level and entry keys merge.go reads/writes.
KEY_CONTEXT
KEY_CONTEXTS
KEY_CONTEXT_CLUSTER
KEY_CONTEXT_USER
KEY_CURRENT_CTX
KEY_NAME
KEY_USERS

Functions§

install
Port of kubeconfig.Install. src is a self-contained kubeconfig as returned by a driver’s get_kubeconfig; dst may be empty. The context and the cluster/user it references are all renamed to name before merging, and existing entries of that name are replaced in place, so calling install repeatedly is idempotent and picks up a new server address after the cluster is recreated.
normalize
Port of kubeconfig.Normalize: returns src as a single-context kubeconfig whose context, cluster and user are all called name, selected as current-context.
uninstall
Port of kubeconfig.Uninstall: removes the context, cluster and user called name from dst, and clears current-context when it pointed at name. Removing an entry that is not there, or from an empty kubeconfig, is a no-op — this returns dst untouched (byte-for-byte) whenever nothing changed, rather than re-rendering (which would reindent every list in a kubectl-formatted file and count as a change).