From 0bca329380a02f62f36e0b29465414da4aa13206 Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Fri, 12 Jan 2024 21:07:53 +0100 Subject: [PATCH] types: add ValidAttachments to "base" NetConf struct Since every plugin needs to deserialize this, it should be in the standard network configuration struct. Signed-off-by: Casey Callendrello --- libcni/api.go | 10 +++------- libcni/api_test.go | 2 +- pkg/types/types.go | 8 ++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libcni/api.go b/libcni/api.go index e004aa94..511c53d9 100644 --- a/libcni/api.go +++ b/libcni/api.go @@ -89,12 +89,8 @@ type NetworkAttachment struct { CapabilityArgs map[string]interface{} } -type GCAttachment struct { - ContainerID string `json:"containerID"` - IfName string `json:"ifname"` -} type GCArgs struct { - ValidAttachments []GCAttachment + ValidAttachments []types.GCAttachment } type CNI interface { @@ -765,7 +761,7 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList, return nil } - validAttachments := make(map[GCAttachment]interface{}, len(args.ValidAttachments)) + validAttachments := make(map[types.GCAttachment]interface{}, len(args.ValidAttachments)) for _, a := range args.ValidAttachments { validAttachments[a] = nil } @@ -777,7 +773,7 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList, continue } // we found this attachment - gca := GCAttachment{ + gca := types.GCAttachment{ ContainerID: cachedAttachment.ContainerID, IfName: cachedAttachment.IfName, } diff --git a/libcni/api_test.go b/libcni/api_test.go index 26852f39..2bf0cc3b 100644 --- a/libcni/api_test.go +++ b/libcni/api_test.go @@ -1513,7 +1513,7 @@ var _ = Describe("Invoking plugins", func() { By("Issuing a GC with valid networks") gcargs := &libcni.GCArgs{ - ValidAttachments: []libcni.GCAttachment{{ + ValidAttachments: []types.GCAttachment{{ ContainerID: runtimeConfig.ContainerID, IfName: runtimeConfig.IfName, }}, diff --git a/pkg/types/types.go b/pkg/types/types.go index 58b57947..bf1f2901 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -68,6 +68,14 @@ type NetConf struct { RawPrevResult map[string]interface{} `json:"prevResult,omitempty"` PrevResult Result `json:"-"` + + // ValidAttachments is only supplied when executing a GC operation + ValidAttachments []GCAttachment `json:"cni.dev/valid-attachments"` +} + +type GCAttachment struct { + ContainerID string `json:"containerID"` + IfName string `json:"ifname"` } // Note: DNS should be omit if DNS is empty but default Marshal function