From 0020c58a46b3d702eb6317c2d43d13d5f8ea45f3 Mon Sep 17 00:00:00 2001
From: Philipp Matthes
Date: Tue, 17 Nov 2026 09:36:35 +0100
Subject: [PATCH 1/4] Refactor VM CRD conditions and spec
Signed-off-by: Philipp Matthes
---
api/v1alpha1/vm_types.go | 228 ++++++++++--------
api/v1alpha1/zz_generated.deepcopy.go | 9 +-
.../cobaltcore.cloud_virtualmachines.yaml | 77 ++----
internal/nova/controller.go | 6 +-
internal/nova/controller_test.go | 11 +-
internal/nova/conversion.go | 43 ++--
internal/nova/conversion_test.go | 20 +-
internal/nova/garbagecollector.go | 4 +-
internal/nova/garbagecollector_test.go | 6 +-
.../cortex-negative-observed-generation.yaml | 23 ++
.../crd/fixtures/valid/consumer-multiple.yaml | 4 +
11 files changed, 241 insertions(+), 190 deletions(-)
create mode 100644 test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
diff --git a/api/v1alpha1/vm_types.go b/api/v1alpha1/vm_types.go
index 980b73d..8057e17 100644
--- a/api/v1alpha1/vm_types.go
+++ b/api/v1alpha1/vm_types.go
@@ -21,13 +21,13 @@ const (
// Label keys set on VirtualMachine objects.
const (
- // LabelRegion is the cloud region. Immutable.
+ // LabelRegion is the OpenStack region within which this vm is hosted.
+ // Once set, this label is intended to stay stable over the entire lifetime.
LabelRegion = "cobaltcore.cloud/region"
- // LabelAZ is the availability zone. Immutable.
+ // LabelAZ is the availability zone within which this vm is hosted.
+ // Once set, this label is intended to stay stable over the entire lifetime.
LabelAZ = "cobaltcore.cloud/az"
- // LabelTargetHost is the host where the VM should be placed on (spec).
- LabelTargetHost = "cobaltcore.cloud/target-host"
// LabelHost is the host the VM is currently observed on (status).
LabelHost = "cobaltcore.cloud/host"
)
@@ -36,122 +36,140 @@ const (
type VMConditionType = string
const (
- // ConditionTypeScheduled is set by Cortex after each scheduling operation.
- // status=Unknown: scheduling in-flight.
- // status=True: scheduling succeeded, one or multiple candidates found.
- // status=False: scheduling failed, see reason and message.
- ConditionTypeScheduled VMConditionType = "Scheduled"
-
- // ConditionTypeRunning is set by the VM operator when the VM domain is executing on a host.
- // status=True: domain running, including during live migration or resize.
- // status=False: domain paused, shut off, crashed, or not found.
- // status=Unknown: exporter cannot reach the host.
+ // ConditionTypeRunning indicates if the virtual machine is observed to
+ // be running on its current host, according to authoritative datasources.
+ // - status=True: the vm is running.
+ // - status=False: the vm is not running. This can be the case if the vm is
+ // turned off, failed, or crashed, but it still exists in the system.
+ // See ConditionTypeDeleted for more details on the deletion state.
+ // - status=Unknown: there is a conflicting state between authoritative
+ // datasources — the operator cannot determine the running state reliably.
ConditionTypeRunning VMConditionType = "Running"
- // ConditionTypeMigrating is set by the VM operator during a live migration.
- // status=True: migration in progress or aborting.
- // status=False: migration completed, rolled back, or failed.
- // status=Unknown: VM visible on multiple hosts, state unclear.
+ // ConditionTypeDeleted indicates if the virtual machine has been deleted,
+ // i.e. it no longer runs AND it has been removed from the system.
+ // See ConditionTypeRunning.
+ // - status=True: the vm has been deleted from all datasources and can
+ // be pruned from k8s.
+ // - status=False: the vm still exists, or deletion failed.
+ // - status=Unknown: it is unclear whether the VM has been fully deleted
+ // because there are conflicting observations from authoritative
+ // datasources. This may just indicate the deletion is still ongoing.
+ ConditionTypeDeleted VMConditionType = "Deleted"
+
+ // ConditionTypeMigrating indicates if the virtual machine is currently
+ // undergoing a migration: a live migration or a cold-migration such as
+ // an evacuation.
+ // - status=True: the vm is currently undergoing a migration. See the
+ // reason and message for details.
+ // - status=False: the vm is not migrating, either because it was never
+ // migrated or a previous migration has completed. See the reason.
+ // - status=Unknown: it is unclear whether the VM is currently undergoing a
+ // migration because there are conflicting observations from
+ // authoritative datasources.
ConditionTypeMigrating VMConditionType = "Migrating"
- // ConditionTypeResizing is set by the VM operator during a resize operation.
- // status=True: resize in progress or being reverted.
- // status=False: resize completed, reverted, or failed.
- // status=Unknown: resize state unclear.
+ // ConditionTypeResizing indicates if the virtual machine is currently
+ // changing its allocated resources (CPU, memory, etc.), known as a resize
+ // operation.
+ // - status=True: the vm is currently undergoing a resize operation.
+ // - status=False: the vm is not currently undergoing a resize operation,
+ // either because it completed, was reverted, or failed.
+ // - status=Unknown: it is unclear whether the VM is currently undergoing a
+ // resize operation because there are conflicting observations from
+ // authoritative datasources.
ConditionTypeResizing VMConditionType = "Resizing"
- // ConditionTypeNovaInSync is set by the VM operator to record if the libvirt-observed state is consistent with what Nova reports.
- // status=True: host and state consistent.
- // status=False: mismatch detected — see reason and message.
- // status=Unknown: not yet checked.
- ConditionTypeNovaInSync VMConditionType = "NovaInSync"
-
- // ConditionTypeNovaSynced is set by the Nova sync controller to record the
- // outcome of reflecting Nova's view of the server onto this resource.
+ // ConditionTypeNovaSynced indicates if the resource reflects the latest
+ // successful Nova fetch.
// status=True: the resource reflects the latest successful Nova fetch.
// status=False: the most recent sync failed — see reason and message.
// status=Unknown: not yet synced.
ConditionTypeNovaSynced VMConditionType = "NovaSynced"
- // ConditionTypeTerminating is set by the VM operator when deletion is detected on either side.
- // Absent when the VM is not being deleted.
- // status=False: deletion observed on one side only — possible false positive or waiting for the other side to catch up.
- // status=True: both libvirt and Nova agree the VM is gone; CRD is held by finalizers pending cleanup.
- ConditionTypeTerminating VMConditionType = "Terminating"
+ // ConditionTypeLibvirtSynced indicates if the resource reflects the latest
+ // successful Libvirt state.
+ // status=True: the resource reflects the latest successful Libvirt fetch.
+ // status=False: the most recent sync failed — see reason and message.
+ // status=Unknown: not yet synced.
+ ConditionTypeLibvirtSynced VMConditionType = "LibvirtSynced"
)
// Reasons for ConditionTypeRunning.
const (
- ConditionReasonRunningShutoff = "Shutoff"
- ConditionReasonRunningCrashed = "Crashed"
- ConditionReasonRunningPaused = "Paused"
+ // ConditionReasonRunningOK is set when the VM is running normally.
+ ConditionReasonRunningOK = "OK"
+ // ConditionReasonRunningShutoff is set when the VM is in the shutoff state.
+ ConditionReasonRunningShutoff = "Shutoff"
+ // ConditionReasonRunningCrashed is set when the VM has crashed.
+ ConditionReasonRunningCrashed = "Crashed"
+ // ConditionReasonRunningPaused is set when the VM is paused.
+ ConditionReasonRunningPaused = "Paused"
+ // ConditionReasonRunningNotFound is set when the VM cannot be found.
ConditionReasonRunningNotFound = "NotFound"
)
+// Reasons for ConditionTypeDeleted.
+const (
+ // ConditionReasonDeletedReady is set when the VM has been deleted
+ // normally.
+ ConditionReasonDeletedReady = "Ready"
+ // ConditionReasonDeletedLibvirtGone is set when libvirt no longer
+ // observes the VM but Nova still reports it as running.
+ ConditionReasonDeletedLibvirtGone = "LibvirtGone"
+ // ConditionReasonDeletedNovaGone is set when Nova reports the VM
+ // as deleted but libvirt still observes it.
+ ConditionReasonDeletedNovaGone = "NovaGone"
+ // ConditionReasonDeletedNovaError is set when the VM deletion has
+ // failed due to a Nova error.
+ ConditionReasonDeletedNovaError = "NovaError"
+)
+
// Reasons for ConditionTypeMigrating.
const (
- ConditionReasonMigratingOngoing = "Ongoing"
- ConditionReasonMigratingAborting = "Aborting"
- ConditionReasonMigratingCompleted = "Completed"
- ConditionReasonMigratingRolledBack = "RolledBack"
- ConditionReasonMigratingFailed = "Failed"
+ // ConditionReasonMigratingLiveInProgress is set when the VM is being
+ // live migrated.
+ ConditionReasonMigratingLiveInProgress = "LiveInProgress"
+ // ConditionReasonMigratingColdInProgress is set when the VM is being
+ // cold migrated.
+ ConditionReasonMigratingColdInProgress = "ColdInProgress"
+ // ConditionReasonMigratingNovaError is set when the VM migration has
+ // failed due to a Nova error.
+ ConditionReasonMigratingNovaError = "NovaError"
)
// Reasons for ConditionTypeResizing.
const (
- ConditionReasonResizingOngoing = "Ongoing"
- ConditionReasonResizingReverting = "Reverting"
- ConditionReasonResizingCompleted = "Completed"
- ConditionReasonResizingReverted = "Reverted"
- ConditionReasonResizingFailed = "Failed"
+ // ConditionReasonResizingInProgress is set when the VM is being resized
+ // normally.
+ ConditionReasonResizingInProgress = "InProgress"
+ // ConditionReasonResizingNovaError is set when the VM resize has
+ // failed due to a Nova error.
+ ConditionReasonResizingNovaError = "NovaError"
)
-// Reasons for ConditionTypeNovaInSync.
+// Reasons for ConditionTypeLibvirtSynced.
const (
- ConditionReasonNovaInSyncHostMismatch = "HostMismatch"
- ConditionReasonNovaInSyncStateMismatch = "StateMismatch"
- ConditionReasonNovaInSyncUnreachable = "NovaUnreachable"
+ // ConditionReasonLibvirtSyncedOK is set when the VM's libvirt state is
+ // successfully synced.
+ ConditionReasonLibvirtSyncedOK = "OK"
+ // ConditionReasonLibvirtSyncedFailed is set when the VM's libvirt state
+ // failed to sync due to an error.
+ ConditionReasonLibvirtSyncedFailed = "Failed"
)
// Reasons for ConditionTypeNovaSynced.
const (
- // ConditionReasonNovaSyncedUpToDate is set when the resource was
- // successfully reconciled against Nova's current view of the server,
- // including when Nova reports the server as gone.
- ConditionReasonNovaSyncedUpToDate = "UpToDate"
- // ConditionReasonNovaSyncedGone is set when a sync succeeded but Nova no
- // longer knows the server. The last-known Nova-derived fields are retained on
- // the resource; this reason is the sole record that the server is gone.
+ // ConditionReasonNovaSyncedOK is set when the VM's Nova state is
+ // successfully synced.
+ ConditionReasonNovaSyncedOK = "OK"
+ // ConditionReasonNovaSyncedGone is set when a successful Nova lookup confirms
+ // the server is absent. Last-known Nova fields are retained; this does not
+ // imply that libvirt has also confirmed deletion.
ConditionReasonNovaSyncedGone = "ServerGone"
- // ConditionReasonNovaSyncedError is set when the sync failed, e.g. Nova was
- // unreachable.
- ConditionReasonNovaSyncedError = "SyncError"
-)
-
-// Reasons for ConditionTypeTerminating.
-const (
- // ConditionReasonTerminatingLibvirtGone is set when libvirt no longer observes the VM but Nova still reports it as running.
- ConditionReasonTerminatingLibvirtGone = "LibvirtGone"
- // ConditionReasonTerminatingNovaGone is set when Nova reports the VM as deleted but libvirt still observes it.
- ConditionReasonTerminatingNovaGone = "NovaGone"
- // ConditionReasonTerminatingConfirmed is set when both libvirt and Nova agree the VM is gone.
- ConditionReasonTerminatingConfirmed = "Confirmed"
-)
-
-// Reasons for ConditionTypeScheduled. Note that these are only the explicitly
-// listed reasons, and other reasons may be provided by the condition writer.
-const (
- // Operation type reasons — set on both success and failure of a scheduling call.
- ConditionReasonScheduledInitialPlacement = "InitialPlacement"
- ConditionReasonScheduledLiveMigration = "LiveMigration"
- ConditionReasonScheduledEvacuation = "Evacuation"
- ConditionReasonScheduledResize = "Resize"
- ConditionReasonScheduledRebuild = "Rebuild"
-
- // Failure reasons — set on status=False.
- ConditionReasonScheduledNoHostFound = "NoHostFound"
- ConditionReasonScheduledTimeout = "Timeout"
- ConditionReasonScheduledError = "Error"
+ // ConditionReasonNovaSyncedFailed is set when the VM's Nova state
+ // failed to sync due to an error.
+ ConditionReasonNovaSyncedFailed = "Failed"
)
// HostRef is a reference to a v1.Hypervisor.
@@ -173,7 +191,7 @@ const (
// Region, AZ, and Resources are populated at creation time either by the Cortex
// placement API (at scheduling time) or by the vm-operator's Nova sync
// controller (when it adopts a pre-existing Nova server that has no CRD yet).
-// Both write the same create-time values; the fields are immutable thereafter.
+// Region and AZ are immutable thereafter; Resources may change on resize.
type VMSpec struct {
// Region is the cloud region this VM is placed in.
// Set once at creation by the Cortex placement API or the vm-operator's
@@ -189,10 +207,6 @@ type VMSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="az is immutable"
AZ string `json:"az"`
- // TargetHost is a reference to the host where this VM should be placed.
- // +kubebuilder:validation:Optional
- TargetHost *HostRef `json:"targetHost,omitempty"`
-
// HypervisorType is the hypervisor type of the host where this VM should be placed.
// +kubebuilder:validation:Optional
HypervisorType *HypervisorType `json:"hypervisorType,omitempty"`
@@ -224,7 +238,7 @@ type NovaSpec struct {
// +kubebuilder:validation:Optional
CreatedAt *metav1.Time `json:"createdAt,omitempty"`
- // Ownership identifies the OpenStack project and user owning this VM.
+ // Ownership identifies the OpenStack project, user, and domain owning this VM.
// +kubebuilder:validation:Required
Ownership Ownership `json:"ownership"`
@@ -242,7 +256,7 @@ type NovaSpec struct {
InstanceGroup *InstanceGroup `json:"instanceGroup,omitempty"`
}
-// Ownership identifies the OpenStack project and user that own a VM.
+// Ownership identifies the OpenStack project, user, and domain that own a VM.
type Ownership struct {
// Project is the OpenStack project (tenant) UUID.
// +kubebuilder:validation:Required
@@ -251,6 +265,10 @@ type Ownership struct {
// User is the OpenStack user UUID that created the VM.
// +kubebuilder:validation:Optional
User string `json:"user,omitempty"`
+
+ // Domain is the OpenStack domain UUID that owns the project, when known.
+ // +kubebuilder:validation:Optional
+ Domain string `json:"domain,omitempty"`
}
// Flavor describes the Nova flavor of a VM.
@@ -368,6 +386,15 @@ type CortexSpec struct {
// this information into the CortexSpec.
// +kubebuilder:validation:Optional
Intent string `json:"intent,omitempty"`
+
+ // LastTransitionTime is the timestamp of the last transition of the VM's intent.
+ // +kubebuilder:validation:Optional
+ LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
+
+ // ObservedGeneration is the last generation observed by cortex for this VM.
+ // +kubebuilder:validation:Optional
+ // +kubebuilder:validation:Minimum=0
+ ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}
// VMStatus defines the observed state of a VirtualMachine.
@@ -392,7 +419,13 @@ type VMStatus struct {
// +kubebuilder:validation:Optional
Libvirt *LibvirtStatus `json:"libvirt,omitempty"`
- // Conditions holds standard Kubernetes conditions for this VM.
+ // Conditions are exclusively reconciled and owned by the vm operator.
+ // They reflect the current state of the VM as observed by the operator.
+ //
+ // If no conditions are set, the operator has not yet recorded observations.
+ // This includes resources just scheduled for the first time by Cortex.
+ // See the cortex spec for scheduling details.
+ //
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:Optional
@@ -431,13 +464,12 @@ type LibvirtHostInfo struct{}
// +kubebuilder:resource:scope=Cluster,shortName=vm
// +kubebuilder:selectablefield:JSONPath=".spec.region"
// +kubebuilder:selectablefield:JSONPath=".spec.az"
-// +kubebuilder:selectablefield:JSONPath=".spec.targetHost.name"
// +kubebuilder:selectablefield:JSONPath=".status.host.name"
// Default columns. The implicit NAME column already holds the Nova instance UUID.
// +kubebuilder:printcolumn:JSONPath=".spec.az",name="AZ",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.resources.cpu",name="CPU",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.resources.memory",name="Memory",type="string"
-// +kubebuilder:printcolumn:JSONPath=".spec.targetHost.name",name="TargetHost",type="string"
+// +kubebuilder:printcolumn:JSONPath=".metadata.labels.cobaltcore\\.cloud/target-host",name="TargetHost",type="string"
// +kubebuilder:printcolumn:JSONPath=".status.host.name",name="ActualHost",type="string"
// Wide-only columns (priority=1).
// +kubebuilder:printcolumn:JSONPath=".status.nova.host",name="NovaHost",type="string",priority=1
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index ff0cc39..a2f9515 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -29,6 +29,10 @@ func (in *CortexSpec) DeepCopyInto(out *CortexSpec) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
+ if in.LastTransitionTime != nil {
+ in, out := &in.LastTransitionTime, &out.LastTransitionTime
+ *out = (*in).DeepCopy()
+ }
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CortexSpec.
@@ -223,11 +227,6 @@ func (in *PlacementConsumer) DeepCopy() *PlacementConsumer {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *VMSpec) DeepCopyInto(out *VMSpec) {
*out = *in
- if in.TargetHost != nil {
- in, out := &in.TargetHost, &out.TargetHost
- *out = new(HostRef)
- **out = **in
- }
if in.HypervisorType != nil {
in, out := &in.HypervisorType, &out.HypervisorType
*out = new(HypervisorType)
diff --git a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
index 2e29dac..dec85ea 100644
--- a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
+++ b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
@@ -26,7 +26,7 @@ spec:
- jsonPath: .spec.resources.memory
name: Memory
type: string
- - jsonPath: .spec.targetHost.name
+ - jsonPath: .metadata.labels.cobaltcore\.cloud/target-host
name: TargetHost
type: string
- jsonPath: .status.host.name
@@ -89,7 +89,7 @@ spec:
Region, AZ, and Resources are populated at creation time either by the Cortex
placement API (at scheduling time) or by the vm-operator's Nova sync
controller (when it adopts a pre-existing Nova server that has no CRD yet).
- Both write the same create-time values; the fields are immutable thereafter.
+ Region and AZ are immutable thereafter; Resources may change on resize.
properties:
az:
description: |-
@@ -220,6 +220,17 @@ spec:
persisted nowhere inside the Nova database, so Cortex propagates
this information into the CortexSpec.
type: string
+ lastTransitionTime:
+ description: LastTransitionTime is the timestamp of the last transition
+ of the VM's intent.
+ format: date-time
+ type: string
+ observedGeneration:
+ description: ObservedGeneration is the last generation observed
+ by cortex for this VM.
+ format: int64
+ minimum: 0
+ type: integer
type: object
hypervisorType:
description: HypervisorType is the hypervisor type of the host where
@@ -287,9 +298,13 @@ spec:
name, used for logging and debugging only.
type: string
ownership:
- description: Ownership identifies the OpenStack project and user
- owning this VM.
+ description: Ownership identifies the OpenStack project, user,
+ and domain owning this VM.
properties:
+ domain:
+ description: Domain is the OpenStack domain UUID that owns
+ the project, when known.
+ type: string
project:
description: Project is the OpenStack project (tenant) UUID.
type: string
@@ -330,50 +345,6 @@ spec:
x-kubernetes-validations:
- message: both cpu and memory must be specified
rule: '"cpu" in self && "memory" in self'
- targetHost:
- description: TargetHost is a reference to the host where this VM should
- be placed.
- properties:
- apiVersion:
- description: API version of the referent.
- type: string
- fieldPath:
- description: |-
- If referring to a piece of an object instead of an entire object, this string
- should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
- For example, if the object reference is to a container within a pod, this would take on a value like:
- "spec.containers{name}" (where "name" refers to the name of the container that triggered
- the event) or if no container name is specified "spec.containers[2]" (container with
- index 2 in this pod). This syntax is chosen only to have some well-defined way of
- referencing a part of an object.
- type: string
- kind:
- description: |-
- Kind of the referent.
- More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
- type: string
- name:
- description: |-
- Name of the referent.
- More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
- type: string
- namespace:
- description: |-
- Namespace of the referent.
- More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
- type: string
- resourceVersion:
- description: |-
- Specific resourceVersion to which this reference is made, if any.
- More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
- type: string
- uid:
- description: |-
- UID of the referent.
- More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
- type: string
- type: object
- x-kubernetes-map-type: atomic
required:
- az
- nova
@@ -384,8 +355,13 @@ spec:
description: VMStatus defines the observed state of a VirtualMachine.
properties:
conditions:
- description: Conditions holds standard Kubernetes conditions for this
- VM.
+ description: |-
+ Conditions are exclusively reconciled and owned by the vm operator.
+ They reflect the current state of the VM as observed by the operator.
+
+ If no conditions are set, the operator has not yet recorded observations.
+ This includes resources just scheduled for the first time by Cortex.
+ See the cortex spec for scheduling details.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
@@ -533,7 +509,6 @@ spec:
selectableFields:
- jsonPath: .spec.region
- jsonPath: .spec.az
- - jsonPath: .spec.targetHost.name
- jsonPath: .status.host.name
served: true
storage: true
diff --git a/internal/nova/controller.go b/internal/nova/controller.go
index 4077dd6..01ca02c 100644
--- a/internal/nova/controller.go
+++ b/internal/nova/controller.go
@@ -142,7 +142,7 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
meta.SetStatusCondition(&vm.Status.Conditions, metav1.Condition{
Type: v1alpha1.ConditionTypeNovaSynced,
Status: metav1.ConditionFalse,
- Reason: v1alpha1.ConditionReasonNovaSyncedError,
+ Reason: v1alpha1.ConditionReasonNovaSyncedFailed,
Message: err.Error(),
})
if perr := c.Status().Patch(ctx, &vm, client.MergeFrom(base)); perr != nil {
@@ -227,7 +227,7 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
meta.SetStatusCondition(&created.Status.Conditions, metav1.Condition{
Type: v1alpha1.ConditionTypeNovaSynced,
Status: metav1.ConditionTrue,
- Reason: v1alpha1.ConditionReasonNovaSyncedUpToDate,
+ Reason: v1alpha1.ConditionReasonNovaSyncedOK,
Message: "resource created from nova state",
})
if err := c.Status().Update(ctx, created); err != nil {
@@ -246,7 +246,7 @@ func (c *Controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
// NovaSynced condition, so operators can still see what the VM was). LastSyncTime,
// conditions and Status.Host are preserved either way.
base := vm.DeepCopy()
- reason, message := v1alpha1.ConditionReasonNovaSyncedUpToDate, "resource reflects the current nova state"
+ reason, message := v1alpha1.ConditionReasonNovaSyncedOK, "resource reflects the current nova state"
outcome := outcomeSynced
var requeueAfter time.Duration
var changed bool
diff --git a/internal/nova/controller_test.go b/internal/nova/controller_test.go
index 8382921..2918244 100644
--- a/internal/nova/controller_test.go
+++ b/internal/nova/controller_test.go
@@ -279,7 +279,7 @@ func TestController_Reconcile_usesServerGet(t *testing.T) {
if got.Status.Nova == nil || got.Status.Nova.Status != "ACTIVE" || got.Status.Nova.Host != "compute-1" {
t.Errorf("status.nova = %+v, want ACTIVE on compute-1", got.Status.Nova)
}
- assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedUpToDate)
+ assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedOK)
}
func TestController_Reconcile_syncsExistingVM(t *testing.T) {
@@ -317,7 +317,7 @@ func TestController_Reconcile_syncsExistingVM(t *testing.T) {
if got.Status.Nova.LastSyncTime == nil {
t.Error("expected LastSyncTime to be stamped on sync")
}
- assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedUpToDate)
+ assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedOK)
}
// TestController_Reconcile_preservesCortexSpec verifies the full update path (the
@@ -429,9 +429,6 @@ func TestController_Reconcile_createsMissingVM(t *testing.T) {
if got.Spec.HypervisorType == nil || *got.Spec.HypervisorType != v1alpha1.HypervisorTypeQEMU {
t.Errorf("spec.hypervisorType = %v, want QEMU", got.Spec.HypervisorType)
}
- if got.Spec.TargetHost == nil || got.Spec.TargetHost.Name != "compute-1" {
- t.Errorf("spec.targetHost = %+v, want name compute-1", got.Spec.TargetHost)
- }
cpu := got.Spec.Resources[v1alpha1.ResourceCPU]
if cpu.Value() != 4 {
t.Errorf("spec.resources[cpu] = %s, want 4", cpu.String())
@@ -447,7 +444,7 @@ func TestController_Reconcile_createsMissingVM(t *testing.T) {
if got.Spec.Nova.Flavor.ExtraSpecs[hypervisorTypeExtraSpec] != "qemu" {
t.Errorf("spec.nova.flavor.extraSpecs = %+v, want hypervisor type qemu", got.Spec.Nova.Flavor.ExtraSpecs)
}
- assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedUpToDate)
+ assertSyncedCondition(t, &got, metav1.ConditionTrue, v1alpha1.ConditionReasonNovaSyncedOK)
}
func TestController_Reconcile_skipsCreateWithoutAZ(t *testing.T) {
@@ -655,7 +652,7 @@ func TestController_Reconcile_recordsFetchFailure(t *testing.T) {
}
got := getVM(t, c)
- assertSyncedCondition(t, &got, metav1.ConditionFalse, v1alpha1.ConditionReasonNovaSyncedError)
+ assertSyncedCondition(t, &got, metav1.ConditionFalse, v1alpha1.ConditionReasonNovaSyncedFailed)
}
func TestController_Reconcile_bothMissingIsNoop(t *testing.T) {
diff --git a/internal/nova/conversion.go b/internal/nova/conversion.go
index 1c056f7..c191ff3 100644
--- a/internal/nova/conversion.go
+++ b/internal/nova/conversion.go
@@ -13,7 +13,6 @@ import (
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/runtime/schema"
v1alpha1 "github.com/cobaltcore-dev/vm-operator/api/v1alpha1"
)
@@ -72,32 +71,36 @@ func ConvertToVirtualMachine(server *servers.Server, flavor *flavors.Flavor, reg
ObjectMeta: metav1.ObjectMeta{
Name: server.ID,
Labels: map[string]string{
- v1alpha1.LabelRegion: region,
- v1alpha1.LabelAZ: server.AvailabilityZone,
- v1alpha1.LabelTargetHost: server.Host,
+ v1alpha1.LabelRegion: region,
+ v1alpha1.LabelAZ: server.AvailabilityZone,
},
},
Spec: v1alpha1.VMSpec{
AZ: server.AvailabilityZone,
Region: region,
HypervisorType: &hypervisorType,
- TargetHost: &v1alpha1.HostRef{
- // So we avoid the import of the Hypervisor operator:
- APIVersion: schema.GroupVersion{Group: "kvm.cloud.sap", Version: "v1"}.String(),
- Kind: "Hypervisor",
- Name: server.Host,
- },
Resources: map[v1alpha1.ResourceName]resource.Quantity{
- v1alpha1.ResourceCPU: *resource.NewQuantity(int64(flavor.VCPUs), resource.DecimalSI),
+ v1alpha1.ResourceCPU: *resource.
+ NewQuantity(int64(flavor.VCPUs), resource.DecimalSI),
// RAM is reported in MB; ResourceMemory is bytes.
- v1alpha1.ResourceMemory: *resource.NewQuantity(int64(flavor.RAM)*1024*1024, resource.BinarySI),
+ v1alpha1.ResourceMemory: *resource.
+ NewQuantity(int64(flavor.RAM)*1024*1024, resource.BinarySI),
},
Nova: v1alpha1.NovaSpec{
InstanceName: server.InstanceName,
CreatedAt: createdAt,
- Ownership: v1alpha1.Ownership{Project: server.TenantID, User: server.UserID},
- Flavor: v1alpha1.Flavor{Name: flavor.Name, FlavorID: flavor.ID, ExtraSpecs: flavor.ExtraSpecs},
- Image: v1alpha1.Image{UUID: imageUUID},
+ Ownership: v1alpha1.Ownership{
+ Project: server.TenantID,
+ User: server.UserID,
+ // Note: the domain information is not available on nova servers,
+ // it needs to be populated through keystone.
+ },
+ Flavor: v1alpha1.Flavor{
+ Name: flavor.Name,
+ FlavorID: flavor.ID,
+ ExtraSpecs: flavor.ExtraSpecs,
+ },
+ Image: v1alpha1.Image{UUID: imageUUID},
},
},
Status: v1alpha1.VMStatus{
@@ -110,12 +113,15 @@ func ConvertToVirtualMachine(server *servers.Server, flavor *flavors.Flavor, reg
// HasChanged reports whether applying this conversion to vm would change any
// sync-owned field — i.e. vm is out of sync. It compares Spec.Nova (excluding
-// Flavor, which never drives a sync on its own) and Status.Nova.Status, ignoring
+// Flavor, which never drives a sync on its own, and Ownership.Domain, which Nova
+// does not expose) and Status.Nova.Status, ignoring
// LastSyncTime, conditions and Status.Host.
func (c ConvertedVirtualMachine) HasChanged(vm *v1alpha1.VirtualMachine) bool {
want := c.Spec.Nova
got := vm.Spec.Nova
want.Flavor, got.Flavor = v1alpha1.Flavor{}, v1alpha1.Flavor{}
+ // Nova does not expose the project's domain; it must not drive a sync.
+ want.Ownership.Domain, got.Ownership.Domain = "", ""
// A nil Status.Nova compares as empty so a never-synced resource is clean.
var gotStatus, gotHost string
if vm.Status.Nova != nil {
@@ -126,7 +132,8 @@ func (c ConvertedVirtualMachine) HasChanged(vm *v1alpha1.VirtualMachine) bool {
}
// PatchInto applies the sync-owned fields (Spec.Nova and Status.Nova) onto vm,
-// leaving the immutable spec, conditions, Status.Host and LastSyncTime untouched.
+// leaving Ownership.Domain, the immutable spec, conditions, Status.Host and
+// LastSyncTime untouched.
//
// It writes only Spec.Nova and Status.Nova, so the Cortex subspec (Spec.Cortex,
// owned by the Cortex placement API) is deliberately left as-is: the Nova sync
@@ -136,7 +143,9 @@ func (c ConvertedVirtualMachine) PatchInto(vm *v1alpha1.VirtualMachine) {
if vm.Status.Nova != nil {
lastSync = vm.Status.Nova.LastSyncTime // carried forward across syncs.
}
+ domain := vm.Spec.Nova.Ownership.Domain
vm.Spec.Nova = c.Spec.Nova
+ vm.Spec.Nova.Ownership.Domain = domain
vm.Status.Nova = &v1alpha1.NovaStatus{
Status: c.Status.Nova.Status,
Host: c.Status.Nova.Host,
diff --git a/internal/nova/conversion_test.go b/internal/nova/conversion_test.go
index 2ab8cf8..fbdfd80 100644
--- a/internal/nova/conversion_test.go
+++ b/internal/nova/conversion_test.go
@@ -93,11 +93,26 @@ func TestPatchInto_preservesLastSyncTime(t *testing.T) {
}
}
+func TestPatchInto_preservesDomain(t *testing.T) {
+ vm := &v1alpha1.VirtualMachine{}
+ vm.Spec.Nova.Ownership.Domain = "domain-uuid"
+ conv := mustConvert(t, fullServer(), qemuFlavor("flavor-uuid", 1, 1))
+ conv.PatchInto(vm)
+ if vm.Spec.Nova.Ownership.Domain != "domain-uuid" {
+ t.Errorf("domain = %q, want domain-uuid", vm.Spec.Nova.Ownership.Domain)
+ }
+ if conv.HasChanged(vm) {
+ t.Error("a domain unknown to Nova must not trigger repeated syncs")
+ }
+}
+
// TestPatchInto_preservesCortex locks in that the Nova sync never clobbers the
// Cortex subspec, which the Cortex placement API owns.
func TestPatchInto_preservesCortex(t *testing.T) {
cortex := &v1alpha1.CortexSpec{
- HostCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-1"}},
+ HostCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-1"}},
+ LastTransitionTime: new(metav1.Now()),
+ ObservedGeneration: 3,
}
vm := &v1alpha1.VirtualMachine{ObjectMeta: metav1.ObjectMeta{Name: "a"}}
vm.Spec.Cortex = cortex
@@ -152,9 +167,6 @@ func TestConvertToVirtualMachine_setsNameAndImmutableSpec(t *testing.T) {
if vm.Spec.HypervisorType == nil || *vm.Spec.HypervisorType != v1alpha1.HypervisorTypeQEMU {
t.Errorf("hypervisorType = %v, want QEMU", vm.Spec.HypervisorType)
}
- if vm.Spec.TargetHost == nil || vm.Spec.TargetHost.Name != "compute-1" {
- t.Errorf("targetHost = %+v", vm.Spec.TargetHost)
- }
// The nova host goes to Status.Nova.Host; Status.Host (runtime host) is owned elsewhere.
if vm.Status.Nova == nil || vm.Status.Nova.Host != "compute-1" {
t.Errorf("status.nova.host = %+v, want compute-1", vm.Status.Nova)
diff --git a/internal/nova/garbagecollector.go b/internal/nova/garbagecollector.go
index 447eb98..1a99306 100644
--- a/internal/nova/garbagecollector.go
+++ b/internal/nova/garbagecollector.go
@@ -188,7 +188,7 @@ func (c *GarbageCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctr
// scheduled deletion. Dispatch on the NovaSynced condition, which records the
// outcome of the last sync attempt:
//
- // - False (SyncError): the last fetch failed (Nova unreachable, 401/503,
+ // - False (Failed): the last fetch failed (Nova unreachable, 401/503,
// transport error), so we do NOT know Nova's current view — the server may
// well still exist. Never prune; leave it for the sync controller to retry.
// - True / ServerGone: a sync succeeded and Nova no longer knows the server.
@@ -246,7 +246,7 @@ func (c *GarbageCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctr
// is gone — it may exist while the sync is pending. Never prune; requeue on the
// OrphanTTL clock so it remains a re-evaluated candidate until the sync
// controller records an outcome (ServerGone, which authorises the prune above,
- // or SyncError / UpToDate, both handled earlier).
+ // or Failed / OK, both handled earlier).
notYetSynced := synced == nil && (vm.Status.Nova == nil || vm.Status.Nova.Status == "")
if notYetSynced {
age := now.Sub(vm.CreationTimestamp.Time)
diff --git a/internal/nova/garbagecollector_test.go b/internal/nova/garbagecollector_test.go
index 0efb3ef..ccf0a73 100644
--- a/internal/nova/garbagecollector_test.go
+++ b/internal/nova/garbagecollector_test.go
@@ -239,7 +239,7 @@ func TestGarbageCollector_keepsGoneServerWithinOrphanTTL(t *testing.T) {
}
}
-// A VM whose last sync FAILED (NovaSynced=False/SyncError) is never pruned,
+// A VM whose last sync FAILED (NovaSynced=False/Failed) is never pruned,
// regardless of age: Nova's view is unknown, so the server may still exist. This
// is the API-outage safety property — a 401/503 must not cascade into deletion.
func TestGarbageCollector_neverPrunesWhenSyncFailing(t *testing.T) {
@@ -252,7 +252,7 @@ func TestGarbageCollector_neverPrunesWhenSyncFailing(t *testing.T) {
meta.SetStatusCondition(&vm.Status.Conditions, metav1.Condition{
Type: v1alpha1.ConditionTypeNovaSynced,
Status: metav1.ConditionFalse,
- Reason: v1alpha1.ConditionReasonNovaSyncedError,
+ Reason: v1alpha1.ConditionReasonNovaSyncedFailed,
Message: "nova unreachable",
})
c := &GarbageCollector{Client: newTestClient(t, scheme, vm), Scheme: scheme}
@@ -371,7 +371,7 @@ func TestGarbageCollector_watchPredicate_ignoresDeletionTimeWrites(t *testing.T)
meta.SetStatusCondition(&vm.Status.Conditions, metav1.Condition{
Type: v1alpha1.ConditionTypeNovaSynced,
Status: metav1.ConditionTrue,
- Reason: v1alpha1.ConditionReasonNovaSyncedUpToDate,
+ Reason: v1alpha1.ConditionReasonNovaSyncedOK,
})
return vm
}
diff --git a/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml b/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
new file mode 100644
index 0000000..b7af4ae
--- /dev/null
+++ b/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
@@ -0,0 +1,23 @@
+# Copyright SAP SE
+# SPDX-License-Identifier: Apache-2.0
+
+# Cortex cannot have observed a negative generation. Must be rejected.
+apiVersion: cobaltcore.cloud/v1alpha1
+kind: VirtualMachine
+metadata:
+ name: 00000000-0000-0000-0000-000000000016
+spec:
+ region: qa-de-1
+ az: qa-de-1a
+ resources:
+ cpu: "4"
+ memory: 8Gi
+ nova:
+ ownership:
+ project: 11111111-1111-1111-1111-111111111111
+ flavor:
+ name: m1.large
+ image:
+ uuid: 22222222-2222-2222-2222-222222222222
+ cortex:
+ observedGeneration: -1
diff --git a/test/crd/fixtures/valid/consumer-multiple.yaml b/test/crd/fixtures/valid/consumer-multiple.yaml
index cf0d78b..aa64490 100644
--- a/test/crd/fixtures/valid/consumer-multiple.yaml
+++ b/test/crd/fixtures/valid/consumer-multiple.yaml
@@ -16,11 +16,15 @@ spec:
nova:
ownership:
project: 11111111-1111-1111-1111-111111111111
+ domain: 55555555-5555-5555-5555-555555555555
flavor:
name: m1.large
image:
uuid: 22222222-2222-2222-2222-222222222222
cortex:
+ intent: live-migration
+ lastTransitionTime: "2026-11-16T10:00:00Z"
+ observedGeneration: 3
consumers:
- uuid: 63ed64e2-27a2-4b70-9b5c-833c2a285d66
generation: 5
From f859ba2eb3bfa138c0bc4b6c0fbdbcebeaab6f9d Mon Sep 17 00:00:00 2001
From: Philipp Matthes
Date: Tue, 17 Nov 2026 09:43:40 +0100
Subject: [PATCH 2/4] Remove printcolumn
Signed-off-by: Philipp Matthes
---
api/v1alpha1/vm_types.go | 1 -
dist/files/crds/cobaltcore.cloud_virtualmachines.yaml | 3 ---
2 files changed, 4 deletions(-)
diff --git a/api/v1alpha1/vm_types.go b/api/v1alpha1/vm_types.go
index 8057e17..14e56d7 100644
--- a/api/v1alpha1/vm_types.go
+++ b/api/v1alpha1/vm_types.go
@@ -469,7 +469,6 @@ type LibvirtHostInfo struct{}
// +kubebuilder:printcolumn:JSONPath=".spec.az",name="AZ",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.resources.cpu",name="CPU",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.resources.memory",name="Memory",type="string"
-// +kubebuilder:printcolumn:JSONPath=".metadata.labels.cobaltcore\\.cloud/target-host",name="TargetHost",type="string"
// +kubebuilder:printcolumn:JSONPath=".status.host.name",name="ActualHost",type="string"
// Wide-only columns (priority=1).
// +kubebuilder:printcolumn:JSONPath=".status.nova.host",name="NovaHost",type="string",priority=1
diff --git a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
index dec85ea..b700863 100644
--- a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
+++ b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
@@ -26,9 +26,6 @@ spec:
- jsonPath: .spec.resources.memory
name: Memory
type: string
- - jsonPath: .metadata.labels.cobaltcore\.cloud/target-host
- name: TargetHost
- type: string
- jsonPath: .status.host.name
name: ActualHost
type: string
From 4876b6fc19aaa5dd7a55b1860d5e4f2a04618a6c Mon Sep 17 00:00:00 2001
From: Philipp Matthes
Date: Tue, 17 Nov 2026 13:42:15 +0100
Subject: [PATCH 3/4] Bundle scheduling info together and add scheduling error
Signed-off-by: Philipp Matthes
---
api/v1alpha1/vm_types.go | 33 ++++++-------
api/v1alpha1/zz_generated.deepcopy.go | 14 +++---
.../cobaltcore.cloud_virtualmachines.yaml | 46 +++++++++++--------
internal/nova/controller_test.go | 6 +--
internal/nova/conversion_test.go | 6 +--
.../crd/fixtures/valid/consumer-multiple.yaml | 6 +--
6 files changed, 59 insertions(+), 52 deletions(-)
diff --git a/api/v1alpha1/vm_types.go b/api/v1alpha1/vm_types.go
index 14e56d7..339db2f 100644
--- a/api/v1alpha1/vm_types.go
+++ b/api/v1alpha1/vm_types.go
@@ -363,10 +363,6 @@ type PlacementConsumer struct {
// CortexSpec captures the desired state of this VM in Cortex.
type CortexSpec struct {
- // HostCandidates is the set of host references Cortex has considered for the most recent scheduling operation of the VM.
- // +kubebuilder:validation:Optional
- HostCandidates []corev1.ObjectReference `json:"hostCandidates,omitempty"`
-
// Consumers contains OpenStack Placement API consumers related to this VM.
// This includes the instance consumer and, if applicable, a migration consumer.
// If the VM has been created freshly, this list may be empty until the first
@@ -374,27 +370,32 @@ type CortexSpec struct {
// +kubebuilder:validation:Optional
Consumers []PlacementConsumer `json:"consumers,omitempty"`
- // Explanation is a human-readable explanation of the scheduling decision
+ // SchedulingCandidates is the set of host references Cortex has considered for the most recent scheduling operation of the VM.
+ // +kubebuilder:validation:Optional
+ SchedulingCandidates []corev1.ObjectReference `json:"schedulingCandidates,omitempty"`
+ // SchedulingError is a human-readable explanation of the scheduling error,
+ // if any occurred. Typically, this is non-empty when the set of scheduling
+ // candidates is empty.
+ // +kubebuilder:validation:Optional
+ SchedulingError string `json:"schedulingError,omitempty"`
+ // SchedulingExplanation is a human-readable explanation of the scheduling decision
// made by Cortex.
// +kubebuilder:validation:Optional
- Explanation string `json:"explanation,omitempty"`
-
- // Intent is the last operation performed on this virtual machine,
+ SchedulingExplanation string `json:"schedulingExplanation,omitempty"`
+ // SchedulingIntent is the last operation performed on this virtual machine,
// e.g. initial placement, evacuation, live-migration, rebuild, etc.
// This is an information provided by Nova to Cortex, but it is
// persisted nowhere inside the Nova database, so Cortex propagates
// this information into the CortexSpec.
// +kubebuilder:validation:Optional
- Intent string `json:"intent,omitempty"`
-
- // LastTransitionTime is the timestamp of the last transition of the VM's intent.
+ SchedulingIntent string `json:"schedulingIntent,omitempty"`
+ // SchedulingTime is the timestamp of the last transition of the VM's intent.
// +kubebuilder:validation:Optional
- LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
-
- // ObservedGeneration is the last generation observed by cortex for this VM.
+ SchedulingTime *metav1.Time `json:"schedulingTime,omitempty"`
+ // ScheduledGeneration is the last generation observed by cortex for this VM.
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
- ObservedGeneration int64 `json:"observedGeneration,omitempty"`
+ ScheduledGeneration int64 `json:"scheduledGeneration,omitempty"`
}
// VMStatus defines the observed state of a VirtualMachine.
@@ -424,7 +425,7 @@ type VMStatus struct {
//
// If no conditions are set, the operator has not yet recorded observations.
// This includes resources just scheduled for the first time by Cortex.
- // See the cortex spec for scheduling details.
+ // See the CortexSpec for scheduling details.
//
// +listType=map
// +listMapKey=type
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index a2f9515..416b199 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -17,11 +17,6 @@ import (
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CortexSpec) DeepCopyInto(out *CortexSpec) {
*out = *in
- if in.HostCandidates != nil {
- in, out := &in.HostCandidates, &out.HostCandidates
- *out = make([]v1.ObjectReference, len(*in))
- copy(*out, *in)
- }
if in.Consumers != nil {
in, out := &in.Consumers, &out.Consumers
*out = make([]PlacementConsumer, len(*in))
@@ -29,8 +24,13 @@ func (in *CortexSpec) DeepCopyInto(out *CortexSpec) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
- if in.LastTransitionTime != nil {
- in, out := &in.LastTransitionTime, &out.LastTransitionTime
+ if in.SchedulingCandidates != nil {
+ in, out := &in.SchedulingCandidates, &out.SchedulingCandidates
+ *out = make([]v1.ObjectReference, len(*in))
+ copy(*out, *in)
+ }
+ if in.SchedulingTime != nil {
+ in, out := &in.SchedulingTime, &out.SchedulingTime
*out = (*in).DeepCopy()
}
}
diff --git a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
index b700863..e836ac7 100644
--- a/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
+++ b/dist/files/crds/cobaltcore.cloud_virtualmachines.yaml
@@ -155,15 +155,16 @@ spec:
- uuid
type: object
type: array
- explanation:
- description: |-
- Explanation is a human-readable explanation of the scheduling decision
- made by Cortex.
- type: string
- hostCandidates:
- description: HostCandidates is the set of host references Cortex
- has considered for the most recent scheduling operation of the
- VM.
+ scheduledGeneration:
+ description: ScheduledGeneration is the last generation observed
+ by cortex for this VM.
+ format: int64
+ minimum: 0
+ type: integer
+ schedulingCandidates:
+ description: SchedulingCandidates is the set of host references
+ Cortex has considered for the most recent scheduling operation
+ of the VM.
items:
description: ObjectReference contains enough information to
let you inspect or modify the referred object.
@@ -209,25 +210,30 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
- intent:
+ schedulingError:
+ description: |-
+ SchedulingError is a human-readable explanation of the scheduling error,
+ if any occurred. Typically, this is non-empty when the set of scheduling
+ candidates is empty.
+ type: string
+ schedulingExplanation:
+ description: |-
+ SchedulingExplanation is a human-readable explanation of the scheduling decision
+ made by Cortex.
+ type: string
+ schedulingIntent:
description: |-
- Intent is the last operation performed on this virtual machine,
+ SchedulingIntent is the last operation performed on this virtual machine,
e.g. initial placement, evacuation, live-migration, rebuild, etc.
This is an information provided by Nova to Cortex, but it is
persisted nowhere inside the Nova database, so Cortex propagates
this information into the CortexSpec.
type: string
- lastTransitionTime:
- description: LastTransitionTime is the timestamp of the last transition
+ schedulingTime:
+ description: SchedulingTime is the timestamp of the last transition
of the VM's intent.
format: date-time
type: string
- observedGeneration:
- description: ObservedGeneration is the last generation observed
- by cortex for this VM.
- format: int64
- minimum: 0
- type: integer
type: object
hypervisorType:
description: HypervisorType is the hypervisor type of the host where
@@ -358,7 +364,7 @@ spec:
If no conditions are set, the operator has not yet recorded observations.
This includes resources just scheduled for the first time by Cortex.
- See the cortex spec for scheduling details.
+ See the CortexSpec for scheduling details.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
diff --git a/internal/nova/controller_test.go b/internal/nova/controller_test.go
index 2918244..f389d5b 100644
--- a/internal/nova/controller_test.go
+++ b/internal/nova/controller_test.go
@@ -331,7 +331,7 @@ func TestController_Reconcile_preservesCortexSpec(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1alpha1.VMSpec{
Cortex: &v1alpha1.CortexSpec{
- HostCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-9"}},
+ SchedulingCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-9"}},
},
},
}
@@ -360,8 +360,8 @@ func TestController_Reconcile_preservesCortexSpec(t *testing.T) {
if got.Spec.Cortex == nil {
t.Fatal("spec.cortex was cleared by the nova sync")
}
- if len(got.Spec.Cortex.HostCandidates) != 1 || got.Spec.Cortex.HostCandidates[0].Name != "compute-9" {
- t.Errorf("spec.cortex.hostCandidates = %+v, want the seeded compute-9", got.Spec.Cortex.HostCandidates)
+ if len(got.Spec.Cortex.SchedulingCandidates) != 1 || got.Spec.Cortex.SchedulingCandidates[0].Name != "compute-9" {
+ t.Errorf("spec.cortex.schedulingCandidates = %+v, want the seeded compute-9", got.Spec.Cortex.SchedulingCandidates)
}
}
diff --git a/internal/nova/conversion_test.go b/internal/nova/conversion_test.go
index fbdfd80..a8481d6 100644
--- a/internal/nova/conversion_test.go
+++ b/internal/nova/conversion_test.go
@@ -110,9 +110,9 @@ func TestPatchInto_preservesDomain(t *testing.T) {
// Cortex subspec, which the Cortex placement API owns.
func TestPatchInto_preservesCortex(t *testing.T) {
cortex := &v1alpha1.CortexSpec{
- HostCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-1"}},
- LastTransitionTime: new(metav1.Now()),
- ObservedGeneration: 3,
+ SchedulingCandidates: []corev1.ObjectReference{{Kind: "Hypervisor", Name: "compute-1"}},
+ SchedulingTime: new(metav1.Now()),
+ ScheduledGeneration: 3,
}
vm := &v1alpha1.VirtualMachine{ObjectMeta: metav1.ObjectMeta{Name: "a"}}
vm.Spec.Cortex = cortex
diff --git a/test/crd/fixtures/valid/consumer-multiple.yaml b/test/crd/fixtures/valid/consumer-multiple.yaml
index aa64490..40199fc 100644
--- a/test/crd/fixtures/valid/consumer-multiple.yaml
+++ b/test/crd/fixtures/valid/consumer-multiple.yaml
@@ -22,9 +22,9 @@ spec:
image:
uuid: 22222222-2222-2222-2222-222222222222
cortex:
- intent: live-migration
- lastTransitionTime: "2026-11-16T10:00:00Z"
- observedGeneration: 3
+ schedulingIntent: live-migration
+ schedulingTime: "2026-11-16T10:00:00Z"
+ scheduledGeneration: 3
consumers:
- uuid: 63ed64e2-27a2-4b70-9b5c-833c2a285d66
generation: 5
From a112a36c03b3be0b5965cbd7b9436b80cfc1bb2a Mon Sep 17 00:00:00 2001
From: Philipp Matthes
Date: Tue, 17 Nov 2026 13:44:07 +0100
Subject: [PATCH 4/4] Fix invalid fixture
Signed-off-by: Philipp Matthes
---
.../fixtures/invalid/cortex-negative-observed-generation.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml b/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
index b7af4ae..ea539fc 100644
--- a/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
+++ b/test/crd/fixtures/invalid/cortex-negative-observed-generation.yaml
@@ -20,4 +20,4 @@ spec:
image:
uuid: 22222222-2222-2222-2222-222222222222
cortex:
- observedGeneration: -1
+ scheduledGeneration: -1