-
Notifications
You must be signed in to change notification settings - Fork 303
/
actions.go
149 lines (115 loc) · 3.08 KB
/
actions.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package store
import (
"fmt"
"time"
"github.com/tilt-dev/wmclient/pkg/analytics"
v1 "k8s.io/api/core/v1"
"github.com/tilt-dev/tilt/pkg/logger"
"github.com/tilt-dev/tilt/pkg/model"
"github.com/tilt-dev/tilt/pkg/model/logstore"
)
type ErrorAction struct {
Error error
}
func (ErrorAction) Action() {}
func NewErrorAction(err error) ErrorAction {
return ErrorAction{Error: err}
}
type LogAction struct {
mn model.ManifestName
spanID logstore.SpanID
timestamp time.Time
fields logger.Fields
msg []byte
level logger.Level
}
func (LogAction) Action() {}
func (LogAction) Summarize(s *ChangeSummary) {
s.Log = true
}
func (le LogAction) ManifestName() model.ManifestName {
return le.mn
}
func (le LogAction) Level() logger.Level {
return le.level
}
func (le LogAction) Time() time.Time {
return le.timestamp
}
func (le LogAction) Fields() logger.Fields {
return le.fields
}
func (le LogAction) Message() []byte {
return le.msg
}
func (le LogAction) SpanID() logstore.SpanID {
return le.spanID
}
func (le LogAction) String() string {
return fmt.Sprintf("manifest: %s, spanID: %s, msg: %q", le.mn, le.spanID, le.msg)
}
func NewLogAction(mn model.ManifestName, spanID logstore.SpanID, level logger.Level, fields logger.Fields, b []byte) LogAction {
return LogAction{
mn: mn,
spanID: spanID,
level: level,
timestamp: time.Now(),
msg: append([]byte{}, b...),
fields: fields,
}
}
func NewGlobalLogAction(level logger.Level, b []byte) LogAction {
return LogAction{
mn: "",
spanID: "",
level: level,
timestamp: time.Now(),
msg: append([]byte{}, b...),
}
}
type K8sEventAction struct {
Event *v1.Event
ManifestName model.ManifestName
}
func (K8sEventAction) Action() {}
func NewK8sEventAction(event *v1.Event, manifestName model.ManifestName) K8sEventAction {
return K8sEventAction{event, manifestName}
}
func (kEvt K8sEventAction) ToLogAction(mn model.ManifestName) LogAction {
msg := fmt.Sprintf("[K8s EVENT: %s] %s\n",
objRefHumanReadable(kEvt.Event.InvolvedObject), kEvt.Event.Message)
return LogAction{
mn: mn,
spanID: logstore.SpanID(fmt.Sprintf("events:%s", mn)),
level: logger.InfoLvl,
timestamp: kEvt.Event.LastTimestamp.Time,
msg: []byte(msg),
}
}
func objRefHumanReadable(obj v1.ObjectReference) string {
s := fmt.Sprintf("%s %s", obj.Kind, obj.Name)
if obj.Namespace != "" {
s += fmt.Sprintf(" (ns: %s)", obj.Namespace)
}
return s
}
type AnalyticsUserOptAction struct {
Opt analytics.Opt
}
func (AnalyticsUserOptAction) Action() {}
type AnalyticsNudgeSurfacedAction struct{}
func (AnalyticsNudgeSurfacedAction) Action() {}
type TiltCloudStatusReceivedAction struct {
Found bool
Username string
TeamName string
IsPostRegistrationLookup bool
SuggestedTiltVersion string
}
func (TiltCloudStatusReceivedAction) Action() {}
type UserStartedTiltCloudRegistrationAction struct{}
func (UserStartedTiltCloudRegistrationAction) Action() {}
type PanicAction struct {
Err error
}
func (PanicAction) Action() {}