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
7 changes: 7 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ jobs:
with:
controller-ref: ${{ github.ref }}
jumpstarter-ref: main
e2e-tests-28d6b1cc3b49ab9ae176918ab9709a2e2522c97e:
runs-on: ubuntu-latest
steps:
- uses: jumpstarter-dev/jumpstarter-e2e@11a5ce6734be9f089ec3ea6ebf55284616f67fe8
with:
controller-ref: ${{ github.ref }}
jumpstarter-ref: 28d6b1cc3b49ab9ae176918ab9709a2e2522c97e
26 changes: 25 additions & 1 deletion api/v1alpha1/exporter_helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package v1alpha1

import "strings"
import (
"strings"

cpb "github.com/jumpstarter-dev/jumpstarter-controller/internal/protocol/jumpstarter/client/v1"
"github.com/jumpstarter-dev/jumpstarter-controller/internal/service/utils"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func (e *Exporter) InternalSubject() string {
return strings.Join([]string{"exporter", e.Namespace, e.Name, string(e.UID)}, ":")
Expand All @@ -15,3 +21,21 @@ func (e *Exporter) Usernames(prefix string) []string {

return usernames
}

func (e *Exporter) ToProtobuf() *cpb.Exporter {
return &cpb.Exporter{
Name: utils.UnparseExporterIdentifier(kclient.ObjectKeyFromObject(e)),
Labels: e.Labels,
}
}

func (l *ExporterList) ToProtobuf() *cpb.ListExportersResponse {
var jexporters []*cpb.Exporter
for _, jexporter := range l.Items {
jexporters = append(jexporters, jexporter.ToProtobuf())
}
return &cpb.ListExportersResponse{
Exporters: jexporters,
NextPageToken: l.Continue,
}
}
87 changes: 87 additions & 0 deletions api/v1alpha1/lease_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,99 @@ import (
"fmt"
"time"

cpb "github.com/jumpstarter-dev/jumpstarter-controller/internal/protocol/jumpstarter/client/v1"
pb "github.com/jumpstarter-dev/jumpstarter-controller/internal/protocol/jumpstarter/v1"
"github.com/jumpstarter-dev/jumpstarter-controller/internal/service/utils"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func LeaseFromProtobuf(
req *cpb.Lease,
key types.NamespacedName,
clientRef corev1.LocalObjectReference,
) (*Lease, error) {
selector, err := metav1.ParseToLabelSelector(req.Selector)
if err != nil {
return nil, err
}

return &Lease{
ObjectMeta: metav1.ObjectMeta{
Namespace: key.Namespace,
Name: key.Name,
},
Spec: LeaseSpec{
ClientRef: clientRef,
Duration: metav1.Duration{Duration: req.Duration.AsDuration()},
Selector: *selector,
},
}, nil
}

func (l *Lease) ToProtobuf() *cpb.Lease {
var conditions []*pb.Condition
for _, condition := range l.Status.Conditions {
conditions = append(conditions, &pb.Condition{
Type: &condition.Type,
Status: (*string)(&condition.Status),
ObservedGeneration: &condition.ObservedGeneration,
LastTransitionTime: &pb.Time{
Seconds: &condition.LastTransitionTime.ProtoTime().Seconds,
Nanos: &condition.LastTransitionTime.ProtoTime().Nanos,
},
Reason: &condition.Reason,
Message: &condition.Message,
})
}

lease := cpb.Lease{
Name: fmt.Sprintf("namespaces/%s/leases/%s", l.Namespace, l.Name),
Selector: metav1.FormatLabelSelector(&l.Spec.Selector),
Duration: durationpb.New(l.Spec.Duration.Duration),
EffectiveDuration: durationpb.New(l.Spec.Duration.Duration), // TODO: implement lease renewal
Client: ptr.To(fmt.Sprintf("namespaces/%s/clients/%s", l.Namespace, l.Spec.ClientRef.Name)),
Conditions: conditions,
// TODO: implement scheduled leases
BeginTime: nil,
EndTime: nil,
}

if l.Status.BeginTime != nil {
lease.EffectiveBeginTime = timestamppb.New(l.Status.BeginTime.Time)
}
if l.Status.EndTime != nil {
lease.EffectiveEndTime = timestamppb.New(l.Status.EndTime.Time)
}
if l.Status.ExporterRef != nil {
lease.Exporter = ptr.To(utils.UnparseExporterIdentifier(kclient.ObjectKey{
Namespace: l.Namespace,
Name: l.Status.ExporterRef.Name,
}))
}

return &lease
}

func (l *LeaseList) ToProtobuf() *cpb.ListLeasesResponse {
var jleases []*cpb.Lease
for _, jlease := range l.Items {
jleases = append(jleases, jlease.ToProtobuf())
}
return &cpb.ListLeasesResponse{
Leases: jleases,
NextPageToken: l.Continue,
}
}

func (l *Lease) GetExporterSelector() (labels.Selector, error) {
return metav1.LabelSelectorAsSelector(&l.Spec.Selector)
}
Expand Down
Loading