Skip to content

Commit

Permalink
Improved irictl machine get events command (#1093)
Browse files Browse the repository at this point in the history
ushabelgur authored Jul 23, 2024
1 parent f0a0d85 commit 8402bfa
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 7 additions & 6 deletions broker/machinebroker/server/event_list_test.go
Original file line number Diff line number Diff line change
@@ -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(),
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 8402bfa

Please sign in to comment.