Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Always return event details
Browse files Browse the repository at this point in the history
- update event backend s.t. list and watch always return event details
- remove the `--details` flag from the `acorn events` sub-command
- maintain compatibility by ignoring the `details` field
  selector on the server (old client -> new server) and always
  requesting details in the client (new client -> old server)

Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Jul 10, 2023
1 parent 206cf11 commit 8777fb7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
11 changes: 2 additions & 9 deletions pkg/cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ func NewEvent(c CommandContext) *cobra.Command {
# Get a single event by name
acorn events 4b2ba097badf2031c4718609b9179fb5
# Getting Details
# The 'details' field provides additional information about an event.
# By default, this field is elided from this command's output, but can be enabled via the '--details' flag.
# This flag must be used in conjunction with a non-table output format, like '-o=yaml'.
acorn events --details -o yaml
`})
return cmd
}
Expand All @@ -71,9 +65,8 @@ func (e *Events) Run(cmd *cobra.Command, args []string) error {
}

opts := &client.EventStreamOptions{
Tail: e.Tail,
Follow: e.Follow,
Details: e.Details,
Tail: e.Tail,
Follow: e.Follow,
}

if len(args) > 0 {
Expand Down
7 changes: 3 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ type ContainerReplicaListOptions struct {
type EventStreamOptions struct {
Tail int `json:"tail,omitempty"`
Follow bool `json:"follow,omitempty"`
Details bool `json:"details,omitempty"`
Prefix string `json:"prefix,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
}
Expand All @@ -338,9 +337,9 @@ func (o EventStreamOptions) ListOptions() *kclient.ListOptions {
if o.Prefix != "" {
fieldSet["prefix"] = o.Prefix
}
if o.Details {
fieldSet["details"] = strconv.FormatBool(o.Details)
}

// Set details selector to get details from older runtime APIs that don't return details by default.
fieldSet["details"] = strconv.FormatBool(true)

return &kclient.ListOptions{
Limit: int64(o.Tail),
Expand Down
17 changes: 5 additions & 12 deletions pkg/server/registry/apigroups/acorn/events/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"sort"
"strconv"
"strings"

"github.com/acorn-io/mink/pkg/strategy"
Expand Down Expand Up @@ -62,10 +61,6 @@ func (s *eventStrategy) List(ctx context.Context, namespace string, opts storage
}

type query struct {
// details determines if the details field is elided from query results.
// If true keep details, otherwise strip them.
details bool

// tail when > 0, determines the number of latest events to return.
tail int64

Expand Down Expand Up @@ -137,8 +132,8 @@ func (q query) filter(events ...apiv1.Event) []apiv1.Event {
tail = int(q.tail)
}

if q.details && q.prefix.all() {
// Query selects all remaining events and includes details
if q.prefix.all() {
// Query selects all remaining events
return events[len(events)-tail:]
}

Expand All @@ -149,10 +144,6 @@ func (q query) filter(events ...apiv1.Event) []apiv1.Event {
continue
}

if !q.details {
event.Details = nil
}

results = append(results, event)
}

Expand All @@ -171,7 +162,9 @@ func stripQuery(opts storage.ListOptions) (q query, stripped storage.ListOptions
var err error
switch f {
case "details":
q.details, err = strconv.ParseBool(v)
// Detail elision is deprecated, so clients should always get details.
// We still strip it from the selector here in order to maintain limited backwards compatibility with old
// clients that still specify it.
case "prefix":
q.prefix = prefix(v)
default:
Expand Down

0 comments on commit 8777fb7

Please sign in to comment.