Ensure pod inspect is locked and validity-checked

Also, don't return the internal podState struct - instead return
a public inspect struct.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1258
Approved by: rhatdan
This commit is contained in:
Matthew Heon
2018-08-11 11:19:08 -04:00
committed by Atomic Bot
parent 029d5aad56
commit 3ef9279cec
3 changed files with 229 additions and 22 deletions

View File

@ -398,7 +398,13 @@ func (p *Pod) Inspect() (*PodInspect, error) {
podContainers []PodContainerInfo
)
containers, err := p.AllContainers()
p.lock.Lock()
defer p.lock.Unlock()
if err := p.updatePod(); err != nil {
return nil, err
}
containers, err := p.runtime.state.PodContainers(p)
if err != nil {
return &PodInspect{}, err
}
@ -420,8 +426,10 @@ func (p *Pod) Inspect() (*PodInspect, error) {
config := new(PodConfig)
deepcopier.Copy(p.config).To(config)
inspectData := PodInspect{
Config: config,
State: p.state,
Config: config,
State: &PodInspectState{
CgroupPath: p.state.CgroupPath,
},
Containers: podContainers,
}
return &inspectData, nil