infrakit: Make Destroy() usable elsewhere

Don't return if the process does not exist. Instead proceed and delete
the state directory.

This allows us to use the Destroy() method elsewhere to clean up the state.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-03-01 17:26:44 -08:00
parent d1ad02e079
commit 1c3f4b4865

View File

@ -149,12 +149,12 @@ func (v hyperkitPlugin) Destroy(id instance.ID) error {
p, err := getProcess(instanceDir) p, err := getProcess(instanceDir)
if err != nil { if err != nil {
log.Warningln("Can't find processes: ", err) log.Warningln("Can't find processes: ", err)
return err } else {
} err = p.Kill()
err = p.Kill() if err != nil {
if err != nil { log.Warningln("Can't kill processes with pid: ", p.Pid, err)
log.Warningln("Can't kill processes with pid: ", p.Pid, err) return err
return err }
} }
if err := os.RemoveAll(instanceDir); err != nil { if err := os.RemoveAll(instanceDir); err != nil {
@ -205,10 +205,12 @@ func (v hyperkitPlugin) DescribeInstances(tags map[string]string) ([]instance.De
if allMatched { if allMatched {
var logicalID *instance.LogicalID var logicalID *instance.LogicalID
id := instance.ID(file.Name())
pidData, err := ioutil.ReadFile(path.Join(instanceDir, hyperkitPid)) pidData, err := ioutil.ReadFile(path.Join(instanceDir, hyperkitPid))
if err == nil { if err == nil {
id := instance.LogicalID(pidData) lid := instance.LogicalID(pidData)
logicalID = &id logicalID = &lid
} else { } else {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return nil, err return nil, err
@ -217,17 +219,13 @@ func (v hyperkitPlugin) DescribeInstances(tags map[string]string) ([]instance.De
// Check if process is running // Check if process is running
if _, err := getProcess(instanceDir); err != nil { if _, err := getProcess(instanceDir); err != nil {
log.Warningln("Process not running: Instance ", file.Name()) log.Warningln("Process not running: Instance ", id)
if err := os.RemoveAll(instanceDir); err != nil { v.Destroy(id)
log.Warningln("Can't remove instance dir ", instanceDir, " error ", err)
}
continue continue
} }
descriptions = append(descriptions, instance.Description{ descriptions = append(descriptions, instance.Description{
ID: instance.ID(file.Name()), ID: id,
LogicalID: logicalID, LogicalID: logicalID,
Tags: instanceTags, Tags: instanceTags,
}) })