Skip to content
Open
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
15 changes: 7 additions & 8 deletions api/external/nova/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log/slog"
"strings"

"github.com/cobaltcore-dev/cortex/api/v1alpha1"
"github.com/cobaltcore-dev/cortex/internal/scheduling/lib"
)

Expand Down Expand Up @@ -129,23 +130,21 @@ func (req ExternalSchedulerRequest) GetHypervisorType() (HypervisorType, error)
return "", errors.New("hypervisor type not specified in flavor extra specs")
}

type RequestIntent string

const (
// LiveMigrationIntent indicates that the request is intended for live migration.
LiveMigrationIntent RequestIntent = "live_migration"
LiveMigrationIntent v1alpha1.SchedulingIntent = "live_migration"
// RebuildIntent indicates that the request is intended for rebuilding a VM.
RebuildIntent RequestIntent = "rebuild"
RebuildIntent v1alpha1.SchedulingIntent = "rebuild"
// ResizeIntent indicates that the request is intended for resizing a VM.
ResizeIntent RequestIntent = "resize"
ResizeIntent v1alpha1.SchedulingIntent = "resize"
// EvacuateIntent indicates that the request is intended for evacuating a VM.
EvacuateIntent RequestIntent = "evacuate"
EvacuateIntent v1alpha1.SchedulingIntent = "evacuate"
// CreateIntent indicates that the request is intended for creating a new VM.
CreateIntent RequestIntent = "create"
CreateIntent v1alpha1.SchedulingIntent = "create"
)

