events

package
v2.0.0-rc.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:    "events",
	Aliases: []string{"event"},
	Usage:   "Display containerd events",
	Action: func(cliContext *cli.Context) error {
		client, ctx, cancel, err := commands.NewClient(cliContext)
		if err != nil {
			return err
		}
		defer cancel()
		eventsClient := client.EventService()
		eventsCh, errCh := eventsClient.Subscribe(ctx, cliContext.Args().Slice()...)
		for {
			var e *events.Envelope
			select {
			case e = <-eventsCh:
			case err = <-errCh:
				return err
			}
			if e != nil {
				var out []byte
				if e.Event != nil {
					v, err := typeurl.UnmarshalAny(e.Event)
					if err != nil {
						log.G(ctx).WithError(err).Warn("cannot unmarshal an event from Any")
						continue
					}
					out, err = json.Marshal(v)
					if err != nil {
						log.G(ctx).WithError(err).Warn("cannot marshal Any into JSON")
						continue
					}
				}
				if _, err := fmt.Println(
					e.Timestamp,
					e.Namespace,
					e.Topic,
					string(out),
				); err != nil {
					return err
				}
			}
		}
	},
}

Command is the cli command for displaying containerd events

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL