diff --git a/broker/machinebroker/server/event_list_test.go b/broker/machinebroker/server/event_list_test.go index 366b17dea..101e6bb8c 100644 --- a/broker/machinebroker/server/event_list_test.go +++ b/broker/machinebroker/server/event_list_test.go @@ -8,6 +8,7 @@ import ( computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1" networkingv1alpha1 "github.com/ironcore-dev/ironcore/api/networking/v1alpha1" + irievent "github.com/ironcore-dev/ironcore/iri/apis/event/v1alpha1" iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1" irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1" @@ -71,11 +72,11 @@ var _ = Describe("ListEvents", func() { eventRecorder.Event(ironcoreMachine, corev1.EventTypeNormal, "testing", "this is test event") By("listing the machine events with no filters") - resp, err := srv.ListEvents(ctx, &iri.ListEventsRequest{}) - - Expect(err).NotTo(HaveOccurred()) - - Expect(resp.Events).To(ConsistOf( + Eventually(func(g Gomega) []*irievent.Event { + resp, err := srv.ListEvents(ctx, &iri.ListEventsRequest{}) + g.Expect(err).NotTo(HaveOccurred()) + return resp.Events + }).Should(ConsistOf( HaveField("Spec", SatisfyAll( HaveField("InvolvedObjectMeta.Id", Equal(ironcoreMachine.Name)), HaveField("Reason", Equal("testing")), @@ -86,7 +87,7 @@ var _ = Describe("ListEvents", func() { ) By("listing the machine events with matching label and time filters") - resp, err = srv.ListEvents(ctx, &iri.ListEventsRequest{Filter: &iri.EventFilter{ + resp, err := srv.ListEvents(ctx, &iri.ListEventsRequest{Filter: &iri.EventFilter{ LabelSelector: map[string]string{machinepoolletv1alpha1.MachineUIDLabel: "foobar"}, EventsFromTime: eventGeneratedTime.Unix(), EventsToTime: time.Now().Unix(), diff --git a/irictl-machine/cmd/irictl-machine/irictlmachine/get/event/event.go b/irictl-machine/cmd/irictl-machine/irictlmachine/get/event/event.go index 7672c5d64..42761177c 100644 --- a/irictl-machine/cmd/irictl-machine/irictlmachine/get/event/event.go +++ b/irictl-machine/cmd/irictl-machine/irictlmachine/get/event/event.go @@ -6,6 +6,7 @@ package event import ( "context" "fmt" + "time" iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1" "github.com/ironcore-dev/ironcore/irictl-machine/cmd/irictl-machine/irictlmachine/common" @@ -17,11 +18,13 @@ import ( ) type Options struct { - Labels map[string]string + Labels map[string]string + Duration time.Duration } func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringToStringVarP(&o.Labels, "labels", "l", o.Labels, "Labels to filter the events by.") + fs.DurationVarP(&o.Duration, "duration", "d", 60*time.Minute, "Duration to filter the events by.") } func Command(streams clicommon.Streams, clientFactory common.Factory) *cobra.Command { @@ -68,11 +71,10 @@ func Run( render renderer.Renderer, opts Options, ) error { - var filter *iri.EventFilter - if opts.Labels != nil { - filter = &iri.EventFilter{ - LabelSelector: opts.Labels, - } + var filter *iri.EventFilter = &iri.EventFilter{ + LabelSelector: opts.Labels, + EventsFromTime: time.Now().Add(-1 * opts.Duration).Unix(), + EventsToTime: time.Now().Unix(), } res, err := client.ListEvents(ctx, &iri.ListEventsRequest{Filter: filter})