-
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
Open
lukasfrank
wants to merge
29
commits into
ironcore-dev:main
Choose a base branch
from
lukasfrank:feat/reservations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e1701b3
WIP
lukasfrank 5287357
WIP
lukasfrank d621f9f
WIP
lukasfrank 839eafc
Merge branch 'main_fork' into feat/reservations
lukasfrank e9e408b
WIP
lukasfrank 7b65293
WIP
lukasfrank 0015864
Tests & fixes
lukasfrank e35adbe
Added copyright
lukasfrank f6855f6
Merge branch 'ironcore-dev:main' into feat/reservations
lukasfrank c7b1640
Fix linting
lukasfrank 436c8bd
codegen
lukasfrank 2c431bb
fix tests
lukasfrank fd3a555
Merge branch 'main_fork' into feat/reservations
lukasfrank 6c1308f
Merge branch 'main' into feat/reservations
lukasfrank 03533de
Fix
lukasfrank 459ccf5
Merge branch 'ironcore-dev:main' into feat/reservations
lukasfrank db793f1
Merge branch 'main_fork' into feat/reservations
lukasfrank 6f4b215
Update proto
lukasfrank 9cd179a
Merge branch 'main' into feat/reservations
lukasfrank bbb5ba8
Fix linting issues
lukasfrank ffc87ea
Fix proto dep
lukasfrank 5deff4b
Review feedback
lukasfrank 554a9a0
Merge branch 'main' into feat/reservations
lukasfrank 642f632
Fix code generation
lukasfrank d2dbece
Merge branch 'main' into feat/reservations
lukasfrank 5ce43e7
PR review
lukasfrank 16e2007
Merge remote-tracking branch 'origin/main' into feat/reservations
lukasfrank 1eda5b4
Update PR
lukasfrank 929b992
Merge branch 'main' into feat/reservations
lukasfrank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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" | ||
// 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"` | ||
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"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.