-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdestroy.go
More file actions
40 lines (36 loc) · 812 Bytes
/
destroy.go
File metadata and controls
40 lines (36 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package client
import (
"fmt"
"github.com/coreos/fleet/job"
)
// Destroy units for a given target
func (c *FleetClient) Destroy(targets string) (err error) {
component, num, err := splitTarget(targets)
if err != nil {
return
}
if num == 0 {
num, err = c.lastUnit(component)
if err != nil {
return err
}
}
name, err := formatUnitName(component, num)
if err != nil {
return err
}
desiredState := string(job.JobStateInactive)
err = c.Fleet.SetUnitTargetState(name, desiredState)
if err != nil {
return err
}
outchan, errchan := waitForUnitStates([]string{name}, desiredState)
err = printUnitState(name, outchan, errchan)
if err != nil {
return err
}
if err = c.Fleet.DestroyUnit(name); err != nil {
return fmt.Errorf("failed destroying job %s: %v", name, err)
}
return
}