Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved irictl machine get events command #1093

Merged
merged 5 commits into from
Jul 23, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,11 +18,15 @@ import (
)

type Options struct {
Labels map[string]string
Labels map[string]string
EventsFromTime string
EventsToTime 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))
lukasfrank marked this conversation as resolved.
Show resolved Hide resolved
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))
ushabelgur marked this conversation as resolved.
Show resolved Hide resolved
}

func Command(streams clicommon.Streams, clientFactory common.Factory) *cobra.Command {
Expand Down Expand Up @@ -68,11 +73,24 @@ func Run(
render renderer.Renderer,
opts Options,
) error {
var filter *iri.EventFilter
var filter *iri.EventFilter = &iri.EventFilter{}
if opts.Labels != nil {
filter = &iri.EventFilter{
LabelSelector: opts.Labels,
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 err != nil {
return fmt.Errorf("error parsing eventsToTime: %w", err)
}
filter.EventsToTime = toDate.Unix()
}

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