@@ -90,11 +90,13 @@ func remove(ctx context.Context, uncli *cli.CLI, nameOrID string, opts removeOpt
90
90
91
91
reset := ! opts .noReset
92
92
var containers []api.ServiceContainer
93
+ reachable := false
93
94
if reset {
94
95
// Check if the machine is up and has service containers.
95
96
listOpts := container.ListOptions {All : true }
96
97
machineContainers , err := client .Docker .ListServiceContainers (mctx , "" , listOpts )
97
98
if err == nil {
99
+ reachable = true
98
100
containers = machineContainers [0 ].Containers
99
101
if len (containers ) > 0 {
100
102
plural := ""
@@ -104,7 +106,7 @@ func remove(ctx context.Context, uncli *cli.CLI, nameOrID string, opts removeOpt
104
106
fmt .Printf ("Found %d service container%s on machine '%s':\n " , len (containers ), plural , m .Name )
105
107
fmt .Println (formatContainerTree (containers ))
106
108
fmt .Println ()
107
- fmt .Println ("This will remove all service containers on the machine, remove it from the cluster, " +
109
+ fmt .Println ("This will remove all service containers from the machine, remove it from the cluster, " +
108
110
"and reset it to the uninitialised state." )
109
111
} else {
110
112
fmt .Printf ("No service containers found on machine '%s'.\n " , m .Name )
@@ -129,24 +131,22 @@ func remove(ctx context.Context, uncli *cli.CLI, nameOrID string, opts removeOpt
129
131
}
130
132
}
131
133
132
- if reset {
133
- if len (containers ) > 0 {
134
- err = progress .RunWithTitle (ctx , func (ctx context.Context ) error {
135
- return removeContainers (ctx , client , containers )
136
- }, uncli .ProgressOut (), "Removing containers" )
137
- if err != nil {
138
- return fmt .Errorf ("remove containers: %w" , err )
139
- }
140
- fmt .Println ()
134
+ if reset && len (containers ) > 0 {
135
+ err = progress .RunWithTitle (ctx , func (ctx context.Context ) error {
136
+ return removeContainers (ctx , client , containers )
137
+ }, uncli .ProgressOut (), "Removing containers" )
138
+ if err != nil {
139
+ return fmt .Errorf ("remove containers: %w" , err )
141
140
}
141
+ fmt .Println ()
142
142
}
143
143
144
144
if _ , err = client .RemoveMachine (ctx , & pb.RemoveMachineRequest {Id : m .Id }); err != nil {
145
145
return fmt .Errorf ("remove machine from cluster: %w" , err )
146
146
}
147
147
fmt .Printf ("Machine '%s' removed from the cluster.\n " , m .Name )
148
148
149
- if reset {
149
+ if reset && reachable {
150
150
_ , err = client .MachineClient .Reset (mctx , & pb.ResetRequest {})
151
151
if err != nil {
152
152
fmt .Printf ("WARNING: Failed to reset machine: %v\n " , err )
0 commit comments