Skip to content
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

Added Reservation API, poollet and broker implementation #1172

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
5 changes: 3 additions & 2 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- lukasfrank:feat/reservations
tags:
- v*
paths-ignore:
Expand Down Expand Up @@ -84,7 +85,7 @@ jobs:
version: latest
endpoint: builders # self-hosted
- name: Login to GHCR
if: github.event_name != 'pull_request'
# if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
Expand All @@ -96,7 +97,7 @@ jobs:
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
# push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: ${{ matrix.image.target }}
60 changes: 60 additions & 0 deletions api/compute/v1alpha1/machinereservation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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:"capabilities,omitempty"`
}

// ReservationStatus defines the observed state of Reservation
type ReservationStatus struct {
Pools []ReservationPoolStatus `json:"pools,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"
)

type ReservationPoolStatus struct {
Name string `json:"ref,omitempty"`
State ReservationState `json:"state,omitempty"`
}

// +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"`
}
2 changes: 2 additions & 0 deletions api/compute/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&MachineClassList{},
&MachinePool{},
&MachinePoolList{},
&Reservation{},
&ReservationList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
126 changes: 126 additions & 0 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 additions & 1 deletion broker/machinebroker/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const (
)

const (
MachineBrokerManager = "machinebroker"
MachineBrokerManager = "machinebroker"
ReservationBrokerManager = "reservationbroker"

VolumeAccessPurpose = "volume-access"
)
71 changes: 71 additions & 0 deletions broker/machinebroker/server/reservation.go
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
}
Loading
Loading