Skip to content

Commit 5d624d7

Browse files
authored
add container id to container info (#251)
Signed-off-by: Cheimu <xerhoneyfc@gmail.com>
1 parent 4fa8400 commit 5d624d7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

pkg/runtimeproxy/resexecutor/cri/container.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func (c *ContainerResourceExecutor) ResourceCheckPoint(rsp interface{}) error {
125125
// container level resource checkpoint would be triggered during post container create only
126126
switch response := rsp.(type) {
127127
case *runtimeapi.CreateContainerResponse:
128+
c.ContainerMata.Id = response.GetContainerId()
128129
err := store.WriteContainerInfo(response.GetContainerId(), &c.ContainerInfo)
129130
if err != nil {
130131
return err

pkg/runtimeproxy/resexecutor/cri/container_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,51 @@ func TestContainerResourceExecutor_UpdateRequestForUpdateContainerResourcesReque
219219
assert.Equal(t, tt.wantAnnotations, tt.args.req.(*runtimeapi.UpdateContainerResourcesRequest).GetAnnotations())
220220
}
221221
}
222+
223+
func TestContainerResourceExecutor_ResourceCheckPoint(t *testing.T) {
224+
type fields struct {
225+
ContainerInfo store.ContainerInfo
226+
}
227+
type args struct {
228+
rsp interface{}
229+
}
230+
tests := []struct {
231+
name string
232+
fields fields
233+
args args
234+
wantErr bool
235+
wantStoreInfo *store.ContainerInfo
236+
}{
237+
{
238+
name: "normal case - CreateContainerResponse - Set Container id successfully",
239+
args: args{
240+
rsp: &runtimeapi.CreateContainerResponse{
241+
ContainerId: "111111",
242+
},
243+
},
244+
fields: fields{
245+
ContainerInfo: store.ContainerInfo{
246+
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
247+
ContainerMata: &v1alpha1.ContainerMetadata{},
248+
},
249+
},
250+
},
251+
wantErr: false,
252+
wantStoreInfo: &store.ContainerInfo{
253+
ContainerResourceHookRequest: &v1alpha1.ContainerResourceHookRequest{
254+
ContainerMata: &v1alpha1.ContainerMetadata{
255+
Id: "111111",
256+
},
257+
}},
258+
},
259+
}
260+
for _, tt := range tests {
261+
c := &ContainerResourceExecutor{
262+
ContainerInfo: tt.fields.ContainerInfo,
263+
}
264+
err := c.ResourceCheckPoint(tt.args.rsp)
265+
containerInfo := store.GetContainerInfo(c.ContainerInfo.ContainerMata.GetId())
266+
assert.Equal(t, tt.wantErr, err != nil, err)
267+
assert.Equal(t, tt.wantStoreInfo, containerInfo)
268+
}
269+
}

0 commit comments

Comments
 (0)