From bfa7393dbf329741c9c40202e8c11e9a9b21f2f0 Mon Sep 17 00:00:00 2001 From: sujeet01 Date: Wed, 14 Aug 2024 14:21:29 +0530 Subject: [PATCH] Add ListEvents implementation in bucket server with empty events until Rook emits bucket events --- go.mod | 4 +-- go.sum | 8 +++--- internal/bucketserver/event_list.go | 44 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 internal/bucketserver/event_list.go diff --git a/go.mod b/go.mod index 0c3c991c..e4298db0 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/gogo/protobuf v1.3.2 github.com/google/addlicense v1.1.1 github.com/ironcore-dev/controller-utils v0.9.3 - github.com/ironcore-dev/ironcore v0.1.3-0.20240724061641-c2f923ef40eb + github.com/ironcore-dev/ironcore v0.1.3-0.20240812224701-1ee4dbcb5f92 github.com/ironcore-dev/ironcore-image v0.2.1 github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1 github.com/onsi/ginkgo/v2 v2.20.0 @@ -119,7 +119,7 @@ require ( golang.org/x/net v0.28.0 // indirect golang.org/x/oauth2 v0.20.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.23.0 // indirect + golang.org/x/sys v0.24.0 // indirect golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.5.0 // indirect diff --git a/go.sum b/go.sum index 947be6a8..6c91b621 100644 --- a/go.sum +++ b/go.sum @@ -565,8 +565,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/ironcore-dev/controller-utils v0.9.3 h1:sTrnxSzX5RrLf4B8KrAH2axSC+gxfJXphkV6df2GSsw= github.com/ironcore-dev/controller-utils v0.9.3/go.mod h1:djKnxDs0Hwxhhc0VmVY8tZnrOrElvrRV2jov/LiCZ2Y= -github.com/ironcore-dev/ironcore v0.1.3-0.20240724061641-c2f923ef40eb h1:eiZSYhN3tW7P0lN007/vs6hPDzzQx9YVAAVh2QMBU0Y= -github.com/ironcore-dev/ironcore v0.1.3-0.20240724061641-c2f923ef40eb/go.mod h1:OAq8mJxuR76Lq7HQDMwB11cWJrb/76nX1wBrXQfMrOw= +github.com/ironcore-dev/ironcore v0.1.3-0.20240812224701-1ee4dbcb5f92 h1:kGJzqRrBDG612VjRe9P42uh/Vwg7cV8T4wc1ytZBgCQ= +github.com/ironcore-dev/ironcore v0.1.3-0.20240812224701-1ee4dbcb5f92/go.mod h1:xnLsVe5zP9a0qZOH+KcKbJ5HUA51tRXc3PbNHGQnOrA= github.com/ironcore-dev/ironcore-image v0.2.1 h1:7LsIftIRX5btnSieo1J+xUSnW1tSIsGzYgD6NnpObyY= github.com/ironcore-dev/ironcore-image v0.2.1/go.mod h1:BNaacvN5++9zGiTDJea4vvGDwHvPJE6S9Xb3G7hsFQU= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -1189,8 +1189,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/internal/bucketserver/event_list.go b/internal/bucketserver/event_list.go new file mode 100644 index 00000000..01d45ea9 --- /dev/null +++ b/internal/bucketserver/event_list.go @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +package bucketserver + +import ( + "context" + + iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" + irievent "github.com/ironcore-dev/ironcore/iri/apis/event/v1alpha1" + "k8s.io/apimachinery/pkg/labels" +) + +func (s *Server) filterEvents(events []*irievent.Event, filter *iri.EventFilter) []*irievent.Event { + if filter == nil { + return events + } + + var ( + res []*irievent.Event + sel = labels.SelectorFromSet(filter.LabelSelector) + ) + for _, iriEvent := range events { + if !sel.Matches(labels.Set(iriEvent.Spec.InvolvedObjectMeta.Labels)) { + continue + } + + if filter.EventsFromTime > 0 && filter.EventsToTime > 0 { + if iriEvent.Spec.EventTime < filter.EventsFromTime || iriEvent.Spec.EventTime > filter.EventsToTime { + continue + } + } + + res = append(res, iriEvent) + } + return res +} + +func (s *Server) ListEvents(ctx context.Context, req *iri.ListEventsRequest) (*iri.ListEventsResponse, error) { + //TODO: Implement actual event listing once Rook starts emitting bucket events + return &iri.ListEventsResponse{ + Events: []*irievent.Event{}, + }, nil +}