diff --git a/apis/v1/cocoonset_types.go b/apis/v1/cocoonset_types.go index 48709ff..d29d8bb 100644 --- a/apis/v1/cocoonset_types.go +++ b/apis/v1/cocoonset_types.go @@ -19,6 +19,12 @@ type CocoonSetSpec struct { // +kubebuilder:default=default NodePool string `json:"nodePool,omitempty"` + // NodeName pins the VM to a node (cross-node migrate). Empty = let the + // scheduler place it within NodePool and leave it alone; a value adds a + // hostname nodeAffinity so the pod lands there or stays Pending if it won't fit. + // +optional + NodeName string `json:"nodeName,omitempty"` + // +kubebuilder:validation:Required Agent AgentSpec `json:"agent"` diff --git a/apis/v1/crds/cocoonset.cocoonstack.io_cocoonsets.yaml b/apis/v1/crds/cocoonset.cocoonstack.io_cocoonsets.yaml index 037fba6..2c1f6a5 100644 --- a/apis/v1/crds/cocoonset.cocoonstack.io_cocoonsets.yaml +++ b/apis/v1/crds/cocoonset.cocoonstack.io_cocoonsets.yaml @@ -160,6 +160,7 @@ spec: - linux - windows - android + - macos type: string probePort: description: ProbePort overrides the default ICMP probe with a @@ -247,6 +248,12 @@ spec: required: - image type: object + nodeName: + description: |- + NodeName pins the VM to a node (cross-node migrate). Empty = let the + scheduler place it within NodePool and leave it alone; a value adds a + hostname nodeAffinity so the pod lands there or stays Pending if it won't fit. + type: string nodePool: default: default type: string @@ -322,6 +329,7 @@ spec: - linux - windows - android + - macos type: string probePort: description: ProbePort overrides the default ICMP probe with @@ -522,6 +530,7 @@ spec: - Scaling - Suspending - Suspended + - Migrating - Failed type: string readyAgents: diff --git a/apis/v1/enums.go b/apis/v1/enums.go index 5793d5a..0e7dac1 100644 --- a/apis/v1/enums.go +++ b/apis/v1/enums.go @@ -16,6 +16,7 @@ const ( OSLinux OSType = "linux" OSWindows OSType = "windows" OSAndroid OSType = "android" + OSMacos OSType = "macos" SnapshotPolicyAlways SnapshotPolicy = "always" SnapshotPolicyMainOnly SnapshotPolicy = "main-only" @@ -26,6 +27,7 @@ const ( CocoonSetPhaseScaling CocoonSetPhase = "Scaling" CocoonSetPhaseSuspending CocoonSetPhase = "Suspending" CocoonSetPhaseSuspended CocoonSetPhase = "Suspended" + CocoonSetPhaseMigrating CocoonSetPhase = "Migrating" CocoonSetPhaseFailed CocoonSetPhase = "Failed" ConnTypeSSH ConnType = "ssh" @@ -42,7 +44,7 @@ const ( var ( agentModeValid = []AgentMode{AgentModeClone, AgentModeRun} toolboxModeValid = []ToolboxMode{ToolboxModeRun, ToolboxModeClone, ToolboxModeStatic} - osTypeValid = []OSType{OSLinux, OSWindows, OSAndroid} + osTypeValid = []OSType{OSLinux, OSWindows, OSAndroid, OSMacos} snapshotPolicyValid = []SnapshotPolicy{SnapshotPolicyAlways, SnapshotPolicyMainOnly, SnapshotPolicyNever} connTypeValid = []ConnType{ConnTypeSSH, ConnTypeRDP, ConnTypeVNC, ConnTypeADB} backendValid = []Backend{BackendCloudHypervisor, BackendFirecracker} @@ -57,7 +59,7 @@ type AgentMode string type ToolboxMode string // OSType defines the guest operating system type. -// +kubebuilder:validation:Enum=linux;windows;android +// +kubebuilder:validation:Enum=linux;windows;android;macos type OSType string // SnapshotPolicy defines when VM snapshots are taken. @@ -65,7 +67,7 @@ type OSType string type SnapshotPolicy string // CocoonSetPhase represents the lifecycle phase of a CocoonSet. -// +kubebuilder:validation:Enum=Pending;Running;Scaling;Suspending;Suspended;Failed +// +kubebuilder:validation:Enum=Pending;Running;Scaling;Suspending;Suspended;Migrating;Failed type CocoonSetPhase string // ConnType is the connection protocol advertised for a VM. Empty diff --git a/meta/hibernate.go b/meta/hibernate.go index c73e314..8db1c2f 100644 --- a/meta/hibernate.go +++ b/meta/hibernate.go @@ -27,3 +27,12 @@ func ReadHibernateState(pod *corev1.Pod) HibernateState { } return HibernateState(pod.Annotations[AnnotationHibernate] == annotationTrue) } + +// ReadRestoreFromHibernate reports whether the pod is flagged to restore its VM +// from the :hibernate snapshot instead of cloning from the base image. +func ReadRestoreFromHibernate(pod *corev1.Pod) bool { + if pod == nil { + return false + } + return pod.Annotations[AnnotationRestoreFromHibernate] == annotationTrue +} diff --git a/meta/keys.go b/meta/keys.go index 42a4516..65cbb3e 100644 --- a/meta/keys.go +++ b/meta/keys.go @@ -50,6 +50,10 @@ const ( AnnotationVNCPort = "vm.cocoonstack.io/vnc-port" // AnnotationHibernate signals "hibernate this VM" when set to "true". AnnotationHibernate = "vm.cocoonstack.io/hibernate" + // AnnotationRestoreFromHibernate signals that a freshly created pod must + // restore its VM from the :hibernate snapshot (cross-node migration) instead + // of cloning from the base image. Written by the operator on the rebuilt pod. + AnnotationRestoreFromHibernate = "vm.cocoonstack.io/restore-from-hibernate" // AnnotationForkFrom names a VM to fork the new VM from. AnnotationForkFrom = "vm.cocoonstack.io/fork-from" // AnnotationCloneFromDir names a host directory to clone the VM image from (vk-cocoon-specific).