-
Notifications
You must be signed in to change notification settings - Fork 10
Added Reservation API, poollet and broker implementation
#1172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e1701b3
5287357
d621f9f
839eafc
e9e408b
7b65293
0015864
e35adbe
f6855f6
c7b1640
436c8bd
2c431bb
fd3a555
6c1308f
03533de
459ccf5
db793f1
6f4b215
9cd179a
bbb5ba8
ffc87ea
5deff4b
554a9a0
642f632
d2dbece
5ce43e7
16e2007
1eda5b4
929b992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||
| // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors | ||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| package v1alpha1 | ||||||
|
|
||||||
| import ( | ||||||
| corev1alpha1 "github.com/ironcore-dev/ironcore/api/core/v1alpha1" | ||||||
| corev1 "k8s.io/api/core/v1" | ||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
| ) | ||||||
|
|
||||||
| // ReservationSpec defines the desired state of Reservation | ||||||
| type ReservationSpec struct { | ||||||
lukasfrank marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Pools []corev1.LocalObjectReference `json:"pools"` | ||||||
| Resources corev1alpha1.ResourceList `json:"resources,omitempty"` | ||||||
| // TODO we might want to add a weight to indicate preference/priority | ||||||
| } | ||||||
|
|
||||||
| // ReservationStatus defines the observed state of Reservation | ||||||
| type ReservationStatus struct { | ||||||
| Pools []ReservationPoolStatus `json:"pools,omitempty"` | ||||||
| Conditions []ReservationCondition `json:"conditions,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| // ReservationState is the state of a Reservation. | ||||||
| // +enum | ||||||
| type ReservationState string | ||||||
|
|
||||||
| const ( | ||||||
| // ReservationStatePending means the Reservation is being reconciled. | ||||||
| ReservationStatePending ReservationState = "Pending" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| // ReservationStateAccepted means the pool accepted the reservation and reserved the requested resources. | ||||||
| ReservationStateAccepted ReservationState = "Accepted" | ||||||
| // ReservationStateRejected means the pool rejected the reservation. | ||||||
| ReservationStateRejected ReservationState = "Rejected" | ||||||
| ) | ||||||
|
|
||||||
| // ReservationConditionType is a type a ReservationCondition can have. | ||||||
| type ReservationConditionType string | ||||||
|
|
||||||
| // ReservationCondition is one of the conditions of a volume. | ||||||
| type ReservationCondition struct { | ||||||
| // Type is the type of the condition. | ||||||
| Type ReservationConditionType `json:"type"` | ||||||
| // Status is the status of the condition. | ||||||
| Status corev1.ConditionStatus `json:"status"` | ||||||
| // Reason is a machine-readable indication of why the condition is in a certain state. | ||||||
| Reason string `json:"reason"` | ||||||
| // Message is a human-readable explanation of why the condition has a certain reason / state. | ||||||
| Message string `json:"message"` | ||||||
| // ObservedGeneration represents the .metadata.generation that the condition was set based upon. | ||||||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||||||
| // LastTransitionTime is the last time the status of a condition has transitioned from one state to another. | ||||||
| LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| type ReservationPoolStatus struct { | ||||||
| Name string `json:"ref,omitempty"` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| State ReservationState `json:"state,omitempty"` | ||||||
lukasfrank marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| // +genclient | ||||||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||||||
|
|
||||||
| // Reservation is the Schema for the machines API | ||||||
| type Reservation struct { | ||||||
| metav1.TypeMeta `json:",inline"` | ||||||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
|
|
||||||
| Spec ReservationSpec `json:"spec,omitempty"` | ||||||
| Status ReservationStatus `json:"status,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||||||
|
|
||||||
| // ReservationList contains a list of Reservation | ||||||
| type ReservationList struct { | ||||||
| metav1.TypeMeta `json:",inline"` | ||||||
| metav1.ListMeta `json:"metadata,omitempty"` | ||||||
| Items []Reservation `json:"items"` | ||||||
| } | ||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package server | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1" | ||
| "github.com/ironcore-dev/ironcore/broker/machinebroker/apiutils" | ||
| iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1" | ||
| ) | ||
|
|
||
| var ironcoreReservationStateToReservationState = map[computev1alpha1.ReservationState]iri.ReservationState{ | ||
| computev1alpha1.ReservationStatePending: iri.ReservationState_RESERVATION_STATE_PENDING, | ||
| computev1alpha1.ReservationStateAccepted: iri.ReservationState_RESERVATION_STATE_ACCEPTED, | ||
| computev1alpha1.ReservationStateRejected: iri.ReservationState_RESERVATION_STATE_REJECTED, | ||
| } | ||
|
|
||
| func (s *Server) convertIronCoreReservationState(state computev1alpha1.ReservationState) (iri.ReservationState, error) { | ||
| if res, ok := ironcoreReservationStateToReservationState[state]; ok { | ||
| return res, nil | ||
| } | ||
| return 0, fmt.Errorf("unknown ironcore reservation state %q", state) | ||
| } | ||
|
|
||
| func (s *Server) convertIronCoreReservationStatus(ironCoreReservation *computev1alpha1.Reservation) (iri.ReservationState, error) { | ||
| if ironCoreReservation.Spec.Pools == nil || ironCoreReservation.Status.Pools == nil { | ||
| return iri.ReservationState_RESERVATION_STATE_PENDING, nil | ||
| } | ||
|
|
||
| //TODO make configurable | ||
| for _, pool := range ironCoreReservation.Status.Pools { | ||
| state, err := s.convertIronCoreReservationState(pool.State) | ||
| if err != nil { | ||
| return iri.ReservationState_RESERVATION_STATE_PENDING, err | ||
| } | ||
|
|
||
| switch state { | ||
| case iri.ReservationState_RESERVATION_STATE_REJECTED: | ||
| return state, nil | ||
| case iri.ReservationState_RESERVATION_STATE_PENDING: | ||
| return state, nil | ||
|
|
||
| } | ||
| } | ||
|
|
||
| return iri.ReservationState_RESERVATION_STATE_REJECTED, nil | ||
| } | ||
|
|
||
| func (s *Server) convertIronCoreReservation(ironCoreReservation *computev1alpha1.Reservation) (*iri.Reservation, error) { | ||
| metadata, err := apiutils.GetObjectMetadata(ironCoreReservation) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| state, err := s.convertIronCoreReservationStatus(ironCoreReservation) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &iri.Reservation{ | ||
| Metadata: metadata, | ||
| Spec: &iri.ReservationSpec{ | ||
| Resources: nil, | ||
| }, | ||
| Status: &iri.ReservationStatus{ | ||
| State: state, | ||
| }, | ||
| }, nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all filenames should follow same pattern either starting with
machinereservationorreservationconsidering future enhancements for volume reservation.