-
Notifications
You must be signed in to change notification settings - Fork 2
fix(daemon): enforce shutdownAction property at runtime #88
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
e2e/tests/machineprovider/testdata/machineprovider3/.devcontainer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "Go", | ||
| "image": "ubuntu", | ||
| "shutdownAction": "none" | ||
| } |
44 changes: 44 additions & 0 deletions
44
e2e/tests/machineprovider/testdata/machineprovider3/provider.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: docker123 | ||
| version: 0.0.1 | ||
| description: |- | ||
| Devsy on Kubernetes | ||
| options: | ||
| NAMESPACE: | ||
| description: The namespace to use | ||
| default: devsy-e2e | ||
| INACTIVITY_TIMEOUT: | ||
| description: The timeout until the pod will be stopped | ||
| default: 5s | ||
| agent: | ||
| path: /usr/local/bin/devsy | ||
| inactivityTimeout: ${INACTIVITY_TIMEOUT} | ||
| exec: | ||
| shutdown: |- | ||
| kill 1 | ||
| exec: | ||
| command: |- | ||
| docker exec -i devsy-${MACHINE_ID} sh -c "${COMMAND}" | ||
| stop: |- | ||
| docker stop devsy-${MACHINE_ID} | ||
| start: |- | ||
| docker start devsy-${MACHINE_ID} | ||
| sleep 5 | ||
| status: |- | ||
| STATUS=$(docker inspect devsy-${MACHINE_ID} 2>/dev/null | ${DEVSY} helper json get "[0].State.Status" || true) | ||
| if [ -z $STATUS ]; then | ||
| echo "NOTFOUND" | ||
| else | ||
| if [ "$STATUS" = "exited" ]; then | ||
| echo "STOPPED" | ||
| elif [ "$STATUS" = "running" ]; then | ||
| echo "RUNNING" | ||
| else | ||
| echo "BUSY" | ||
| fi | ||
| fi | ||
| create: |- | ||
| docker run -d --privileged --name devsy-${MACHINE_ID} docker | ||
| docker exec devsy-${MACHINE_ID} mkdir /etc/init.d | ||
| sleep 5 | ||
| delete: |- | ||
| docker stop devsy-${MACHINE_ID} && docker rm devsy-${MACHINE_ID} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Test123 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/devsy-org/api/pkg/devsy" | ||
| "github.com/devsy-org/devsy/pkg/devcontainer/config" | ||
| provider2 "github.com/devsy-org/devsy/pkg/provider" | ||
| ) | ||
|
|
||
| func TestBuildWorkspaceDaemonConfig_ShutdownAction(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| shutdownAction string | ||
| want string | ||
| }{ | ||
| { | ||
| name: "defaults to stopContainer when empty", | ||
| shutdownAction: "", | ||
| want: "stopContainer", | ||
| }, | ||
| { | ||
| name: "preserves none", | ||
| shutdownAction: "none", | ||
| want: "none", | ||
| }, | ||
| { | ||
| name: "preserves stopContainer", | ||
| shutdownAction: "stopContainer", | ||
| want: "stopContainer", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| merged := &config.MergedDevContainerConfig{} | ||
| merged.ShutdownAction = tt.shutdownAction | ||
|
|
||
| cfg, err := BuildWorkspaceDaemonConfig( | ||
| devsy.PlatformOptions{}, | ||
| &provider2.Workspace{}, | ||
| &config.SubstitutionContext{}, | ||
| merged, | ||
| ) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if cfg.ShutdownAction != tt.want { | ||
| t.Errorf("ShutdownAction = %q, want %q", cfg.ShutdownAction, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM — e2e coverage correctly exercises the
shutdownAction: "none"path.The flow (up → stop → up →
Consistently RUNNINGfor 30s) exercises the code path that decodes the persistedDaemonConfig(includingShutdownAction) on restart, which is exactly where the new gating incmd/agent/container/daemon.goruns. The 30s window comfortably exceeds the worst-case fire time (5s timeout + 10s ticker period inrunTimeoutMonitor).One minor consideration: because
shutdownAction: "none"disables auto-stop, this test relies entirely onDevsyWorkspaceDeleteinDeferCleanupto tear the container down. If the test aborts beforeDeferCleanupruns (e.g.,SIGKILLon CI), a straydevsy-${MACHINE_ID}container could linger and interfere with later runs. Not a blocker — existing tests have the same pattern — but worth keeping in mind for CI flakiness triage.🤖 Prompt for AI Agents