Skip to content

Commit 75693af

Browse files
committed
fix: remove stale instance entry on recreate and guard stop against missing containers
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
1 parent 5941830 commit 75693af

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ microcks start --name [name of you container/instance]`,
6666
errors.CheckError(err)
6767
if !exists {
6868
fmt.Printf("Container for instance %s no longer exists, recreating it\n", name)
69+
localConfig.RemoveInstance(instance.ContainerID)
6970
instance.Status = ""
70-
instance.ContainerID = ""
7171
}
7272
}
7373

cmd/stop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewStopCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
5959
_ = localConfig.RemoveServer(ctx.Server.Server)
6060
_ = localConfig.RemoveUser(ctx.User.Name)
6161
_ = localConfig.RemoveAuth(ctx.Server.Server)
62-
_ = localConfig.RemoveInstance(instance.Name)
62+
_ = localConfig.RemoveInstance(instance.ContainerID)
6363

6464
localConfig.CurrentContext = ""
6565
log.Printf("Instance %s removed successfully", instance.Name)

pkg/config/localconfig.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,12 @@ func (l *LocalConfig) UpsertInstance(instance Instance) {
321321
}
322322

323323
// Returns true if server was removed successfully
324-
func (l *LocalConfig) RemoveInstance(instanceName string) bool {
325-
if instanceName == "" {
324+
func (l *LocalConfig) RemoveInstance(instanceID string) bool {
325+
if instanceID == "" {
326326
return true
327327
}
328328
for a, i := range l.Instances {
329-
if i.Name == instanceName {
329+
if i.ContainerID == instanceID {
330330
l.Instances = append(l.Instances[:a], l.Instances[a+1:]...)
331331
return true
332332
}

0 commit comments

Comments
 (0)