meta

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package meta defines shared metadata keys and naming rules used across Cocoon controllers, webhooks, dashboards, and providers.

All identifiers live under two cocoonstack.io subdomains:

  • cocoonset.cocoonstack.io/* — CocoonSet CRD group, Pod selector labels, and the declarative annotation fields mirrored from a CocoonSet spec onto a managed Pod.
  • vm.cocoonstack.io/* — runtime state observed about the VM backing a Pod (id, name, ip, vnc-port, hibernate, fork-from).

Index

Constants

View Source
const (
	APIVersion    = "cocoonset.cocoonstack.io/v1"
	KindCocoonSet = "CocoonSet"

	TolerationKey = "virtual-kubelet.io/provider"

	LabelCocoonSet = "cocoonset.cocoonstack.io/name"
	LabelRole      = "cocoonset.cocoonstack.io/role"
	LabelSlot      = "cocoonset.cocoonstack.io/slot"

	// Cluster-wide selector for the cocoon node pool a workload
	// targets. Used by the webhook for affinity scoping and by
	// vk-cocoon to know which node the binary is registering as.
	LabelNodePool = "cocoonstack.io/pool"

	// DefaultNodePool is the cocoon-pool name used when a CocoonSet
	// (or pod) does not specify one explicitly.
	DefaultNodePool = "default"

	// LabelManagedBy is the standard k8s "app.kubernetes.io/managed-by"
	// key the cocoonstack components stamp on resources they own
	// (per-pool affinity ConfigMaps, etc.) so cleanup tooling can
	// recognize them.
	LabelManagedBy = "app.kubernetes.io/managed-by"

	AnnotationMode           = "cocoonset.cocoonstack.io/mode"
	AnnotationImage          = "cocoonset.cocoonstack.io/image"
	AnnotationStorage        = "cocoonset.cocoonstack.io/storage"
	AnnotationManaged        = "cocoonset.cocoonstack.io/managed"
	AnnotationOS             = "cocoonset.cocoonstack.io/os"
	AnnotationSnapshotPolicy = "cocoonset.cocoonstack.io/snapshot-policy"
	AnnotationNetwork        = "cocoonset.cocoonstack.io/network"

	AnnotationVMID      = "vm.cocoonstack.io/id"
	AnnotationVMName    = "vm.cocoonstack.io/name"
	AnnotationIP        = "vm.cocoonstack.io/ip"
	AnnotationVNCPort   = "vm.cocoonstack.io/vnc-port"
	AnnotationHibernate = "vm.cocoonstack.io/hibernate"
	AnnotationForkFrom  = "vm.cocoonstack.io/fork-from"

	RoleMain     = "main"
	RoleSubAgent = "sub-agent"
	RoleToolbox  = "toolbox"

	// Connection protocol identifiers returned by ConnectionType.
	// Sharing them as constants keeps callers (operator status,
	// glance, vk-cocoon) and the function in lock-step.
	ConnTypeVNC = "vnc"
	ConnTypeADB = "adb"
	ConnTypeRDP = "rdp"
	ConnTypeSSH = "ssh"
)
View Source
const (
	// HibernateSnapshotTag is the OCI tag vk-cocoon uses when pushing a
	// hibernation snapshot to epoch and the operator probes when
	// checking whether a hibernation has completed.
	HibernateSnapshotTag = "hibernate"
)

Variables

This section is empty.

Functions

func ConnectionType

func ConnectionType(osType string, hasVNCPort bool) string

ConnectionType returns the preferred connection protocol for the given OS and VNC availability.

func ExtractSlotFromVMName

func ExtractSlotFromVMName(vmName string) int

ExtractSlotFromVMName parses the trailing slot index from a VM name, returning -1 if absent.

func HasCocoonToleration

func HasCocoonToleration(tolerations []corev1.Toleration) bool

HasCocoonToleration reports whether any toleration matches the virtual-kubelet provider key.

func InferRoleFromVMName

func InferRoleFromVMName(vmName string) string

InferRoleFromVMName determines the role (main or sub-agent) based on the VM name slot.

func IsOwnedByCocoonSet added in v0.1.3

func IsOwnedByCocoonSet(ownerRefs []metav1.OwnerReference) bool

IsOwnedByCocoonSet reports whether any of the supplied owner references points at a CocoonSet. Webhook + operator + vk-cocoon all need this so it lives next to the rest of the meta helpers rather than each one re-implementing the loop.

func MainAgentVMName

func MainAgentVMName(vmName string) string

MainAgentVMName replaces the slot suffix with 0 to derive the main agent name. Names with no parseable slot suffix (e.g. pod-style names produced by VMNameForPod) are returned unchanged so a stray dash inside the name can never be mistaken for a slot separator.

func OwnerDeploymentName added in v0.1.2

func OwnerDeploymentName(ownerRefs []metav1.OwnerReference) string

OwnerDeploymentName extracts the deployment name from a ReplicaSet owner reference.

func VMNameForDeployment

func VMNameForDeployment(namespace, deployment string, slot int) string

VMNameForDeployment builds a deterministic VM name for a deployment slot.

func VMNameForPod

func VMNameForPod(namespace, podName string) string

VMNameForPod builds a deterministic VM name for a standalone pod.

Types

type HibernateState added in v0.1.3

type HibernateState bool

HibernateState is the typed contract for the hibernate annotation. Truthy means the operator wants vk-cocoon to snapshot and tear down the VM while keeping the backing pod alive.

func ReadHibernateState added in v0.1.3

func ReadHibernateState(pod *corev1.Pod) HibernateState

ReadHibernateState extracts the HibernateState from a pod's annotations. Anything other than the literal string annotationTrue reads as false.

func (HibernateState) Apply added in v0.1.3

func (s HibernateState) Apply(pod *corev1.Pod)

Apply writes the HibernateState into a pod's annotation map. False removes the annotation entirely (rather than writing "false") to keep the absence-as-default semantics that vk-cocoon expects.

type VMRuntime added in v0.1.3

type VMRuntime struct {
	VMID    string
	IP      string
	VNCPort int32
}

VMRuntime is the typed contract that vk-cocoon writes back onto a managed pod after VM creation or discovery.

func ParseVMRuntime added in v0.1.3

func ParseVMRuntime(pod *corev1.Pod) VMRuntime

ParseVMRuntime extracts a VMRuntime from a pod's annotations. Missing or malformed VNCPort comes back as 0; nil pods are tolerated.

func (VMRuntime) Apply added in v0.1.3

func (r VMRuntime) Apply(pod *corev1.Pod)

Apply writes the VMRuntime into a pod's annotation map. If the map is nil it allocates one. Zero VNCPort is treated as "not set" and is not emitted; pass an explicit value to overwrite.

type VMSpec added in v0.1.3

type VMSpec struct {
	VMName         string
	Image          string
	Mode           string
	OS             string
	Storage        string
	Network        string
	SnapshotPolicy string
	ForkFrom       string
	Managed        bool
}

VMSpec is the typed contract that the operator (and webhook) writes onto a managed pod for vk-cocoon to consume. Wrapping the loose annotation map in a struct lets every consumer share one source of truth and gives the compiler a chance to catch field renames.

func ParseVMSpec added in v0.1.3

func ParseVMSpec(pod *corev1.Pod) VMSpec

ParseVMSpec extracts a VMSpec from a pod's annotations. Missing fields come back as the zero value; nil pods are tolerated.

func (VMSpec) Apply added in v0.1.3

func (s VMSpec) Apply(pod *corev1.Pod)

Apply writes the VMSpec into a pod's annotation map. If the map is nil it allocates one. Empty fields are skipped so callers can layer partial updates without clobbering existing values.

Limitation: because empty values are skipped, Apply cannot *clear* a previously set field. To remove an annotation use delete(pod.Annotations, meta.Annotation*) directly. The Managed flag follows the same rule — Managed=false on a pod that already has the managed annotation will not remove it.

Jump to

Keyboard shortcuts

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