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
36 changes: 32 additions & 4 deletions pkg/adaptation/adaptation.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,46 @@ func (r *Adaptation) Stop() {
}

// RunPodSandbox relays the corresponding CRI request to plugins.
func (r *Adaptation) RunPodSandbox(ctx context.Context, req *RunPodSandboxRequest) error {
// Plugins can return a PodSandboxAdjustment for the pod sandbox in their
// response; the network IPs from every plugin are concatenated, in plugin
// invocation order, into the response's PodSandboxAdjustment so they can be
// propagated through the runtime (e.g. surfaced to the kubelet via CRI).
// Duplicate IP addresses (whether reported by a single plugin or by multiple
// plugins) are collapsed; first occurrence wins. Plugins that have nothing to
// contribute can return an empty response or a nil response.
func (r *Adaptation) RunPodSandbox(ctx context.Context, req *RunPodSandboxRequest) (*RunPodSandboxResponse, error) {
Comment on lines +245 to +252

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires changes on containerd and crio, otherwise it will not work, since CNI happens before this hook ... and now it will need to check after this hook again

r.Lock()
defer r.Unlock()
defer r.removeClosedPlugins()

var (
ips []string
seen = map[string]struct{}{}
)
for _, plugin := range r.plugins {
if _, err := plugin.runPodSandbox(ctx, req); err != nil {
return err
pluginRsp, err := plugin.runPodSandbox(ctx, req)
if err != nil {
return nil, err
}
for _, ip := range pluginRsp.GetAdjust().GetNetwork().GetIps() {
if ip == "" {
continue
}
if _, ok := seen[ip]; ok {
continue
}
seen[ip] = struct{}{}
ips = append(ips, ip)
}
}

return nil
rsp := &RunPodSandboxResponse{}
if len(ips) > 0 {
rsp.Adjust = &PodSandboxAdjustment{
Network: &PodSandboxNetwork{Ips: ips},
}
}
return rsp, nil
}

// UpdatePodSandbox relays the corresponding CRI request to plugins.
Expand Down
2 changes: 2 additions & 0 deletions pkg/adaptation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type (
StateChangeResponse = api.StateChangeResponse
RunPodSandboxRequest = api.RunPodSandboxRequest
RunPodSandboxResponse = api.RunPodSandboxResponse
PodSandboxAdjustment = api.PodSandboxAdjustment
PodSandboxNetwork = api.PodSandboxNetwork
UpdatePodSandboxRequest = api.UpdatePodSandboxRequest
UpdatePodSandboxResponse = api.UpdatePodSandboxResponse
StopPodSandboxRequest = api.StopPodSandboxRequest
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 @@ -240,7 +240,8 @@ func (m *mockRuntime) synchronize(ctx context.Context, cb nri.SyncCB) error {
func (m *mockRuntime) RunPodSandbox(ctx context.Context, req *api.RunPodSandboxRequest) error {
b := m.runtime.BlockPluginSync()
defer b.Unblock()
return m.runtime.RunPodSandbox(ctx, req)
_, err := m.runtime.RunPodSandbox(ctx, req)
return err
}

func (m *mockRuntime) UpdatePodSandbox(ctx context.Context, req *api.UpdatePodSandboxRequest) (*api.UpdatePodSandboxResponse, error) {
Expand Down
Loading
Loading