feat(agent): Add shutdown lifecycle states and shutdown_script support (#6139)

* feat(api): Add agent shutdown lifecycle states

* feat(agent): Add shutdown_script support

* feat(agent): Add shutdown_script timeout

* feat(site): Support new agent lifecycle states

---

Co-authored-by: Marcin Tojek <marcin@coder.com>
This commit is contained in:
Mathias Fredriksson
2023-03-06 21:34:00 +02:00
committed by GitHub
co-authored by Marcin Tojek
parent 02100c64b5
commit 22e3ff96be
41 changed files with 1439 additions and 635 deletions
+24 -1
View File
@@ -17,7 +17,10 @@ import (
"github.com/coder/coder/codersdk"
)
var AgentStartError = xerrors.New("agent startup exited with non-zero exit status")
var (
AgentStartError = xerrors.New("agent startup exited with non-zero exit status")
AgentShuttingDown = xerrors.New("agent is shutting down")
)
type AgentOptions struct {
WorkspaceName string
@@ -146,6 +149,10 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
case codersdk.WorkspaceAgentLifecycleStartError:
showMessage()
return AgentStartError
case codersdk.WorkspaceAgentLifecycleShuttingDown, codersdk.WorkspaceAgentLifecycleShutdownTimeout,
codersdk.WorkspaceAgentLifecycleShutdownError, codersdk.WorkspaceAgentLifecycleOff:
showMessage()
return AgentShuttingDown
default:
select {
case <-warningShown:
@@ -229,6 +236,22 @@ func waitingMessage(agent codersdk.WorkspaceAgent, opts AgentOptions) (m *messag
m.Spin = ""
m.Prompt = "The workspace ran into a problem while getting ready, the agent startup script exited with non-zero status."
default:
switch agent.LifecycleState {
case codersdk.WorkspaceAgentLifecycleShutdownTimeout:
m.Spin = ""
m.Prompt = "The workspace is shutting down, but is taking longer than expected to shut down and the agent shutdown script is still executing."
m.Troubleshoot = true
case codersdk.WorkspaceAgentLifecycleShutdownError:
m.Spin = ""
m.Prompt = "The workspace ran into a problem while shutting down, the agent shutdown script exited with non-zero status."
m.Troubleshoot = true
case codersdk.WorkspaceAgentLifecycleShuttingDown:
m.Spin = ""
m.Prompt = "The workspace is shutting down."
case codersdk.WorkspaceAgentLifecycleOff:
m.Spin = ""
m.Prompt = "The workspace is not running."
}
// Not a failure state, no troubleshooting necessary.
return m
}