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 <[email protected]>
  • Loading branch information
squeed committed Jan 12, 2024
1 parent cd9b222 commit 0bca329
Show file tree
Hide file tree
Showing 3 changed files with 12 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 @@ -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
}
Expand All @@ -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,
}
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
8 changes: 8 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bca329

Please sign in to comment.