Merge pull request #7 from mrunalp/state_lock
Add lock around container state access
This commit is contained in:
commit
0652579fb0
1 changed files with 6 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/ocid/utils"
|
"github.com/kubernetes-incubator/ocid/utils"
|
||||||
|
@ -93,6 +94,8 @@ func (r *Runtime) DeleteContainer(c *Container) error {
|
||||||
|
|
||||||
// updateStatus refreshes the status of the container.
|
// updateStatus refreshes the status of the container.
|
||||||
func (r *Runtime) UpdateStatus(c *Container) error {
|
func (r *Runtime) UpdateStatus(c *Container) error {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
out, err := exec.Command(r.path, "state", c.name).Output()
|
out, err := exec.Command(r.path, "state", c.name).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting container state for %s: %s", c.name, err)
|
return fmt.Errorf("error getting container state for %s: %s", c.name, err)
|
||||||
|
@ -106,6 +109,8 @@ func (r *Runtime) UpdateStatus(c *Container) error {
|
||||||
|
|
||||||
// ContainerStatus returns the state of a container.
|
// ContainerStatus returns the state of a container.
|
||||||
func (r *Runtime) ContainerStatus(c *Container) *ContainerState {
|
func (r *Runtime) ContainerStatus(c *Container) *ContainerState {
|
||||||
|
c.stateLock.Lock()
|
||||||
|
defer c.stateLock.Unlock()
|
||||||
return c.state
|
return c.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +122,7 @@ type Container struct {
|
||||||
labels map[string]string
|
labels map[string]string
|
||||||
sandbox string
|
sandbox string
|
||||||
state *ContainerState
|
state *ContainerState
|
||||||
|
stateLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus represents the status of a container.
|
// ContainerStatus represents the status of a container.
|
||||||
|
|
Loading…
Reference in a new issue