@@ -33,7 +33,12 @@ func (daemon *Daemon) CmdPodStop(job *engine.Job) error {
33
33
func (daemon * Daemon ) StopPod (podId , stopVm string ) (int , string , error ) {
34
34
glog .V (1 ).Infof ("Prepare to stop the POD: %s" , podId )
35
35
// find the vm id which running POD, and stop it
36
- if daemon .PodList [podId ].Status != types .S_POD_RUNNING {
36
+ mypod , ok := daemon .PodList [podId ]
37
+ if ! ok {
38
+ glog .Errorf ("Can not find pod(%s)" , podId )
39
+ return - 1 , "" , fmt .Errorf ("Can not find pod(%s)" , podId )
40
+ }
41
+ if mypod .Status != types .S_POD_RUNNING {
37
42
return - 1 , "" , fmt .Errorf ("The POD %s has aleady stopped, can not stop again!" , podId )
38
43
}
39
44
vmid , err := daemon .GetPodVmByName (podId )
@@ -42,9 +47,9 @@ func (daemon *Daemon) StopPod(podId, stopVm string) (int, string, error) {
42
47
}
43
48
// we need to set the 'RestartPolicy' of the pod to 'never' if stop command is invoked
44
49
// for kubernetes
45
- if daemon . PodList [ podId ] .Type == "kubernetes" {
46
- daemon . PodList [ podId ] .RestartPolicy = "never"
47
- if daemon . PodList [ podId ] .Vm == "" {
50
+ if mypod .Type == "kubernetes" {
51
+ mypod .RestartPolicy = "never"
52
+ if mypod .Vm == "" {
48
53
return types .E_VM_SHUTDOWN , "" , nil
49
54
}
50
55
}
@@ -53,7 +58,6 @@ func (daemon *Daemon) StopPod(podId, stopVm string) (int, string, error) {
53
58
if ! ok {
54
59
return - 1 , "" , fmt .Errorf ("VM is not exist" )
55
60
}
56
- mypod , _ := daemon .PodList [podId ]
57
61
58
62
vmResponse := vm .StopPod (mypod , stopVm )
59
63
@@ -63,6 +67,9 @@ func (daemon *Daemon) StopPod(podId, stopVm string) (int, string, error) {
63
67
if vmResponse .Code == types .E_VM_SHUTDOWN {
64
68
daemon .RemoveVm (vmid )
65
69
}
70
+ if mypod .Autoremove == true {
71
+ daemon .CleanPod (podId )
72
+ }
66
73
67
74
return vmResponse .Code , vmResponse .Cause , nil
68
75
}
0 commit comments