Conversation
Signed-off-by: Justin Chadwell <justin@unikraft.com>
There was a problem hiding this comment.
Pull request overview
Adds CLI support for “delete-on-stop” instances (Docker-like --rm), and adjusts stop/restart UX to handle instances that disappear immediately after stopping.
Changes:
- Add
--rmtounikraft instance create, mapping it to the platformdelete_on_stopfeature. - Update
instance stop/instance restartto tolerate “not found” after stop/start when delete-on-stop removes instances, aiming to show a meaningful diff. - Add a new golden test and update help output to cover
--rm.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/cmd/instances.go | Adds --rm handling on create; adjusts stop/restart flows to treat not-found as deletion for diff output. |
| cmd/unikraft/testdata/TestGolden/instances/rm | New golden transcript verifying --rm causes deletion after stop. |
| cmd/unikraft/testdata/TestGolden/instances/help | Updates help golden output to include the new --rm flag. |
| cmd/unikraft/instances_test.go | Adds a new golden test case exercising instance create --rm + instance stop. |
Comments suppressed due to low confidence (1)
internal/cmd/instances.go:1297
- In
InstancesRestartCmd.Run, whenstartInstancesreturnslen(started)==0due to delete-on-stop (andstartErrisgroup.ErrRefNotFound), the code proceeds but then buildskeySetfromstarted(empty) and fetchesupdatedusingstarted.Strings()(also empty). This causesbeforeto be filtered down to empty and the diff to show no deletions, which contradicts the intent in the preceding comment. Consider usingstopped(or the originaltargetKeys) as the key set for diffing, and skip theGetcall when there are no started instances so the diff can reflect the instances being removed.
started, startErr := startInstances(ctx, g, stopped)
opErr = errors.Join(opErr, startErr)
// If all stopped instances were removed (e.g. by delete-on-stop)
// before they could be restarted, show a diff reflecting the
// deletion instead of returning a confusing error.
if len(started) == 0 {
var refErr group.ErrRefNotFound
if startErr == nil || !errors.As(startErr, &refErr) {
return opErr
}
}
updated, getErr := Instance{}.Get(ctx, started.Strings())
// Same as above: tolerate not-found when delete-on-stop already
// removed the instances.
if getErr != nil && len(updated) == 0 {
var refErr group.ErrRefNotFound
if !errors.As(getErr, &refErr) {
opErr = errors.Join(opErr, getErr)
return opErr
}
} else {
opErr = errors.Join(opErr, getErr)
}
keySet := make(map[string]struct{}, len(started))
for _, k := range started {
keySet[k.Canonical()] = struct{}{}
}
before = slices.DeleteFunc(slices.Clone(before), func(r resource.Resource) bool {
_, ok := keySet[r.Key().Canonical()]
return !ok
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // If all stopped instances were removed (e.g. by delete-on-stop) | ||
| // before they could be restarted, show a diff reflecting the | ||
| // deletion instead of returning a confusing error. | ||
| if len(started) == 0 { | ||
| return opErr | ||
| var refErr group.ErrRefNotFound | ||
| if startErr == nil || !errors.As(startErr, &refErr) { | ||
| return opErr | ||
| } | ||
| } |
There was a problem hiding this comment.
The new delete-on-stop tolerance path in InstancesRestartCmd.Run (handling group.ErrRefNotFound when startInstances/Get can’t find instances) isn’t covered by the golden CLI tests. Adding a test similar to the new rm stop test but exercising unikraft instance restart --rm (or restarting an instance created with --rm) would help prevent regressions.
Fixes https://linear.app/unikraft/issue/TOOL-823/add-cli-support-for-delete-on-stop.