1
// Code generated by go run tools/import_commands.go --talos-version v1.7.1 events
4
// This Source Code Form is subject to the terms of the Mozilla Public
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
6
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
19
"github.com/siderolabs/gen/xslices"
20
"github.com/spf13/cobra"
22
"github.com/siderolabs/talos/cmd/talosctl/pkg/talos/helpers"
23
"github.com/siderolabs/talos/pkg/machinery/api/machine"
24
"github.com/siderolabs/talos/pkg/machinery/client"
27
var eventsCmdFlags struct {
29
tailDuration time.Duration
35
// eventsCmd represents the events command.
36
var eventsCmd = &cobra.Command{
38
Short: "Stream runtime events",
40
RunE: func(cmd *cobra.Command, args []string) error {
41
return WithClient(func(ctx context.Context, c *client.Client) error {
42
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
43
fmt.Fprintln(w, "NODE\tID\tEVENT\tACTOR\tSOURCE\tMESSAGE")
45
opts := []client.EventsOptionFunc{}
47
if eventsCmdFlags.tailEvents != 0 {
48
opts = append(opts, client.WithTailEvents(eventsCmdFlags.tailEvents))
51
if eventsCmdFlags.tailDuration != 0 {
52
opts = append(opts, client.WithTailDuration(eventsCmdFlags.tailDuration))
55
if eventsCmdFlags.tailID != "" {
56
opts = append(opts, client.WithTailID(eventsCmdFlags.tailID))
59
if eventsCmdFlags.actorID != "" {
60
opts = append(opts, client.WithActorID(eventsCmdFlags.actorID))
63
events, err := c.Events(ctx, opts...)
68
return helpers.ReadGRPCStream(events, func(ev *machine.Event, node string, multipleNodes bool) error {
69
format := "%s\t%s\t%s\n%s\t%s\t%s\n"
71
event, err := client.UnmarshalEvent(ev)
73
if errors.Is(err, client.ErrEventNotSupported) {
80
var args []interface{}
82
switch msg := event.Payload.(type) {
83
case *machine.SequenceEvent:
84
args = []interface{}{msg.GetSequence()}
86
args = append(args, "error:"+" "+msg.GetError().GetMessage())
88
args = append(args, msg.GetAction().String())
90
case *machine.PhaseEvent:
91
args = []interface{}{msg.GetPhase(), msg.GetAction().String()}
92
case *machine.TaskEvent:
93
args = []interface{}{msg.GetTask(), msg.GetAction().String()}
94
case *machine.ServiceStateEvent:
95
args = []interface{}{msg.GetService(), fmt.Sprintf("%s: %s", msg.GetAction(), msg.GetMessage())}
96
case *machine.ConfigLoadErrorEvent:
97
args = []interface{}{"error", msg.GetError()}
98
case *machine.ConfigValidationErrorEvent:
99
args = []interface{}{"error", msg.GetError()}
100
case *machine.AddressEvent:
101
args = []interface{}{msg.GetHostname(), fmt.Sprintf("ADDRESSES: %s", strings.Join(msg.GetAddresses(), ","))}
102
case *machine.MachineStatusEvent:
103
args = []interface{}{
104
msg.GetStage().String(),
105
fmt.Sprintf("ready: %v, unmet conditions: %v",
106
msg.GetStatus().Ready,
107
xslices.Map(msg.GetStatus().GetUnmetConditions(),
108
func(c *machine.MachineStatusEvent_MachineStatus_UnmetCondition) string {
116
args = append([]interface{}{event.Node, event.ID, event.TypeURL, event.ActorID}, args...)
117
fmt.Fprintf(w, format, args...)
126
eventsCmd.Flags().StringSliceVarP(&eventsCmdFlags.configFiles,
127
"file", "f", nil, "specify config files or patches in a YAML file (can specify multiple)",
129
eventsCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
130
nodesFromArgs := len(
136
len(GlobalArgs.Endpoints) > 0
137
for _, configFile := range eventsCmdFlags.
139
if err := processModelineAndUpdateGlobals(configFile, nodesFromArgs, endpointsFromArgs, false); err != nil {
147
addCommand(eventsCmd)
148
eventsCmd.Flags().Int32Var(&eventsCmdFlags.tailEvents, "tail", 0, "show specified number of past events (use -1 to show full history, default is to show no history)")
149
eventsCmd.Flags().DurationVar(&eventsCmdFlags.tailDuration, "duration", 0, "show events for the past duration interval (one second resolution, default is to show no history)")
150
eventsCmd.Flags().StringVar(&eventsCmdFlags.tailID, "since", "", "show events after the specified event ID (default is to show no history)")
151
eventsCmd.Flags().StringVar(&eventsCmdFlags.actorID, "actor-id", "", "filter events by the specified actor ID (default is no filter)")