Skip to content

Commit

Permalink
stub: fix plugin UpdateContainerInterface.
Browse files Browse the repository at this point in the history
Fix UpdateContainer adding an argument for the updated resources.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed May 23, 2023
1 parent f5d0f51 commit d042d24
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/adaptation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ type mockPlugin struct {
postCreateContainer func(*mockPlugin, *api.PodSandbox, *api.Container) error
startContainer func(*mockPlugin, *api.PodSandbox, *api.Container) error
postStartContainer func(*mockPlugin, *api.PodSandbox, *api.Container) error
updateContainer func(*mockPlugin, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error)
updateContainer func(*mockPlugin, *api.PodSandbox, *api.Container, *api.LinuxResources) ([]*api.ContainerUpdate, error)
postUpdateContainer func(*mockPlugin, *api.PodSandbox, *api.Container) error
stopContainer func(*mockPlugin, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error)
removeContainer func(*mockPlugin, *api.PodSandbox, *api.Container) error
Expand Down Expand Up @@ -546,12 +546,12 @@ func (m *mockPlugin) PostStartContainer(_ context.Context, pod *api.PodSandbox,
return m.postStartContainer(m, pod, ctr)
}

func (m *mockPlugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container) ([]*api.ContainerUpdate, error) {
func (m *mockPlugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container, res *api.LinuxResources) ([]*api.ContainerUpdate, error) {
m.pods[pod.Id] = pod
m.ctrs[ctr.Id] = ctr
m.q.Add(ContainerEvent(ctr, UpdateContainer))

return m.updateContainer(m, pod, ctr)
return m.updateContainer(m, pod, ctr, res)
}

func (m *mockPlugin) PostUpdateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container) error {
Expand Down Expand Up @@ -585,7 +585,7 @@ func nopCreateContainer(*mockPlugin, *api.PodSandbox, *api.Container) (*api.Cont
return nil, nil, nil
}

func nopUpdateContainer(*mockPlugin, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error) {
func nopUpdateContainer(*mockPlugin, *api.PodSandbox, *api.Container, *api.LinuxResources) ([]*api.ContainerUpdate, error) {
return nil, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type UpdateContainerInterface interface {
// The plugin can request updates both to the container being updated
// (which then supersedes the original update) and to other unstopped
// containers in response.
UpdateContainer(context.Context, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error)
UpdateContainer(context.Context, *api.PodSandbox, *api.Container, *api.LinuxResources) ([]*api.ContainerUpdate, error)
}

// StopContainerInterface handles StopContainer API requests.
Expand Down Expand Up @@ -261,7 +261,7 @@ type handlers struct {
RemovePodSandbox func(context.Context, *api.PodSandbox) error
CreateContainer func(context.Context, *api.PodSandbox, *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error)
StartContainer func(context.Context, *api.PodSandbox, *api.Container) error
UpdateContainer func(context.Context, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error)
UpdateContainer func(context.Context, *api.PodSandbox, *api.Container, *api.LinuxResources) ([]*api.ContainerUpdate, error)
StopContainer func(context.Context, *api.PodSandbox, *api.Container) ([]*api.ContainerUpdate, error)
RemoveContainer func(context.Context, *api.PodSandbox, *api.Container) error
PostCreateContainer func(context.Context, *api.PodSandbox, *api.Container) error
Expand Down Expand Up @@ -619,7 +619,7 @@ func (stub *stub) UpdateContainer(ctx context.Context, req *api.UpdateContainerR
if handler == nil {
return nil, nil
}
update, err := handler(ctx, req.Pod, req.Container)
update, err := handler(ctx, req.Pod, req.Container, req.LinuxResources)
return &api.UpdateContainerResponse{
Update: update,
}, err
Expand Down
2 changes: 1 addition & 1 deletion plugins/differ/nri-differ.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (p *plugin) PostStartContainer(_ context.Context, pod *api.PodSandbox, cont
return nil
}

func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, container *api.Container) ([]*api.ContainerUpdate, error) {
func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, container *api.Container, r *api.LinuxResources) ([]*api.ContainerUpdate, error) {
p.differ("UpdateContainer", pod, container)

return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/logger/nri-logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (p *plugin) PostStartContainer(_ context.Context, pod *api.PodSandbox, cont
return nil
}

func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, container *api.Container) ([]*api.ContainerUpdate, error) {
dump("UpdateContainer", "pod", pod, "container", container)
func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, container *api.Container, r *api.LinuxResources) ([]*api.ContainerUpdate, error) {
dump("UpdateContainer", "pod", pod, "container", container, "resources", r)
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/template/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *plugin) PostStartContainer(_ context.Context, pod *api.PodSandbox, ctr
return nil
}

func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container) ([]*api.ContainerUpdate, error) {
func (p *plugin) UpdateContainer(_ context.Context, pod *api.PodSandbox, ctr *api.Container, r *api.LinuxResources) ([]*api.ContainerUpdate, error) {
log.Infof("Updating container %s/%s/%s...", pod.GetNamespace(), pod.GetName(), ctr.GetName())

//
Expand Down

0 comments on commit d042d24

Please sign in to comment.