Skip to content

fix(agent/agentcontainers): remove deleted devcontainers #18545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,19 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
}

case dc.Container == nil:
if !api.devcontainerNames[dc.Name] {
dc.Name = ""
if !api.devcontainerNames[dc.Name] { // TODO(mafredri): Change this, not stable after https://github.com/coder/coder/pull/18513
// If this is a runtime-detected container, check if we
// should remove it.
// TODO(mafredri): Consider using afero.
if _, err := os.Stat(dc.WorkspaceFolder); errors.Is(err, os.ErrNotExist) {
// If the workspace folder doesn't exist, we can assume
// that the devcontainer is no longer valid and should be
// removed.
logger.Debug(ctx, "devcontainer workspace folder does not exist, removing devcontainer")
delete(api.knownDevcontainers, dc.WorkspaceFolder)
// TODO(mafredri): Delete the agent if it exists.
continue
}
}
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStopped
dc.Dirty = false
Expand Down
Loading