Skip to content

Commit eb65c72

Browse files
committed
backend
1 parent f2f0237 commit eb65c72

File tree

9 files changed

+235
-102
lines changed

9 files changed

+235
-102
lines changed

agent/agentcontainers/api.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
486486
// Check if the container is running and update the known devcontainers.
487487
for i := range updated.Containers {
488488
container := &updated.Containers[i] // Grab a reference to the container to allow mutating it.
489-
container.DevcontainerStatus = "" // Reset the status for the container (updated later).
490-
container.DevcontainerDirty = false // Reset dirty state for the container (updated later).
491489

492490
workspaceFolder := container.Labels[DevcontainerLocalFolderLabel]
493491
configFile := container.Labels[DevcontainerConfigFileLabel]
@@ -568,8 +566,6 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
568566
// TODO(mafredri): Parse the container label (i.e. devcontainer.json) for customization.
569567
dc.Name = safeFriendlyName(dc.Container.FriendlyName)
570568
}
571-
dc.Container.DevcontainerStatus = dc.Status
572-
dc.Container.DevcontainerDirty = dc.Dirty
573569
}
574570

575571
switch {
@@ -584,13 +580,11 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
584580
if dc.Container.Running {
585581
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusRunning
586582
}
587-
dc.Container.DevcontainerStatus = dc.Status
588583

589584
dc.Dirty = false
590585
if lastModified, hasModTime := api.configFileModifiedTimes[dc.ConfigPath]; hasModTime && dc.Container.CreatedAt.Before(lastModified) {
591586
dc.Dirty = true
592587
}
593-
dc.Container.DevcontainerDirty = dc.Dirty
594588

595589
if _, injected := api.injectedSubAgentProcs[dc.Container.ID]; !injected && dc.Status == codersdk.WorkspaceAgentDevcontainerStatusRunning {
596590
err := api.injectSubAgentIntoContainerLocked(ctx, dc)
@@ -661,9 +655,19 @@ func (api *API) getContainers() (codersdk.WorkspaceAgentListContainersResponse,
661655
if api.containersErr != nil {
662656
return codersdk.WorkspaceAgentListContainersResponse{}, api.containersErr
663657
}
658+
659+
devcontainers := make([]codersdk.WorkspaceAgentDevcontainer, 0, len(api.knownDevcontainers))
660+
for _, dc := range api.knownDevcontainers {
661+
devcontainers = append(devcontainers, dc)
662+
}
663+
slices.SortFunc(devcontainers, func(a, b codersdk.WorkspaceAgentDevcontainer) int {
664+
return strings.Compare(a.ID.String(), b.ID.String())
665+
})
666+
664667
return codersdk.WorkspaceAgentListContainersResponse{
665-
Containers: slices.Clone(api.containers.Containers),
666-
Warnings: slices.Clone(api.containers.Warnings),
668+
Devcontainers: devcontainers,
669+
Containers: slices.Clone(api.containers.Containers),
670+
Warnings: slices.Clone(api.containers.Warnings),
667671
}, nil
668672
}
669673

@@ -740,9 +744,6 @@ func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Reques
740744
// Update the status so that we don't try to recreate the
741745
// devcontainer multiple times in parallel.
742746
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStarting
743-
if dc.Container != nil {
744-
dc.Container.DevcontainerStatus = dc.Status
745-
}
746747
api.knownDevcontainers[dc.WorkspaceFolder] = dc
747748
api.asyncWg.Add(1)
748749
go api.recreateDevcontainer(dc, configPath)
@@ -815,9 +816,6 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
815816
api.mu.Lock()
816817
dc = api.knownDevcontainers[dc.WorkspaceFolder]
817818
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusError
818-
if dc.Container != nil {
819-
dc.Container.DevcontainerStatus = dc.Status
820-
}
821819
api.knownDevcontainers[dc.WorkspaceFolder] = dc
822820
api.recreateErrorTimes[dc.WorkspaceFolder] = api.clock.Now("agentcontainers", "recreate", "errorTimes")
823821
api.mu.Unlock()
@@ -838,7 +836,6 @@ func (api *API) recreateDevcontainer(dc codersdk.WorkspaceAgentDevcontainer, con
838836
if dc.Container.Running {
839837
dc.Status = codersdk.WorkspaceAgentDevcontainerStatusRunning
840838
}
841-
dc.Container.DevcontainerStatus = dc.Status
842839
}
843840
dc.Dirty = false
844841
api.recreateSuccessTimes[dc.WorkspaceFolder] = api.clock.Now("agentcontainers", "recreate", "successTimes")
@@ -914,10 +911,6 @@ func (api *API) markDevcontainerDirty(configPath string, modifiedAt time.Time) {
914911
logger.Info(api.ctx, "marking devcontainer as dirty")
915912
dc.Dirty = true
916913
}
917-
if dc.Container != nil && !dc.Container.DevcontainerDirty {
918-
logger.Info(api.ctx, "marking devcontainer container as dirty")
919-
dc.Container.DevcontainerDirty = true
920-
}
921914

922915
api.knownDevcontainers[dc.WorkspaceFolder] = dc
923916
}

agent/agentcontainers/api_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ func TestAPI(t *testing.T) {
592592
require.Len(t, resp.Devcontainers, 1, "expected one devcontainer in response")
593593
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusStarting, resp.Devcontainers[0].Status, "devcontainer is not starting")
594594
require.NotNil(t, resp.Devcontainers[0].Container, "devcontainer should have container reference")
595-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusStarting, resp.Devcontainers[0].Container.DevcontainerStatus, "container dc status is not starting")
596595

