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§
- Install
Entries - Port of
kubeconfig.installEntries: holds the three renamed list entriesinstallmerges into the destination, each already rendered as the lines of a single--prefixed block-sequence item ready to splice into aclusters/contexts/userssection.
Enums§
- Merge
Error - Port of
kubeconfig.ErrNoContext,ErrAmbiguousContext,ErrNotMapping.
Constants§
- KEY_
CLUSTERS - Port of the kubeconfig top-level and entry keys
merge.goreads/writes. - KEY_
CONTEXT - KEY_
CONTEXTS - KEY_
CONTEXT_ CLUSTER - KEY_
CONTEXT_ USER - KEY_
CURRENT_ CTX - KEY_
NAME - KEY_
USERS
Functions§
- install
- Port of
kubeconfig.Install.srcis a self-contained kubeconfig as returned by a driver’sget_kubeconfig;dstmay be empty. The context and the cluster/user it references are all renamed tonamebefore merging, and existing entries of that name are replaced in place, so callinginstallrepeatedly is idempotent and picks up a new server address after the cluster is recreated. - normalize
- Port of
kubeconfig.Normalize: returnssrcas a single-context kubeconfig whose context, cluster and user are all calledname, selected ascurrent-context. - uninstall
- Port of
kubeconfig.Uninstall: removes the context, cluster and user callednamefromdst, and clearscurrent-contextwhen it pointed atname. Removing an entry that is not there, or from an empty kubeconfig, is a no-op — this returnsdstuntouched (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).