7
7
"strconv"
8
8
9
9
"github.com/jedib0t/go-pretty/v6/table"
10
+ "golang.org/x/mod/semver"
10
11
11
12
"github.com/coder/coder/coderd/database"
12
13
@@ -18,6 +19,7 @@ type WorkspaceResourcesOptions struct {
18
19
HideAgentState bool
19
20
HideAccess bool
20
21
Title string
22
+ ServerVersion string
21
23
}
22
24
23
25
// WorkspaceResources displays the connection status and tree-view of provided resources.
@@ -48,6 +50,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
48
50
row := table.Row {"Resource" }
49
51
if ! options .HideAgentState {
50
52
row = append (row , "Status" )
53
+ row = append (row , "Version" )
51
54
}
52
55
if ! options .HideAccess {
53
56
row = append (row , "Access" )
@@ -91,21 +94,12 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
91
94
}
92
95
if ! options .HideAgentState {
93
96
var agentStatus string
97
+ var agentVersion string
94
98
if ! options .HideAgentState {
95
- switch agent .Status {
96
- case codersdk .WorkspaceAgentConnecting :
97
- since := database .Now ().Sub (agent .CreatedAt )
98
- agentStatus = Styles .Warn .Render ("⦾ connecting" ) + " " +
99
- Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
100
- case codersdk .WorkspaceAgentDisconnected :
101
- since := database .Now ().Sub (* agent .DisconnectedAt )
102
- agentStatus = Styles .Error .Render ("⦾ disconnected" ) + " " +
103
- Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
104
- case codersdk .WorkspaceAgentConnected :
105
- agentStatus = Styles .Keyword .Render ("⦿ connected" )
106
- }
99
+ agentStatus = renderAgentStatus (agent )
100
+ agentVersion = renderAgentVersion (agent .Version , options .ServerVersion )
107
101
}
108
- row = append (row , agentStatus )
102
+ row = append (row , agentStatus , agentVersion )
109
103
}
110
104
if ! options .HideAccess {
111
105
sshCommand := "coder ssh " + options .WorkspaceName
@@ -122,3 +116,34 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
122
116
_ , err := fmt .Fprintln (writer , tableWriter .Render ())
123
117
return err
124
118
}
119
+
120
+ func renderAgentStatus (agent codersdk.WorkspaceAgent ) string {
121
+ switch agent .Status {
122
+ case codersdk .WorkspaceAgentConnecting :
123
+ since := database .Now ().Sub (agent .CreatedAt )
124
+ return Styles .Warn .Render ("⦾ connecting" ) + " " +
125
+ Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
126
+ case codersdk .WorkspaceAgentDisconnected :
127
+ since := database .Now ().Sub (* agent .DisconnectedAt )
128
+ return Styles .Error .Render ("⦾ disconnected" ) + " " +
129
+ Styles .Placeholder .Render ("[" + strconv .Itoa (int (since .Seconds ()))+ "s]" )
130
+ case codersdk .WorkspaceAgentConnected :
131
+ return Styles .Keyword .Render ("⦿ connected" )
132
+ default :
133
+ return Styles .Warn .Render ("○ unknown" )
134
+ }
135
+ }
136
+
137
+ func renderAgentVersion (agentVersion , serverVersion string ) string {
138
+ if agentVersion == "" {
139
+ agentVersion = "(unknown)"
140
+ }
141
+ if ! semver .IsValid (serverVersion ) || ! semver .IsValid (agentVersion ) {
142
+ return Styles .Placeholder .Render (agentVersion )
143
+ }
144
+ outdated := semver .Compare (agentVersion , serverVersion ) < 0
145
+ if outdated {
146
+ return Styles .Warn .Render (agentVersion + " (outdated)" )
147
+ }
148
+ return Styles .Keyword .Render (agentVersion )
149
+ }
0 commit comments