Skip to content

Commit

Permalink
add container id to container info (#251)
Browse files Browse the repository at this point in the history
Signed-off-by: Cheimu <xerhoneyfc@gmail.com>
  • Loading branch information
cheimu committed Jun 14, 2022
1 parent 4fa8400 commit 5d624d7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/runtimeproxy/resexecutor/cri/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (c *ContainerResourceExecutor) ResourceCheckPoint(rsp interface{}) error {
// container level resource checkpoint would be triggered during post container create only
switch response := rsp.(type) {
case *runtimeapi.CreateContainerResponse:
c.ContainerMata.Id = response.GetContainerId()
err := store.WriteContainerInfo(response.GetContainerId(), &c.ContainerInfo)
if err != nil {
return err
Expand Down
48 changes: 48 additions & 0 deletions pkg/runtimeproxy/resexecutor/cri/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,51 @@ func TestContainerResourceExecutor_UpdateRequestForUpdateContainerResourcesReque
assert.Equal(t, tt.wantAnnotations, tt.args.req.(*runtimeapi.UpdateContainerResourcesRequest).GetAnnotations())
}
}

func TestContainerResourceExecutor_ResourceCheckPoint(t *testing.T) {
type fields struct {
ContainerInfo store.ContainerInfo
}
type args struct {
rsp interface{}
}
tests := []struct {
name string
fields fields
args args
wantErr bool
wantStoreInfo *store.ContainerInfo
}{
{
name: "normal case - CreateContainerResponse - Set Container id successfully",
args: args{
rsp: &runtimeapi.CreateContainerResponse{
ContainerId: "111111",
},
},
fields: fields{
ContainerInfo: store.ContainerInfo{
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
ContainerMata: &v1alpha1.ContainerMetadata{},
},
},
},
wantErr: false,
wantStoreInfo: &store.ContainerInfo{
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
ContainerMata: &v1alpha1.ContainerMetadata{
Id: "111111",
},
}},
},
}
for _, tt := range tests {
c := &ContainerResourceExecutor{
ContainerInfo: tt.fields.ContainerInfo,
}
err := c.ResourceCheckPoint(tt.args.rsp)
containerInfo := store.GetContainerInfo(c.ContainerInfo.ContainerMata.GetId())
assert.Equal(t, tt.wantErr, err != nil, err)
assert.Equal(t, tt.wantStoreInfo, containerInfo)
}
}

0 comments on commit 5d624d7

Please sign in to comment.