597596
// Allow the devcontainer CLI to continue the up process.
598597
close(tt.devcontainerCLI.upErrC)
@@ -620,7 +619,6 @@ func TestAPI(t *testing.T) {
620619
require.Len(t, resp.Devcontainers, 1, "expected one devcontainer in response after error")
621620
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusError, resp.Devcontainers[0].Status, "devcontainer is not in an error state after up failure")
622621
require.NotNil(t, resp.Devcontainers[0].Container, "devcontainer should have container reference after up failure")
623-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusError, resp.Devcontainers[0].Container.DevcontainerStatus, "container dc status is not error after up failure")
624622
return
625623
}
626624

@@ -645,7 +643,6 @@ func TestAPI(t *testing.T) {
645643
require.Len(t, resp.Devcontainers, 1, "expected one devcontainer in response after recreation")
646644
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, resp.Devcontainers[0].Status, "devcontainer is not running after recreation")
647645
require.NotNil(t, resp.Devcontainers[0].Container, "devcontainer should have container reference after recreation")
648-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, resp.Devcontainers[0].Container.DevcontainerStatus, "container dc status is not running after recreation")
649646
})
650647
}
651648
})
@@ -740,7 +737,6 @@ func TestAPI(t *testing.T) {
740737
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, dc.Status)
741738
require.NotNil(t, dc.Container)
742739
assert.Equal(t, "runtime-container-1", dc.Container.ID)
743-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, dc.Container.DevcontainerStatus)
744740
},
745741
},
746742
{
@@ -785,10 +781,8 @@ func TestAPI(t *testing.T) {
785781

786782
require.NotNil(t, known1.Container)
787783
assert.Equal(t, "known-container-1", known1.Container.ID)
788-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, known1.Container.DevcontainerStatus)
789784
require.NotNil(t, runtime1.Container)
790785
assert.Equal(t, "runtime-container-1", runtime1.Container.ID)
791-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, runtime1.Container.DevcontainerStatus)
792786
},
793787
},
794788
{
@@ -828,11 +822,9 @@ func TestAPI(t *testing.T) {
828822

829823
require.NotNil(t, running.Container, "running container should have container reference")
830824
assert.Equal(t, "running-container", running.Container.ID)
831-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, running.Container.DevcontainerStatus)
832825

833826
require.NotNil(t, nonRunning.Container, "non-running container should have container reference")
834827
assert.Equal(t, "non-running-container", nonRunning.Container.ID)
835-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusStopped, nonRunning.Container.DevcontainerStatus)
836828
},
837829
},
838830
{
@@ -868,7 +860,6 @@ func TestAPI(t *testing.T) {
868860
assert.NotEmpty(t, dc2.ConfigPath)
869861
require.NotNil(t, dc2.Container)
870862
assert.Equal(t, "known-container-2", dc2.Container.ID)
871-
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, dc2.Container.DevcontainerStatus)
872863
},
873864
},
874865
{
@@ -1166,8 +1157,6 @@ func TestAPI(t *testing.T) {
11661157
"devcontainer should not be marked as dirty initially")
11671158
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, response.Devcontainers[0].Status, "devcontainer should be running initially")
11681159
require.NotNil(t, response.Devcontainers[0].Container, "container should not be nil")
1169-
assert.False(t, response.Devcontainers[0].Container.DevcontainerDirty,
1170-
"container should not be marked as dirty initially")
11711160

