Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit f20ea2c

Browse files
committed
Associate containers with sandbox
Signed-off-by: fupan <lifupan@gmail.com>
1 parent b4e91ad commit f20ea2c

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

daemon/pod/container.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,32 @@ func (c *Container) addToSandbox() error {
943943
return nil
944944
}
945945

946+
func (c *Container) associateToSandbox() error {
947+
c.Log(DEBUG, "try to associate container %s to sandbox", c.Id())
948+
949+
containerStatus, err := c.p.sandbox.StatusContainer(c.Id())
950+
if err != nil {
951+
c.Log(ERROR, err)
952+
return err
953+
}
954+
955+
switch containerStatus.State.State {
956+
case vc.StateRunning:
957+
c.status.State = S_CONTAINER_RUNNING
958+
c.status.StartedAt = containerStatus.StartTime
959+
960+
default:
961+
c.status.State = S_CONTAINER_CREATED
962+
c.status.CreatedAt = time.Now()
963+
}
964+
965+
go c.waitFinish(-1)
966+
967+
c.startLogging()
968+
969+
return nil
970+
}
971+
946972
// This method should be called when initialzing container or put into resource lock.
947973
func (c *Container) initStreams() error {
948974
if c.streams != nil {

daemon/pod/persist.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,15 @@ func LoadXPod(factory *PodFactory, layout *types.PersistPodLayout) (*XPod, error
144144
if err != nil {
145145
return nil, err
146146
}
147-
/*
148-
//associate containers
149-
if p.status == S_POD_RUNNING {
150-
for _, c := range p.containers {
151-
if err = c.associateToSandbox(); err != nil {
152-
return nil, err
153-
}
147+
148+
//associate containers
149+
if p.status == S_POD_RUNNING {
150+
for _, c := range p.containers {
151+
if err = c.associateToSandbox(); err != nil {
152+
return nil, err
154153
}
155154
}
156-
*/
155+
}
157156

158157
// don't need to reserve name again, because this is load
159158
return p, nil
@@ -450,31 +449,31 @@ func (inf *Interface) removeFromDB() error {
450449

451450
func (p *XPod) saveSandbox() error {
452451

453-
var (
454-
sb types.SandboxPersistInfo
455-
err error
456-
)
457-
stop_status := map[PodState]bool{
458-
S_POD_NONE: true,
459-
S_POD_STOPPED: true,
460-
S_POD_STOPPING: true,
461-
S_POD_ERROR: true,
452+
var (
453+
sb types.SandboxPersistInfo
454+
err error
455+
)
456+
stop_status := map[PodState]bool{
457+
S_POD_NONE: true,
458+
S_POD_STOPPED: true,
459+
S_POD_STOPPING: true,
460+
S_POD_ERROR: true,
461+
}
462+
p.statusLock.RLock()
463+
defer p.statusLock.RUnlock()
464+
if !stop_status[p.status] {
465+
sb.Id = p.sandbox.ID()
466+
/*By now the sandbox info had been managed by kata, thus there is no need
467+
*to keep those info here.
468+
*/
469+
sb.PersistInfo = nil
470+
if err != nil {
471+
hlog.HLog(ERROR, p, 2, "failed to dump sandbox %s: %v", sb.Id, err)
472+
return err
462473
}
463-
p.statusLock.RLock()
464-
defer p.statusLock.RUnlock()
465-
if !stop_status[p.status] {
466-
sb.Id = p.sandbox.ID()
467-
/*By now the sandbox info had been managed by kata, thus there is no need
468-
*to keep those info here.
469-
*/
470-
sb.PersistInfo = nil
471-
if err != nil {
472-
hlog.HLog(ERROR, p, 2, "failed to dump sandbox %s: %v", sb.Id, err)
473-
return err
474-
}
475-
return saveMessage(p.factory.db, fmt.Sprintf(SB_KEY_FMT, p.Id()), &sb, p, "sandbox info")
474+
return saveMessage(p.factory.db, fmt.Sprintf(SB_KEY_FMT, p.Id()), &sb, p, "sandbox info")
476475

477-
}
476+
}
478477

479478
return nil
480479
}

0 commit comments

Comments
 (0)