Skip to content

Commit

Permalink
incorporating review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ushabelgur committed Jul 22, 2024
1 parent 80893f6 commit 655b550
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions irictl-machine/cmd/irictl-machine/irictlmachine/get/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

const DefaultDuration = 60 * time.Minute

type Options struct {
Labels map[string]string
EventsFromTime string
EventsToTime string
Labels map[string]string
Duration string
}

func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringToStringVarP(&o.Labels, "labels", "l", o.Labels, "Labels to filter the events by.")
fs.StringVarP(&o.EventsFromTime, "eventsFromTime", "f", o.EventsFromTime, fmt.Sprintf("Events From Time to filter the events by. In the format of %s", time.DateTime))
fs.StringVarP(&o.EventsToTime, "eventsToTime", "t", o.EventsToTime, fmt.Sprintf("Events To Time to filter the events by. In the format of %s", time.DateTime))
fs.StringVarP(&o.Duration, "duration", "d", o.Duration, "Duration to filter the events by.")
}

func Command(streams clicommon.Streams, clientFactory common.Factory) *cobra.Command {
Expand Down Expand Up @@ -73,24 +73,20 @@ func Run(
render renderer.Renderer,
opts Options,
) error {
var filter *iri.EventFilter = &iri.EventFilter{}
var filter *iri.EventFilter = &iri.EventFilter{
EventsFromTime: time.Now().Add(-1 * DefaultDuration).Unix(),
EventsToTime: time.Now().Unix(),
}
if opts.Labels != nil {
filter.LabelSelector = opts.Labels
}
if opts.EventsFromTime != "" {
fromDate, err := time.Parse(time.DateTime, opts.EventsFromTime)
if err != nil {
return fmt.Errorf("error parsing eventsFromTime: %w", err)
}
filter.EventsFromTime = fromDate.Unix()
}

if opts.EventsToTime != "" {
toDate, err := time.Parse(time.DateTime, opts.EventsToTime)
if opts.Duration != "" {
duration, err := time.ParseDuration(opts.Duration)
if err != nil {
return fmt.Errorf("error parsing eventsToTime: %w", err)
return fmt.Errorf("error parsing Duration: %w", err)
}
filter.EventsToTime = toDate.Unix()
filter.EventsFromTime = time.Now().Add(-1 * duration).Unix()
}

res, err := client.ListEvents(ctx, &iri.ListEventsRequest{Filter: filter})
Expand Down

0 comments on commit 655b550

Please sign in to comment.