Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
test: ## Run all tests.
go test ./...

.PHONY: generate
generate: deepcopy crds ## Regenerate CRDs and DeepCopy after API type changes.

.PHONY: crds
crds: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=helm/library/cortex/files/crds
Expand Down
158 changes: 120 additions & 38 deletions api/v1alpha1/reservation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,150 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Additional specifications needed to place the reservation.
type ReservationSchedulerSpec struct {
// If the type of scheduler is cortex-nova, this field will contain additional
// information used by cortex-nova to place the instance.
CortexNova *ReservationSchedulerSpecCortexNova `json:"cortexNova,omitempty"`
}
// ReservationType defines the type of reservation.
// In Kubernetes, "Type" is the conventional field name for sub-type discrimination
// within a resource (similar to Service.spec.type), while "Kind" refers to the
// resource type itself (Pod, Deployment, etc.).
type ReservationType string

const (
// ReservationTypeCommittedResource is a reservation for committed/reserved capacity.
ReservationTypeCommittedResource ReservationType = "CommittedResourceReservation"
// ReservationTypeFailover is a reservation for failover capacity.
ReservationTypeFailover ReservationType = "FailoverReservation"
)

// CommittedResourceReservationSpec defines the spec fields specific to committed resource reservations.
type CommittedResourceReservationSpec struct {
// ResourceName is the name of the resource to reserve (e.g., FlavorName for Nova).
// +kubebuilder:validation:Optional
ResourceName string `json:"resourceName,omitempty"`

// Additional specifications needed by cortex-nova to place the instance.
type ReservationSchedulerSpecCortexNova struct {
// The project ID to reserve for.
// ResourceGroup is the group/category of the resource (e.g., "hana_medium_v2").
// +kubebuilder:validation:Optional
ResourceGroup string `json:"resourceGroup,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is ResourceGroup also on root level? Required for more use cases than CRs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not on root the diff is just not great


// ProjectID is the UUID of the project this reservation belongs to.
// +kubebuilder:validation:Optional
ProjectID string `json:"projectID,omitempty"`
// The domain ID to reserve for.

// DomainID is the domain ID to reserve for.
// +kubebuilder:validation:Optional
DomainID string `json:"domainID,omitempty"`
// The flavor name of the instance to reserve.
FlavorName string `json:"flavorName,omitempty"`
// Extra specifications relevant for initial placement of the instance.
FlavorExtraSpecs map[string]string `json:"flavorExtraSpecs,omitempty"`

// Creator identifies the system or component that created this reservation.
// Used to track ownership and for cleanup purposes (e.g., "commitments-syncer").
// +kubebuilder:validation:Optional
Creator string `json:"creator,omitempty"`
}

// FailoverReservationSpec defines the spec fields specific to failover reservations.
type FailoverReservationSpec struct {
// ResourceGroup is the group/category of the resource (e.g., "hana_medium_v2").
// +kubebuilder:validation:Optional
ResourceGroup string `json:"resourceGroup,omitempty"`
}

// ReservationSpec defines the desired state of Reservation.
type ReservationSpec struct {
// A remark that can be used to identify the creator of the reservation.
// This can be used to clean up reservations synced from external systems
// without touching reservations created manually or by other systems.
Creator string `json:"creator,omitempty"`
// Specification of the scheduler that will handle the reservation.
Scheduler ReservationSchedulerSpec `json:"scheduler,omitempty"`
// Resources requested to reserve for this instance.
Requests map[string]resource.Quantity `json:"requests,omitempty"`
}
// Type of reservation.
// +kubebuilder:validation:Enum=CommittedResourceReservation;FailoverReservation
// +kubebuilder:validation:Required
Type ReservationType `json:"type"`

// The phase in which the reservation is.
type ReservationStatusPhase string
// SchedulingDomain specifies the scheduling domain for this reservation (e.g., "nova", "ironcore").
// +kubebuilder:validation:Optional
SchedulingDomain string `json:"schedulingDomain,omitempty"`

const (
// The reservation has been placed and is considered during scheduling.
ReservationStatusPhaseActive ReservationStatusPhase = "active"
// The reservation could not be fulfilled.
ReservationStatusPhaseFailed ReservationStatusPhase = "failed"
)
// Resources to reserve for this instance.
// +kubebuilder:validation:Optional
Resources map[string]resource.Quantity `json:"resources,omitempty"`

// StartTime is the time when the reservation becomes active.
// +kubebuilder:validation:Optional
StartTime *metav1.Time `json:"startTime,omitempty"`

// EndTime is the time when the reservation expires.
// +kubebuilder:validation:Optional
EndTime *metav1.Time `json:"endTime,omitempty"`

// TargetHost is the desired compute host where the reservation should be placed.
// This is a generic name that represents different concepts depending on the scheduling domain:
// - For Nova: the hypervisor hostname
// - For Pods: the node name
// The scheduler will attempt to place the reservation on this host.
// +kubebuilder:validation:Optional
TargetHost string `json:"targetHost,omitempty"`

// CommittedResourceReservation contains fields specific to committed resource reservations.
// Only used when Type is CommittedResourceReservation.
// +kubebuilder:validation:Optional
CommittedResourceReservation *CommittedResourceReservationSpec `json:"committedResourceReservation,omitempty"`

// FailoverReservation contains fields specific to failover reservations.
// Only used when Type is FailoverReservation.
// +kubebuilder:validation:Optional
FailoverReservation *FailoverReservationSpec `json:"failoverReservation,omitempty"`
}

const (
// Something went wrong during the handling of the reservation.
ReservationConditionError = "Error"
// ReservationConditionReady indicates whether the reservation is active and ready.
ReservationConditionReady = "Ready"
)

// CommittedResourceReservationStatus defines the status fields specific to committed resource reservations.
type CommittedResourceReservationStatus struct {
// Allocations lists the VM/instance UUIDs that are currently allocated against this reservation.
// +kubebuilder:validation:Optional
Allocations []string `json:"allocations,omitempty"`
}

// FailoverReservationStatus defines the status fields specific to failover reservations.
type FailoverReservationStatus struct {
// Allocations maps VM/instance UUIDs to the host they are currently allocated on.
// Key: VM/instance UUID, Value: Host name where the VM is currently running.
// +kubebuilder:validation:Optional
Allocations map[string]string `json:"allocations,omitempty"`
}

// ReservationStatus defines the observed state of Reservation.
type ReservationStatus struct {
// The current phase of the reservation.
Phase ReservationStatusPhase `json:"phase,omitempty"`
// The current status conditions of the reservation.
// Conditions include:
// - type: Ready
// status: True|False|Unknown
// reason: ReservationReady
// message: Reservation is successfully scheduled
// lastTransitionTime: <timestamp>
// +kubebuilder:validation:Optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
// The name of the compute host that was allocated.
Host string `json:"host"`

// Host is the actual host where the reservation is placed.
// This is set by the scheduler after successful placement and reflects the current state.
// It should match Spec.TargetHost when the reservation is successfully placed.
// This is a generic name that represents different concepts depending on the scheduling domain:
// - For Nova: the hypervisor hostname
// - For Pods: the node name
// +kubebuilder:validation:Optional
Host string `json:"host,omitempty"`

// CommittedResourceReservation contains status fields specific to committed resource reservations.
// Only used when Type is CommittedResourceReservation.
// +kubebuilder:validation:Optional
CommittedResourceReservation *CommittedResourceReservationStatus `json:"committedResourceReservation,omitempty"`

// FailoverReservation contains status fields specific to failover reservations.
// Only used when Type is FailoverReservation.
// +kubebuilder:validation:Optional
FailoverReservation *FailoverReservationStatus `json:"failoverReservation,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type"
// +kubebuilder:printcolumn:name="Host",type="string",JSONPath=".status.host"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"

// Reservation is the Schema for the reservations API
type Reservation struct {
Expand Down
147 changes: 102 additions & 45 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading