GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cli/cmd/events.go at main · PastureStack/cli

Expand file tree

/

events.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
100 lines (88 loc) · 2.14 KB
/

events.go

Copy path

File metadata and controls

100 lines (88 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package cmd
import (
"fmt"
"time"
cli "github.com/PastureStack/cli/internal/legacycli"
"github.com/PastureStack/cli/internal/rancherclient/v2"
"github.com/PastureStack/cli/monitor"
"github.com/sirupsen/logrus"
)
func EventsCommand() cli.Command {
return cli.Command{
Name: "events",
ShortName: "event",
Usage: "Displays resource change events",
Description: "\nOnly events that are actively occurring in the compatible control platform are listed.\n",
ArgsUsage: "None",
Action: events,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "'json' or Custom format: '{{.Name}} {{.Data.resource.kind}}'",
},
cli.BoolFlag{
Name: "reconnect,r",
Usage: "Reconnect on error",
},
},
}
}
func getClientForSubscribe(ctx *cli.Context) (*client.RancherClient, error) {
if ctx.Bool("all") {
return GetRawClient(ctx)
}
return GetClient(ctx)
}
func events(ctx *cli.Context) error {
reconnect := ctx.Bool("reconnect")
for {
c, err := getClientForSubscribe(ctx)
if err != nil {
if reconnect {
logrus.Error(err)
time.Sleep(time.Second)
continue
} else {
return err
}
}
m := monitor.New(c)
sub := m.Subscribe()
go func() {
if ctx.Bool("reconnect") {
for {
if err := m.Start(); err != nil {
logrus.Error(err)
}
time.Sleep(time.Second)
}
} else {
logrus.Fatal(m.Start())
}
}()
format := ctx.String("format")
for event := range sub.C {
if format == "" {
resource, _ := event.Data["resource"].(map[string]interface{})
name, _ := resource["name"].(string)
if name == "ping" {
continue
}
healthState, _ := resource["healthState"].(string)
state, _ := resource["state"].(string)
combined := healthState
if state != "active" || combined == "" {
combined = state
}
message, _ := resource["transitioningMessage"].(string)
fmt.Printf("%s %s %s [%s] %v\n", event.ResourceType, event.ResourceID, combined, name, message)
} else {
writer := NewTableWriter(nil, ctx)
writer.Write(event)
if err := writer.Err(); err != nil {
logrus.Error(err)
}
}
}
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.