Skip to content

Commit 2142413

Browse files
zhangyuefuweid
authored andcommitted
fix: add more events
Signed-off-by: zhangyue <[email protected]>
1 parent 17ba8c3 commit 2142413

File tree

9 files changed

+28
-7
lines changed

9 files changed

+28
-7
lines changed

daemon/mgr/container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,8 @@ func (mgr *ContainerManager) Restart(ctx context.Context, name string, timeout i
982982
c.RestartCount++
983983

984984
logrus.Debugf("container %s restartCount is %d", c.ID, c.RestartCount)
985+
mgr.LogContainerEvent(ctx, c, "restart")
986+
985987
return c.Write(mgr.Store)
986988
}
987989

@@ -1451,6 +1453,7 @@ func (mgr *ContainerManager) Top(ctx context.Context, name string, psArgs string
14511453
if err != nil {
14521454
return nil, errors.Wrapf(err, "failed parsePSOutput")
14531455
}
1456+
mgr.LogContainerEvent(ctx, c, "top")
14541457

14551458
return procList, nil
14561459
}
@@ -1469,6 +1472,7 @@ func (mgr *ContainerManager) Resize(ctx context.Context, name string, opts types
14691472
return fmt.Errorf("failed to resize container %s: container is not running", c.ID)
14701473
}
14711474

1475+
mgr.LogContainerEvent(ctx, c, "resize")
14721476
return mgr.Client.ResizeContainer(ctx, c.ID, opts)
14731477
}
14741478

daemon/mgr/container_commit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (mgr *ContainerManager) Commit(ctx context.Context, name string, options *t
8080
// pouch can see the new image reference.
8181
logrus.Warnf("failed to update image store: %s", err)
8282
}
83+
mgr.LogContainerEvent(ctx, c, "commit")
8384

8485
// return 12 bits image id as a result
8586
imageID := imageDigest.Hex()

daemon/mgr/container_copy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func (mgr *ContainerManager) ArchivePath(ctx context.Context, name, path string)
154154
c.Unlock()
155155
return err
156156
})
157+
mgr.LogContainerEvent(ctx, c, "archive-path")
157158

158159
return content, stat, nil
159160
}
@@ -224,6 +225,8 @@ func (mgr *ContainerManager) ExtractToDir(ctx context.Context, name, path string
224225
NoOverwriteDirNonDir: noOverwriteDirNonDir,
225226
}
226227

228+
mgr.LogContainerEvent(ctx, c, "extract-to-dir")
229+
227230
return chrootarchive.Untar(content, resolvedPath, opts)
228231
}
229232

daemon/mgr/container_exec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (mgr *ContainerManager) CreateExec(ctx context.Context, name string, config
4343
}
4444

4545
mgr.ExecProcesses.Put(execid, execConfig)
46-
46+
mgr.LogContainerEvent(ctx, c, "exec_create")
4747
return execid, nil
4848
}
4949

@@ -165,6 +165,7 @@ func (mgr *ContainerManager) StartExec(ctx context.Context, execid string, cfg *
165165
}, timeout); err != nil {
166166
return err
167167
}
168+
mgr.LogContainerEvent(ctx, c, "exec_start")
168169
return <-attachErrCh
169170
}
170171

daemon/mgr/image.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (mgr *ImageManager) PushImage(ctx context.Context, name, tag string, authCo
270270
} else {
271271
ref = reference.WithTag(ref, tag)
272272
}
273-
273+
mgr.LogImageEvent(ctx, ref.String(), ref.String(), "push")
274274
return mgr.client.PushImage(ctx, ref.String(), authConfig, out)
275275
}
276276

@@ -465,7 +465,7 @@ func (mgr *ImageManager) RemoveImage(ctx context.Context, idOrRef string, force
465465
// the searchable reference has different locator without force.
466466
// It's different reference from locator aspect.
467467
if !force && !uniqueLocatorReference(mgr.localStore.GetReferences(id)) {
468-
return fmt.Errorf("Unable to remove the image %q (must force) - image has serveral references", idOrRef)
468+
return fmt.Errorf("unable to remove the image %q (must force) - image has serveral references", idOrRef)
469469
}
470470

471471
for _, ref := range mgr.localStore.GetPrimaryReferences(id) {
@@ -486,7 +486,7 @@ func (mgr *ImageManager) RemoveImage(ctx context.Context, idOrRef string, force
486486
if err := mgr.localStore.RemoveReference(id, primaryRef); err != nil {
487487
return err
488488
}
489-
489+
mgr.LogImageEvent(ctx, namedRef.String(), namedRef.String(), "delete")
490490
return mgr.client.RemoveImage(ctx, primaryRef.String())
491491
}
492492

@@ -537,6 +537,7 @@ func (mgr *ImageManager) AddTag(ctx context.Context, sourceImage string, targetT
537537
Name: tagRef.String(),
538538
Target: ctrdImg.Target(),
539539
})
540+
mgr.LogImageEvent(ctx, sourceImage, tagRef.String(), "tag")
540541
return err
541542
}
542543

daemon/mgr/image_load.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ func (mgr *ImageManager) LoadImage(ctx context.Context, imageName string, tarstr
6262
if merrs.Size() != 0 {
6363
return fmt.Errorf("fails to load image: %v", merrs.Error())
6464
}
65+
mgr.LogImageEvent(ctx, imageName, imageName, "load")
6566
return nil
6667
}

daemon/mgr/image_save.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (mgr *ImageManager) SaveImage(ctx context.Context, idOrRef string) (io.Read
1818
if err != nil {
1919
return nil, err
2020
}
21+
mgr.LogImageEvent(ctx, idOrRef, ref.String(), "save")
2122

2223
return exportedStream, nil
2324
}

daemon/mgr/volume.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (vm *VolumeManager) Attach(ctx context.Context, name string, options map[st
185185
}
186186
}
187187

188+
vm.LogVolumeEvent(ctx, name, "attach", map[string]string{"driver": v.Driver()})
188189
return vm.core.AttachVolume(id, options)
189190
}
190191

@@ -220,6 +221,6 @@ func (vm *VolumeManager) Detach(ctx context.Context, name string, options map[st
220221
}
221222
}
222223
}
223-
224+
vm.LogVolumeEvent(ctx, name, "detach", map[string]string{"driver": v.Driver()})
224225
return vm.core.DetachVolume(id, options)
225226
}

test/cli_events_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ func (suite *PouchEventsSuite) TestExecDieEventWorks(c *check.C) {
8989

9090
// check output contains exec_die event
9191
lines := delEmptyStrInSlice(strings.Split(output, "\n"))
92-
if len(lines) != 1 {
92+
if len(lines) != 3 {
9393
c.Errorf("unexpected output %s: should just contains 1 line", output)
9494
}
9595

96-
if err := checkContainerEvent(lines[0], "exec_die"); err != nil {
96+
if err := checkContainerEvent(lines[0], "exec_create"); err != nil {
97+
c.Errorf("exec_create event check error: %v", err)
98+
}
99+
100+
if err := checkContainerEvent(lines[1], "exec_start"); err != nil {
101+
c.Errorf("exec_start event check error: %v", err)
102+
}
103+
104+
if err := checkContainerEvent(lines[2], "exec_die"); err != nil {
97105
c.Errorf("exec_die event check error: %v", err)
98106
}
99107
}

0 commit comments

Comments
 (0)