fix: remove stale instance entry on recreate and guard stop against missing containers - #468
Syedowais312 wants to merge 2 commits into
Conversation
|
Matching by |
f3b0073 to
700e6db
Compare
i have added appropriate test cases in pkg/config/localconfig_test.go |
|
Thanks for adding tests after the earlier review feedback. One thing I want to call out: the PR title mentions “guard stop against missing containers”, but I don’t see an actual missing-container guard added in
|
a859375 to
700e6db
Compare
a5e72de to
cd4b467
Compare
sorry i missed it earlier. |
060992b to
6a740ad
Compare
Vaishnav88sk
left a comment
There was a problem hiding this comment.
Please resolve that. After that LGTM. 👍🏻
6a740ad to
80c3d0c
Compare
|
Thanks @Syedowais312 The reconcile logic on master resets the stale entry in place (Status/ContainerID cleared, then reused) rather than appending a new record — see the "Reconcile before trusting it" block in cmd/start.go. Could you re-verify duplicates still accumulate on a current build? If not, this can be closed. |
Hey @Caesarsage, I pulled the latest The reason is around this line: Line 102 in 0dd8f55 Here we clear But the old instance entry is still present in the config with the old container ID. Later, In this PR, I removed the stale instance before recreating it. I also changed |
80c3d0c to
55ef2cc
Compare
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
55ef2cc to
1fcfbe3
Compare
|
Hey, I've rebased the branch onto the latest master. Could you take a look when you get a chance? |
e15e697 to
987b4b5
Compare
| if !exists { | ||
| fmt.Printf("Container for instance %s no longer exists\n", instance.Name) | ||
| fmt.Printf("Run 'microcks start --name %s' to bring the container back\n", instance.Name) | ||
| return nil | ||
| } else { | ||
| if err := containerClient.StopContainer(instance.ContainerID); err != nil { | ||
| return errors.Wrap(errors.KindEnvironment, fmt.Errorf("failed to stop container: %w", err)) | ||
| } | ||
| fmt.Println("") | ||
| log.Printf("Instance %s stopped successfully", instance.Name) |
There was a problem hiding this comment.
Almost there! Thanks for moving StopContainer to the else block.
However, the return nil and the 'Run microcks start to bring it back' print statement are still inside the if !exists block. Because of that return nil, the code still exits early and skips the // update configs section at the bottom.
Could you please remove the return nil (and optionally the second print statement) so that execution falls through to the config cleanup?
It should look exactly like this:
if !exists {
fmt.Printf("Container for instance %s no longer exists\n", instance.Name)
} else {
if err := containerClient.StopContainer(instance.ContainerID); err != nil {
return errors.Wrap(errors.KindEnvironment, fmt.Errorf("failed to stop container: %w", err))
}
fmt.Println("")
log.Printf("Instance %s stopped successfully", instance.Name)
}
// update configsThere was a problem hiding this comment.
Thanks for the review! Removed the return nil ,but I kept the second print statement since it tells the user how to bring the container back, which seemed useful for UX? or would you prefer I remove it?
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
987b4b5 to
38819db
Compare
Problem
When a container is removed externally (e.g.
docker system prune) andmicrocks startrecreates it, the old instance entry was never removed fromconfig causing duplicate instance records to accumulate on every recreate.
Two root causes:
RemoveInstancematched byName(not unique) instead ofContainerID(unique)autoRemovepath instop.gowas passinginstance.NametoRemoveInstance,silently failing to remove the correct entry
start.gowas clearinginstance.ContainerID = ""instead of callingRemoveInstanceto actually remove the stale record from configChanges
cmd/start.go: calllocalConfig.RemoveInstance(instance.ContainerID)toremove the stale record before recreating, instead of just clearing the local variable
cmd/stop.go: passinstance.ContainerIDtoRemoveInstancein theautoRemovepathpkg/config/localconfig.go:RemoveInstancenow matches byContainerIDinstead ofNameTesting
Ran
docker rm <container>while config showsstatus: Running, thenmicrocks start --name <instance>config shows a single clean entry withthe new container ID, no duplicates.
Realted: #456
Fix: #483