Skip to content

Commit c2cb517

Browse files
committed
add envelope type
1 parent dde870f commit c2cb517

6 files changed

Lines changed: 2102 additions & 1668 deletions

File tree

pkg/adaptation/adaptation.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,42 +242,45 @@ func (r *Adaptation) Stop() {
242242
}
243243

244244
// RunPodSandbox relays the corresponding CRI request to plugins.
245-
// Plugins can return IP addresses for the pod sandbox in their response; the
246-
// IPs from every plugin are concatenated, in plugin invocation order, and
247-
// returned to the caller so they can be propagated through the runtime (e.g.
248-
// surfaced to the kubelet via CRI). Duplicate IP addresses (whether reported
249-
// by a single plugin or by multiple plugins) are collapsed; first occurrence
250-
// wins. Plugins that have nothing to contribute can return an empty response
251-
// or a nil response.
245+
// Plugins can return a PodSandboxAdjustment for the pod sandbox in their
246+
// response; the network IPs from every plugin are concatenated, in plugin
247+
// invocation order, into the response's PodSandboxAdjustment so they can be
248+
// propagated through the runtime (e.g. surfaced to the kubelet via CRI).
249+
// Duplicate IP addresses (whether reported by a single plugin or by multiple
250+
// plugins) are collapsed; first occurrence wins. Plugins that have nothing to
251+
// contribute can return an empty response or a nil response.
252252
func (r *Adaptation) RunPodSandbox(ctx context.Context, req *RunPodSandboxRequest) (*RunPodSandboxResponse, error) {
253253
r.Lock()
254254
defer r.Unlock()
255255
defer r.removeClosedPlugins()
256256

257257
var (
258-
rsp = &RunPodSandboxResponse{}
258+
ips []string
259259
seen = map[string]struct{}{}
260260
)
261261
for _, plugin := range r.plugins {
262262
pluginRsp, err := plugin.runPodSandbox(ctx, req)
263263
if err != nil {
264264
return nil, err
265265
}
266-
if pluginRsp == nil {
267-
continue
268-
}
269-
for _, ip := range pluginRsp.Ips {
266+
for _, ip := range pluginRsp.GetAdjust().GetNetwork().GetIps() {
270267
if ip == "" {
271268
continue
272269
}
273270
if _, ok := seen[ip]; ok {
274271
continue
275272
}
276273
seen[ip] = struct{}{}
277-
rsp.Ips = append(rsp.Ips, ip)
274+
ips = append(ips, ip)
278275
}
279276
}
280277

278+
rsp := &RunPodSandboxResponse{}
279+
if len(ips) > 0 {
280+
rsp.Adjust = &PodSandboxAdjustment{
281+
Network: &PodSandboxNetwork{Ips: ips},
282+
}
283+
}
281284
return rsp, nil
282285
}
283286

pkg/adaptation/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type (
5252
StateChangeResponse = api.StateChangeResponse
5353
RunPodSandboxRequest = api.RunPodSandboxRequest
5454
RunPodSandboxResponse = api.RunPodSandboxResponse
55+
PodSandboxAdjustment = api.PodSandboxAdjustment
56+
PodSandboxNetwork = api.PodSandboxNetwork
5557
UpdatePodSandboxRequest = api.UpdatePodSandboxRequest
5658
UpdatePodSandboxResponse = api.UpdatePodSandboxResponse
5759
StopPodSandboxRequest = api.StopPodSandboxRequest

0 commit comments

Comments
 (0)