Skip to content

Commit 3690424

Browse files
committed
pr suggestion updates
1 parent 6cc0259 commit 3690424

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

pkg/adaptation/adaptation.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,39 @@ func (r *Adaptation) UpdatePodSandbox(ctx context.Context, req *UpdatePodSandbox
240240

241241
// PodSandboxStatus relays the corresponding CRI request to plugins.
242242
// If a plugin returns IP addresses, those will be returned to the caller.
243-
// The last plugin to return non-empty IPs wins.
243+
// An error is returned if multiple plugins attempt to set the same field.
244244
func (r *Adaptation) PodSandboxStatus(ctx context.Context, req *PodSandboxStatusRequest) (*PodSandboxStatusResponse, error) {
245245
r.Lock()
246246
defer r.Unlock()
247247
defer r.removeClosedPlugins()
248248

249-
rsp := &PodSandboxStatusResponse{}
249+
var (
250+
rsp = &PodSandboxStatusResponse{}
251+
ipOwner = ""
252+
additionalIpsOwner = ""
253+
)
254+
250255
for _, plugin := range r.plugins {
251256
pluginRsp, err := plugin.podSandboxStatus(ctx, req)
252257
if err != nil {
253258
return nil, err
254259
}
255-
// Use the last plugin's non-empty IP response
256-
if pluginRsp != nil && (pluginRsp.Ip != "" || len(pluginRsp.AdditionalIps) > 0) {
257-
rsp = pluginRsp
260+
if pluginRsp == nil || (pluginRsp.Ip == "" && len(pluginRsp.AdditionalIps) == 0) {
261+
continue
262+
}
263+
if pluginRsp.Ip != "" {
264+
if ipOwner != "" {
265+
return nil, fmt.Errorf("plugins %q and %q both tried to set PodSandboxStatus IP address field", ipOwner, plugin.name())
266+
}
267+
rsp.Ip = pluginRsp.Ip
268+
ipOwner = plugin.name()
269+
}
270+
if len(pluginRsp.AdditionalIps) > 0 {
271+
if additionalIpsOwner != "" {
272+
return nil, fmt.Errorf("plugins %q and %q both tried to set PodSandboxStatus additional IP addresses field", additionalIpsOwner, plugin.name())
273+
}
274+
rsp.AdditionalIps = pluginRsp.AdditionalIps
275+
additionalIpsOwner = plugin.name()
258276
}
259277
}
260278

pkg/stub/stub.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ type PostUpdatePodInterface interface {
9696
// PodSandboxStatusInterface handles PodSandboxStatus API requests.
9797
type PodSandboxStatusInterface interface {
9898
// PodSandboxStatus relays a PodSandboxStatus request to the plugin.
99-
// The plugin can return modified IP addresses for the pod sandbox.
100-
// Returns: primary IP, additional IPs, error
101-
PodSandboxStatus(context.Context, *api.PodSandbox) (string, []string, error)
99+
// The plugin can return modified IP addresses for the pod sandbox
100+
// in a PodSandboxStatusResponse.
101+
PodSandboxStatus(context.Context, *api.PodSandbox) (*api.PodSandboxStatusResponse, error)
102102
}
103103

104104
// CreateContainerInterface handles CreateContainer API requests.
@@ -324,7 +324,7 @@ type handlers struct {
324324
StopPodSandbox func(context.Context, *api.PodSandbox) error
325325
RemovePodSandbox func(context.Context, *api.PodSandbox) error
326326
PostUpdatePodSandbox func(context.Context, *api.PodSandbox) error
327-
PodSandboxStatus func(context.Context, *api.PodSandbox) (string, []string, error)
327+
PodSandboxStatus func(context.Context, *api.PodSandbox) (*api.PodSandboxStatusResponse, error)
328328
CreateContainer func(context.Context, *api.PodSandbox, *api.Container) (*api.ContainerAdjustment, []*api.ContainerUpdate, error)
329329
StartContainer func(context.Context, *api.PodSandbox, *api.Container) error
330330
UpdateContainer func(context.Context, *api.PodSandbox, *api.Container, *api.LinuxResources) ([]*api.ContainerUpdate, error)
@@ -797,11 +797,8 @@ func (stub *stub) PodSandboxStatus(ctx context.Context, req *api.PodSandboxStatu
797797
if handler == nil {
798798
return &api.PodSandboxStatusResponse{}, nil
799799
}
800-
ip, additionalIPs, err := handler(ctx, req.Pod)
801-
return &api.PodSandboxStatusResponse{
802-
Ip: ip,
803-
AdditionalIps: additionalIPs,
804-
}, err
800+
801+
return handler(ctx, req.Pod)
805802
}
806803

807804
// StateChange event handler.

0 commit comments

Comments
 (0)