Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/adaptation/builtin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import (
"github.com/containerd/nri/pkg/api"
)

// BuiltinPlugin implements the NRI API and runs in-process
// within the container runtime.
type BuiltinPlugin struct {
Base string
Index string
Handlers BuiltinHandlers
}

// BuiltinHandlers contains request handlers for the builtin plugin.
type BuiltinHandlers struct {
Configure func(context.Context, *api.ConfigureRequest) (*api.ConfigureResponse, error)
Synchronize func(context.Context, *api.SynchronizeRequest) (*api.SynchronizeResponse, error)
Expand All @@ -48,6 +51,7 @@ type BuiltinHandlers struct {
ValidateContainerAdjustment func(context.Context, *api.ValidateContainerAdjustmentRequest) error
}

// Configure implements PluginService of the NRI API.
func (b *BuiltinPlugin) Configure(ctx context.Context, req *api.ConfigureRequest) (*api.ConfigureResponse, error) {
var (
rpl = &api.ConfigureResponse{}
Expand Down Expand Up @@ -110,38 +114,44 @@ func (b *BuiltinPlugin) Configure(ctx context.Context, req *api.ConfigureRequest
return rpl, err
}

// Synchronize implements PluginService of the NRI API.
func (b *BuiltinPlugin) Synchronize(ctx context.Context, req *api.SynchronizeRequest) (*api.SynchronizeResponse, error) {
if b.Handlers.Synchronize != nil {
return b.Handlers.Synchronize(ctx, req)
}
return &api.SynchronizeResponse{}, nil
}

// Shutdown implements PluginService of the NRI API.
func (b *BuiltinPlugin) Shutdown(context.Context, *api.ShutdownRequest) (*api.ShutdownResponse, error) {
return &api.ShutdownResponse{}, nil
}

// CreateContainer implements PluginService of the NRI API.
func (b *BuiltinPlugin) CreateContainer(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
if b.Handlers.CreateContainer != nil {
return b.Handlers.CreateContainer(ctx, req)
}
return &api.CreateContainerResponse{}, nil
}

// UpdateContainer implements PluginService of the NRI API.
func (b *BuiltinPlugin) UpdateContainer(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) {
if b.Handlers.UpdateContainer != nil {
return b.Handlers.UpdateContainer(ctx, req)
}
return &api.UpdateContainerResponse{}, nil
}

// StopContainer implements PluginService of the NRI API.
func (b *BuiltinPlugin) StopContainer(ctx context.Context, req *api.StopContainerRequest) (*api.StopContainerResponse, error) {
if b.Handlers.StopContainer != nil {
return b.Handlers.StopContainer(ctx, req)
}
return &api.StopContainerResponse{}, nil
}

// StateChange implements PluginService of the NRI API.
func (b *BuiltinPlugin) StateChange(ctx context.Context, evt *api.StateChangeEvent) (*api.StateChangeResponse, error) {
var err error
switch evt.Event {
Expand Down Expand Up @@ -182,20 +192,23 @@ func (b *BuiltinPlugin) StateChange(ctx context.Context, evt *api.StateChangeEve
return &api.StateChangeResponse{}, err
}

// UpdatePodSandbox implements PluginService of the NRI API.
func (b *BuiltinPlugin) UpdatePodSandbox(ctx context.Context, req *api.UpdatePodSandboxRequest) (*api.UpdatePodSandboxResponse, error) {
if b.Handlers.UpdatePodSandbox != nil {
return b.Handlers.UpdatePodSandbox(ctx, req)
}
return &api.UpdatePodSandboxResponse{}, nil
}

// PostUpdatePodSandbox is a handler for the PostUpdatePodSandbox event.
func (b *BuiltinPlugin) PostUpdatePodSandbox(ctx context.Context, req *api.PostUpdatePodSandboxRequest) error {
if b.Handlers.PostUpdatePodSandbox != nil {
return b.Handlers.PostUpdatePodSandbox(ctx, req)
}
return nil
}

// ValidateContainerAdjustment implements PluginService of the NRI API.
func (b *BuiltinPlugin) ValidateContainerAdjustment(ctx context.Context, req *api.ValidateContainerAdjustmentRequest) (*api.ValidateContainerAdjustmentResponse, error) {
if b.Handlers.ValidateContainerAdjustment != nil {
if err := b.Handlers.ValidateContainerAdjustment(ctx, req); err != nil {
Expand Down
Loading