11721161
// Verify the watcher is watching the config file.
11731162
assert.Contains(t, fWatcher.addedPaths, configPath,
@@ -1201,8 +1190,6 @@ func TestAPI(t *testing.T) {
12011190
"container should be marked as dirty after config file was modified")
12021191
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, response.Devcontainers[0].Status, "devcontainer should be running after config file was modified")
12031192
require.NotNil(t, response.Devcontainers[0].Container, "container should not be nil")
1204-
assert.True(t, response.Devcontainers[0].Container.DevcontainerDirty,
1205-
"container should be marked as dirty after config file was modified")
12061193

12071194
container.ID = "new-container-id" // Simulate a new container ID after recreation.
12081195
container.FriendlyName = "new-container-name"
@@ -1227,8 +1214,6 @@ func TestAPI(t *testing.T) {
12271214
"dirty flag should be cleared on the devcontainer after container recreation")
12281215
assert.Equal(t, codersdk.WorkspaceAgentDevcontainerStatusRunning, response.Devcontainers[0].Status, "devcontainer should be running after recreation")
12291216
require.NotNil(t, response.Devcontainers[0].Container, "container should not be nil")
1230-
assert.False(t, response.Devcontainers[0].Container.DevcontainerDirty,
1231-
"dirty flag should be cleared on the container after container recreation")
12321217
})
12331218

12341219
t.Run("SubAgentLifecycle", func(t *testing.T) {

coderd/apidoc/docs.go

Lines changed: 39 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 39 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaceagents_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,15 +1403,13 @@ func TestWorkspaceAgentRecreateDevcontainer(t *testing.T) {
14031403
agentcontainers.DevcontainerConfigFileLabel: configFile,
14041404
}
14051405
devContainer = codersdk.WorkspaceAgentContainer{
1406-
ID: uuid.NewString(),
1407-
CreatedAt: dbtime.Now(),
1408-
FriendlyName: testutil.GetRandomName(t),
1409-
Image: "busybox:latest",
1410-
Labels: dcLabels,
1411-
Running: true,
1412-
Status: "running",
1413-
DevcontainerDirty: true,
1414-
DevcontainerStatus: codersdk.WorkspaceAgentDevcontainerStatusRunning,
1406+
ID: uuid.NewString(),
1407+
CreatedAt: dbtime.Now(),
1408+
FriendlyName: testutil.GetRandomName(t),
1409+
Image: "busybox:latest",
1410+
Labels: dcLabels,
1411+
Running: true,
1412+
Status: "running",
14151413
}
14161414
plainContainer = codersdk.WorkspaceAgentContainer{
14171415
ID: uuid.NewString(),

codersdk/workspaceagents.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,6 @@ type WorkspaceAgentContainer struct {
450450
// Volumes is a map of "things" mounted into the container. Again, this
451451
// is somewhat implementation-dependent.
452452
Volumes map[string]string `json:"volumes"`
453-
// DevcontainerStatus is the status of the devcontainer, if this
454-
// container is a devcontainer. This is used to determine if the
455-
// devcontainer is running, stopped, starting, or in an error state.
456-
DevcontainerStatus WorkspaceAgentDevcontainerStatus `json:"devcontainer_status,omitempty"`
457-
// DevcontainerDirty is true if the devcontainer configuration has changed
458-
// since the container was created. This is used to determine if the
459-
// container needs to be rebuilt.
460-
DevcontainerDirty bool `json:"devcontainer_dirty"`
461453
}
462454

463455
func (c *WorkspaceAgentContainer) Match(idOrName string) bool {
@@ -486,6 +478,8 @@ type WorkspaceAgentContainerPort struct {
486478
// WorkspaceAgentListContainersResponse is the response to the list containers
487479
// request.
488480
type WorkspaceAgentListContainersResponse struct {
481+
// Devcontainers is a list of devcontainers visible to the workspace agent.
482+
Devcontainers []WorkspaceAgentDevcontainer `json:"devcontainers"`
489483
// Containers is a list of containers visible to the workspace agent.
490484
Containers []WorkspaceAgentContainer `json:"containers"`
491485
// Warnings is a list of warnings that may have occurred during the

0 commit comments

Comments
 (0)