Skip to content

Add spec.bookings field with typed resource claim entries#296

Draft
PhilippMatthes wants to merge 2 commits intomainfrom
spec-bookings
Draft

Add spec.bookings field with typed resource claim entries#296
PhilippMatthes wants to merge 2 commits intomainfrom
spec-bookings

Conversation

@PhilippMatthes
Copy link
Copy Markdown
Member

@PhilippMatthes PhilippMatthes commented Apr 30, 2026

The Cortex Placement Shim needs to record which resources each instance consumes on a hypervisor, and which capacity is held back from scheduling. Today, the Hypervisor CRD tracks actual resource usage via status.allocation (auto-discovered by kvm-node-agent from libvirt), but has no representation of what Nova thinks is allocated. This prevents the shim from serving allocation and inventory endpoints directly from the CRD.

This PR introduces spec.bookings — the CRD's record of all resource claims as seen by the Placement API. There are two kinds of resource claims:

  • Consumers — instance allocations. Each consumer (identified by UUID) holds resources on one or more providers. A consumer can span multiple Hypervisor CRs during live migration.
  • Reservations — capacity held back from scheduling. Nova's reserved_host_memory_mb, reserved_host_cpus, and reserved_host_disk_mb config options subtract from available inventory.

The field follows the same field-presence union pattern established by spec.groups (and PodSpec.volumes in core Kubernetes). Each entry populates exactly one type-specific sub-field, and the populated field identifies the booking type:

spec:
  bookings:
    - consumer:
        uuid: "instance-uuid-1"
        resources:
          cpu: "2"
          memory: "4Gi"
        consumerGeneration: 1
        consumerType: "INSTANCE"
        projectID: "proj-123"
        userID: "user-456"
    - reservation:
        name: "nova-reserved"
        resources:
          cpu: "2"
          memory: "512Mi"

A CEL validation rule enforces that exactly one sub-field is populated per entry. The consumerType field is a free-form string to accommodate all consumer types in the Placement API (see API reference).

Library helper functions (GetConsumers, GetConsumer, HasConsumer, GetReservations, GetReservation, SumResources) follow the same pattern as the spec.groups helpers and are reusable across the shim, operator, and scheduler.

The design is extensible: adding a new booking concept means adding one optional pointer field to the Booking struct and a corresponding type-specific struct. No changes to existing fields or consumers are required.

See: cobaltcore-dev/cortex#787

Model consumer allocations and reserved capacity under spec.bookings
using the field-presence union pattern established by spec.groups.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb1fa9f2-b51f-4bdf-a922-b6b57e7acf1c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch spec-bookings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The modernize/newexpr linter flags the generic ptr[T] helper as an
inlinable wrapper around new(). Replace the single usage with new(int64)
and remove the helper function entirely.
@github-actions
Copy link
Copy Markdown

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1 0.00% (ø)
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations 0.00% (ø)
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/api/v1 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1/hypervisor_types.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1/zz_generated.deepcopy.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/api/v1/booking.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/api/v1/consumerbooking.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/api/v1/hypervisorspec.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/api/v1/reservationbooking.go 0.00% (ø) 0 0 0
github.com/cobaltcore-dev/openstack-hypervisor-operator/applyconfigurations/utils.go 0.00% (ø) 0 0 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1/hypervisor_validation_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant