Skip to content

Commit

Permalink
types: add ValidAttachments to "base" NetConf struct
Browse files Browse the repository at this point in the history
Since every plugin needs to deserialize this, it should be in the
standard network configuration struct.

Signed-off-by: Casey Callendrello <c1@caseyc.net>
  • Loading branch information
squeed committed Mar 18, 2024
1 parent 8eb1091 commit 56f11c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 3 additions & 7 deletions libcni/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -768,7 +764,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
}
Expand All @@ -780,7 +776,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,
}
Expand Down
2 changes: 1 addition & 1 deletion libcni/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}},
Expand Down
11 changes: 11 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ 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,omitempty"`
}

// GCAttachment is the parameters to a GC call -- namely,
// the container ID and ifname pair that represents a
// still-valid attachment.
type GCAttachment struct {
ContainerID string `json:"containerID"`
IfName string `json:"ifname"`
}

// Note: DNS should be omit if DNS is empty but default Marshal function
Expand Down

0 comments on commit 56f11c6

Please sign in to comment.