Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 20 additions & 8 deletions pkg/adaptation/adaptation.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (r *Adaptation) UpdatePodSandbox(ctx context.Context, req *UpdatePodSandbox
for _, plugin := range r.plugins {
_, err := plugin.updatePodSandbox(ctx, req)
if err != nil {
return nil, err
return nil, pluginError(plugin, err)
}
}

Expand All @@ -257,7 +257,7 @@ func (r *Adaptation) RemovePodSandbox(ctx context.Context, evt *StateChangeEvent
}

// CreateContainer relays the corresponding CRI request to plugins.
func (r *Adaptation) CreateContainer(ctx context.Context, req *CreateContainerRequest) (*CreateContainerResponse, error) {
func (r *Adaptation) CreateContainer(ctx context.Context, req *CreateContainerRequest) (*CreateContainerResponse, *api.OwningPlugins, error) {
r.Lock()
defer r.Unlock()
defer r.removeClosedPlugins()
Expand All @@ -280,15 +280,20 @@ func (r *Adaptation) CreateContainer(ctx context.Context, req *CreateContainerRe
}
rpl, err := plugin.createContainer(ctx, req)
if err != nil {
return nil, err
return nil, nil, pluginError(plugin, err)
}
err = result.apply(rpl, plugin.name())
if err != nil {
return nil, err
return nil, nil, err
}
}

return r.validateContainerAdjustment(ctx, validate, result)
rpl, err := r.validateContainerAdjustment(ctx, validate, result)
if err != nil {
return nil, nil, err
}

return rpl, result.owners, nil
}

// PostCreateContainer relays the corresponding CRI event to plugins.
Expand Down Expand Up @@ -319,7 +324,7 @@ func (r *Adaptation) UpdateContainer(ctx context.Context, req *UpdateContainerRe
for _, plugin := range r.plugins {
rpl, err := plugin.updateContainer(ctx, req)
if err != nil {
return nil, err
return nil, pluginError(plugin, err)
}
err = result.apply(rpl, plugin.name())
if err != nil {
Expand All @@ -346,7 +351,7 @@ func (r *Adaptation) StopContainer(ctx context.Context, req *StopContainerReques
for _, plugin := range r.plugins {
rpl, err := plugin.stopContainer(ctx, req)
if err != nil {
return nil, err
return nil, pluginError(plugin, err)
}
err = result.apply(rpl, plugin.name())
if err != nil {
Expand Down Expand Up @@ -376,7 +381,7 @@ func (r *Adaptation) StateChange(ctx context.Context, evt *StateChangeEvent) err
for _, plugin := range r.plugins {
err := plugin.StateChange(ctx, evt)
if err != nil {
return err
return pluginError(plugin, err)
}
}

Expand Down Expand Up @@ -720,3 +725,10 @@ func (b *PluginSyncBlock) Unblock() {
b.r = nil
}
}

func pluginError(plugin *plugin, err error) error {
if err == nil {
return nil
}
return fmt.Errorf("plugin %q: %w", plugin.name(), err)
}
2 changes: 2 additions & 0 deletions pkg/adaptation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type (
POSIXRlimit = api.POSIXRlimit
SecurityProfile = api.SecurityProfile
User = api.User
OwningPlugins = api.OwningPlugins
FieldOwners = api.FieldOwners

EventMask = api.EventMask
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/adaptation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func (m *mockRuntime) UpdatePodSandbox(ctx context.Context, req *api.UpdatePodSa
func (m *mockRuntime) CreateContainer(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
b := m.runtime.BlockPluginSync()
defer b.Unblock()
return m.runtime.CreateContainer(ctx, req)
rpl, _, err := m.runtime.CreateContainer(ctx, req)
return rpl, err
}

func (m *mockRuntime) UpdateContainer(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (o *OwningPlugins) ClaimHooks(id, plugin string) error {
}

func (o *OwningPlugins) HooksOwner(id string) (string, bool) {
return o.ownersFor(id).simpleOwner(Field_OciHooks.Key())
return o.ownersFor(id).SimpleOwner(Field_OciHooks.Key())
}

func (o *OwningPlugins) ClearHooks(id, plugin string) {
Expand Down Expand Up @@ -148,7 +148,7 @@ func (f *FieldOwners) ClaimHooks(plugin string) error {
}

func (f *FieldOwners) HooksOwner() (string, bool) {
return f.simpleOwner(Field_OciHooks.Key())
return f.SimpleOwner(Field_OciHooks.Key())
}

func (f *FieldOwners) ClearHooks(plugin string) {
Expand All @@ -175,7 +175,7 @@ func (f *FieldOwners) ClearRdt(plugin string) {
}

func (f *FieldOwners) accumulateSimple(field int32, plugin string) {
old, ok := f.simpleOwner(field)
old, ok := f.SimpleOwner(field)
if ok {
plugin = old + "," + plugin
}
Expand All @@ -200,7 +200,7 @@ func (f *FieldOwners) compoundOwnerMap(field int32) (map[string]string, bool) {
return m.Owners, true
}

func (f *FieldOwners) compoundOwner(field int32, key string) (string, bool) {
func (f *FieldOwners) CompoundOwner(field int32, key string) (string, bool) {
if f == nil {
return "", false
}
Expand All @@ -214,7 +214,7 @@ func (f *FieldOwners) compoundOwner(field int32, key string) (string, bool) {
return plugin, ok
}

func (f *FieldOwners) simpleOwner(field int32) (string, bool) {
func (f *FieldOwners) SimpleOwner(field int32) (string, bool) {
if f == nil {
return "", false
}
Expand Down
Loading
Loading