-
Notifications
You must be signed in to change notification settings - Fork 288
/
view.go
126 lines (101 loc) · 3.17 KB
/
view.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
package webview
import (
"time"
"github.com/windmilleng/tilt/internal/container"
"github.com/windmilleng/tilt/internal/dockercompose"
"github.com/windmilleng/tilt/internal/k8s"
"github.com/windmilleng/tilt/internal/model"
)
type ResourceInfoView interface {
resourceInfoView()
RuntimeLog() model.Log
Status() string
}
type DCResourceInfo struct {
ConfigPath string
ContainerStatus dockercompose.Status
ContainerID container.ID
Log model.Log
StartTime time.Time
}
func NewDCResourceInfo(configPath string, status dockercompose.Status, cID container.ID, log model.Log, startTime time.Time) DCResourceInfo {
return DCResourceInfo{
ConfigPath: configPath,
ContainerStatus: status,
ContainerID: cID,
Log: log,
StartTime: startTime,
}
}
var _ ResourceInfoView = DCResourceInfo{}
func (DCResourceInfo) resourceInfoView() {}
func (dcInfo DCResourceInfo) RuntimeLog() model.Log { return dcInfo.Log }
func (dcInfo DCResourceInfo) Status() string { return string(dcInfo.ContainerStatus) }
type K8SResourceInfo struct {
PodName string
PodCreationTime time.Time
PodUpdateStartTime time.Time
PodStatus string
PodRestarts int
PodLog model.Log
YAML string
}
var _ ResourceInfoView = K8SResourceInfo{}
func (K8SResourceInfo) resourceInfoView() {}
func (k8sInfo K8SResourceInfo) RuntimeLog() model.Log { return k8sInfo.PodLog }
func (k8sInfo K8SResourceInfo) Status() string { return k8sInfo.PodStatus }
type YAMLResourceInfo struct {
K8sResources []string
}
var _ ResourceInfoView = YAMLResourceInfo{}
func (YAMLResourceInfo) resourceInfoView() {}
func (yamlInfo YAMLResourceInfo) RuntimeLog() model.Log { return model.NewLog("") }
func (yamlInfo YAMLResourceInfo) Status() string { return "" }
type Resource struct {
Name model.ManifestName
DirectoriesWatched []string
PathsWatched []string
LastDeployTime time.Time
BuildHistory []model.BuildRecord
CurrentBuild model.BuildRecord
PendingBuildReason model.BuildReason
PendingBuildEdits []string
PendingBuildSince time.Time
Endpoints []string
PodID k8s.PodID
// TODO(nick): Remove ResourceInfoView. This is fundamentally a bad
// data structure for the webview because the webview loses the Go type
// on serialization to JS.
ResourceInfo ResourceInfoView
RuntimeStatus RuntimeStatus
IsTiltfile bool
ShowBuildStatus bool // if true, we show status & time in 'Build Status'; else, "N/A"
CombinedLog model.Log
}
func (r Resource) LastBuild() model.BuildRecord {
if len(r.BuildHistory) == 0 {
return model.BuildRecord{}
}
return r.BuildHistory[0]
}
type RuntimeStatus string
const (
RuntimeStatusOK RuntimeStatus = "ok"
RuntimeStatusPending = "pending"
RuntimeStatusError = "error"
)
type View struct {
Log model.Log
Resources []Resource
LogTimestamps bool
SailEnabled bool
SailURL string
}
func (v View) Resource(n model.ManifestName) (Resource, bool) {
for _, res := range v.Resources {
if res.Name == n {
return res, true
}
}
return Resource{}, false
}