// GetIntent analyzes the request spec and determines the intent of the scheduling request.
func (req ExternalSchedulerRequest) GetIntent() (RequestIntent, error) {
func (req ExternalSchedulerRequest) GetIntent() (v1alpha1.SchedulingIntent, error) {
str, err := req.Spec.Data.GetSchedulerHintStr("_nova_check_type")
if err != nil {
return "", err
Expand Down
4 changes: 3 additions & 1 deletion api/external/nova/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package api
import (
"encoding/json"
"testing"

"github.com/cobaltcore-dev/cortex/api/v1alpha1"
)

func TestGetIntent(t *testing.T) {
tests := []struct {
name string
schedulerHints map[string]any
expectedIntent RequestIntent
expectedIntent v1alpha1.SchedulingIntent
expectError bool
}{
{
Expand Down
116 changes: 116 additions & 0 deletions api/v1alpha1/history_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright SAP SE
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// SchedulingIntent defines the intent of a scheduling decision.
type SchedulingIntent string

// Other intents can be defined by the operators.
const (
// Used as default intent if the operator does not specify one.
SchedulingIntentUnknown SchedulingIntent = "Unknown"
)

type SchedulingHistoryEntry struct {
// The timestamp of when the decision was made.
Timestamp metav1.Time `json:"timestamp"`
// The pipeline that was used for the decision.
PipelineRef corev1.ObjectReference `json:"pipelineRef"`
// The intent of the decision (e.g., initial scheduling, rescheduling, etc.).
Intent SchedulingIntent `json:"intent"`
// The top hosts ordered by score for the decision (limited to 3).
// This is not a complete list of all candidates — only the highest-ranked
// hosts are retained to keep the history compact.
// +kubebuilder:validation:Optional
OrderedHosts []string `json:"orderedHosts"`
// Whether the scheduling decision was successful.
// +kubebuilder:validation:Optional
Successful bool `json:"successful"`
}

type HistorySpec struct {
// The scheduling domain this object with the history belongs to.
SchedulingDomain SchedulingDomain `json:"schedulingDomain"`
// The resource ID this history belongs to (e.g., the UUID of a nova instance).
ResourceID string `json:"resourceID"`
}

// CurrentDecision holds the full context of the most recent scheduling
// decision. When a new decision arrives the previous CurrentDecision is
// compacted into a SchedulingHistoryEntry and appended to History.
type CurrentDecision struct {
// The timestamp of when the decision was made.
Timestamp metav1.Time `json:"timestamp"`
// The pipeline that was used for the decision.
PipelineRef corev1.ObjectReference `json:"pipelineRef"`
// The intent of the decision (e.g., initial scheduling, rescheduling, etc.).
Intent SchedulingIntent `json:"intent"`
// Whether the scheduling decision was successful.
Successful bool `json:"successful"`
// The target host selected for the resource. nil when no host was found.
// +kubebuilder:validation:Optional
TargetHost *string `json:"targetHost,omitempty"`
// A human-readable explanation of the scheduling decision.
// +kubebuilder:validation:Optional
Explanation string `json:"explanation,omitempty"`
// The top hosts ordered by score (limited to 3).
// +kubebuilder:validation:Optional
OrderedHosts []string `json:"orderedHosts,omitempty"`
}

type HistoryStatus struct {
// Current represents the latest scheduling decision with full context.
// +kubebuilder:validation:Optional
Current CurrentDecision `json:"current,omitempty"`
// History of past scheduling decisions (limited to last 10).
// +kubebuilder:validation:Optional
History []SchedulingHistoryEntry `json:"history,omitempty"`

// Conditions represent the latest available observations of the history's state.
// +kubebuilder:validation:Optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="Domain",type="string",JSONPath=".spec.schedulingDomain"
// +kubebuilder:printcolumn:name="Resource ID",type="string",JSONPath=".spec.resourceID"
// +kubebuilder:printcolumn:name="Target Host",type="string",JSONPath=".status.current.targetHost"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
// +kubebuilder:printcolumn:name="Created",type="date",JSONPath=".metadata.creationTimestamp"

// History is the Schema for the history API
type History struct {
metav1.TypeMeta `json:",inline"`

// Standard object metadata.
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the desired state of History.
// +required
Spec HistorySpec `json:"spec"`
// Status defines the observed state of History.
// +optional
Status HistoryStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// HistoryList contains a list of History
type HistoryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []History `json:"items"`
}

func init() {
SchemeBuilder.Register(&History{}, &HistoryList{})
}
3 changes: 3 additions & 0 deletions api/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type PipelineSpec struct {

// If this pipeline should create decision objects.
// When this is false, the pipeline will still process requests.
// NOTE: This flag is intentionally kept as "createDecisions" to avoid
// breaking changes. It will be renamed when the deprecated Decision CRD
// is fully replaced in a future refactoring.
// +kubebuilder:default=false
CreateDecisions bool `json:"createDecisions,omitempty"`

Expand Down
153 changes: 153 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

14 changes: 0 additions & 14 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/cobaltcore-dev/cortex/internal/knowledge/extractor"
"github.com/cobaltcore-dev/cortex/internal/knowledge/kpis"
"github.com/cobaltcore-dev/cortex/internal/scheduling/cinder"
"github.com/cobaltcore-dev/cortex/internal/scheduling/explanation"
schedulinglib "github.com/cobaltcore-dev/cortex/internal/scheduling/lib"
"github.com/cobaltcore-dev/cortex/internal/scheduling/machines"
"github.com/cobaltcore-dev/cortex/internal/scheduling/manila"
Expand Down Expand Up @@ -443,19 +442,6 @@ func main() {
os.Exit(1)
}
}
if slices.Contains(mainConfig.EnabledControllers, "explanation-controller") {
// Setup a controller which will reconcile the history and explanation for
// decision resources.
explanationControllerConfig := conf.GetConfigOrDie[explanation.ControllerConfig]()
explanationController := &explanation.Controller{
Client: multiclusterClient,
Config: explanationControllerConfig,
}
if err := explanationController.SetupWithManager(mgr, multiclusterClient); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ExplanationController")
os.Exit(1)
}
}
if slices.Contains(mainConfig.EnabledControllers, "reservations-controller") {
monitor := reservationscontroller.NewControllerMonitor(multiclusterClient)
metrics.Registry.MustRegister(&monitor)
Expand Down
1 change: 0 additions & 1 deletion helm/bundles/cortex-cinder/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ cortex-scheduling-controllers:
component: cinder-scheduling
enabledControllers:
- cinder-decisions-pipeline-controller
- explanation-controller
enabledTasks:
- cinder-decisions-cleanup-task

Expand Down
1 change: 0 additions & 1 deletion helm/bundles/cortex-ironcore/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ cortex:
schedulingDomain: machines
enabledControllers:
- ironcore-decisions-pipeline-controller
- explanation-controller
monitoring:
labels:
github_org: cobaltcore-dev
Expand Down
Loading