Skip to content

Commit 45eac09

Browse files
committed
Use type aliases to hint deprecation for old API types (#928)
Signed-off-by: Benjamin Leggett <[email protected]>
1 parent 3b789c5 commit 45eac09

File tree

9 files changed

+170
-122
lines changed

9 files changed

+170
-122
lines changed

Diff for: cnitool/cnitool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func main() {
6666
if netdir == "" {
6767
netdir = DefaultNetDir
6868
}
69-
netconf, err := libcni.LoadConfList(netdir, os.Args[2])
69+
netconf, err := libcni.LoadNetworkConf(netdir, os.Args[2])
7070
if err != nil {
7171
exit(err)
7272
}

Diff for: libcni/api.go

+32-27
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,22 @@ type RuntimeConf struct {
6767
CacheDir string
6868
}
6969

70-
type NetworkConfig struct {
71-
Network *types.NetConf
70+
// Deprecated: Use PluginConfig instead of NetworkConfig, the NetworkConfig
71+
// backwards-compat alias will be removed in a future release.
72+
type NetworkConfig = PluginConfig
73+
74+
type PluginConfig struct {
75+
Network *types.PluginConf
7276
Bytes []byte
7377
}
7478

7579
type NetworkConfigList struct {
76-
Name string
77-
CNIVersion string
78-
DisableCheck bool
79-
Plugins []*NetworkConfig
80-
Bytes []byte
80+
Name string
81+
CNIVersion string
82+
DisableCheck bool
83+
LoadOnlyInlinedPlugins bool
84+
Plugins []*PluginConfig
85+
Bytes []byte
8186
}
8287

8388
type NetworkAttachment struct {
@@ -101,14 +106,14 @@ type CNI interface {
101106
GetNetworkListCachedResult(net *NetworkConfigList, rt *RuntimeConf) (types.Result, error)
102107
GetNetworkListCachedConfig(net *NetworkConfigList, rt *RuntimeConf) ([]byte, *RuntimeConf, error)
103108

104-
AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error)
105-
CheckNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error
106-
DelNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error
107-
GetNetworkCachedResult(net *NetworkConfig, rt *RuntimeConf) (types.Result, error)
108-
GetNetworkCachedConfig(net *NetworkConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error)
109+
AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error)
110+
CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error
111+
DelNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error
112+
GetNetworkCachedResult(net *PluginConfig, rt *RuntimeConf) (types.Result, error)
113+
GetNetworkCachedConfig(net *PluginConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error)
109114

110115
ValidateNetworkList(ctx context.Context, net *NetworkConfigList) ([]string, error)
111-
ValidateNetwork(ctx context.Context, net *NetworkConfig) ([]string, error)
116+
ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error)
112117

113118
GCNetworkList(ctx context.Context, net *NetworkConfigList, args *GCArgs) error
114119
GetStatusNetworkList(ctx context.Context, net *NetworkConfigList) error
@@ -144,7 +149,7 @@ func NewCNIConfigWithCacheDir(path []string, cacheDir string, exec invoke.Exec)
144149
}
145150
}
146151

147-
func buildOneConfig(name, cniVersion string, orig *NetworkConfig, prevResult types.Result, rt *RuntimeConf) (*NetworkConfig, error) {
152+
func buildOneConfig(name, cniVersion string, orig *PluginConfig, prevResult types.Result, rt *RuntimeConf) (*PluginConfig, error) {
148153
var err error
149154

150155
inject := map[string]interface{}{
@@ -180,7 +185,7 @@ func buildOneConfig(name, cniVersion string, orig *NetworkConfig, prevResult typ
180185
// capabilities include "portMappings", and the CapabilityArgs map includes a
181186
// "portMappings" key, that key and its value are added to the "runtimeConfig"
182187
// dictionary to be passed to the plugin's stdin.
183-
func injectRuntimeConfig(orig *NetworkConfig, rt *RuntimeConf) (*NetworkConfig, error) {
188+
func injectRuntimeConfig(orig *PluginConfig, rt *RuntimeConf) (*PluginConfig, error) {
184189
var err error
185190

186191
rc := make(map[string]interface{})
@@ -401,7 +406,7 @@ func (c *CNIConfig) GetNetworkListCachedResult(list *NetworkConfigList, rt *Runt
401406

402407
// GetNetworkCachedResult returns the cached Result of the previous
403408
// AddNetwork() operation for a network, or an error.
404-
func (c *CNIConfig) GetNetworkCachedResult(net *NetworkConfig, rt *RuntimeConf) (types.Result, error) {
409+
func (c *CNIConfig) GetNetworkCachedResult(net *PluginConfig, rt *RuntimeConf) (types.Result, error) {
405410
return c.getCachedResult(net.Network.Name, net.Network.CNIVersion, rt)
406411
}
407412

@@ -413,7 +418,7 @@ func (c *CNIConfig) GetNetworkListCachedConfig(list *NetworkConfigList, rt *Runt
413418

414419
// GetNetworkCachedConfig copies the input RuntimeConf to output
415420
// RuntimeConf with fields updated with info from the cached Config.
416-
func (c *CNIConfig) GetNetworkCachedConfig(net *NetworkConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error) {
421+
func (c *CNIConfig) GetNetworkCachedConfig(net *PluginConfig, rt *RuntimeConf) ([]byte, *RuntimeConf, error) {
417422
return c.getCachedConfig(net.Network.Name, rt)
418423
}
419424

@@ -476,7 +481,7 @@ func (c *CNIConfig) GetCachedAttachments(containerID string) ([]*NetworkAttachme
476481
return attachments, nil
477482
}
478483

479-
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
484+
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
480485
c.ensureExec()
481486
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
482487
if err != nil {
@@ -518,7 +523,7 @@ func (c *CNIConfig) AddNetworkList(ctx context.Context, list *NetworkConfigList,
518523
return result, nil
519524
}
520525

521-
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
526+
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
522527
c.ensureExec()
523528
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
524529
if err != nil {
@@ -560,7 +565,7 @@ func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigLis
560565
return nil
561566
}
562567

563-
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
568+
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
564569
c.ensureExec()
565570
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
566571
if err != nil {
@@ -603,7 +608,7 @@ func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList,
603608
return nil
604609
}
605610

606-
func pluginDescription(net *types.NetConf) string {
611+
func pluginDescription(net *types.PluginConf) string {
607612
if net == nil {
608613
return "<missing>"
609614
}
@@ -617,7 +622,7 @@ func pluginDescription(net *types.NetConf) string {
617622
}
618623

619624
// AddNetwork executes the plugin with the ADD command
620-
func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error) {
625+
func (c *CNIConfig) AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error) {
621626
result, err := c.addNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, nil, rt)
622627
if err != nil {
623628
return nil, err
@@ -631,7 +636,7 @@ func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *Runt
631636
}
632637

633638
// CheckNetwork executes the plugin with the CHECK command
634-
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error {
639+
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error {
635640
// CHECK was added in CNI spec version 0.4.0 and higher
636641
if gtet, err := version.GreaterThanOrEqualTo(net.Network.CNIVersion, "0.4.0"); err != nil {
637642
return err
@@ -647,7 +652,7 @@ func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *Ru
647652
}
648653

649654
// DelNetwork executes the plugin with the DEL command
650-
func (c *CNIConfig) DelNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error {
655+
func (c *CNIConfig) DelNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error {
651656
var cachedResult types.Result
652657

653658
// Cached result on DEL was added in CNI spec version 0.4.0 and higher
@@ -707,7 +712,7 @@ func (c *CNIConfig) ValidateNetworkList(ctx context.Context, list *NetworkConfig
707712
// ValidateNetwork checks that a configuration is reasonably valid.
708713
// It uses the same logic as ValidateNetworkList)
709714
// Returns a list of capabilities
710-
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *NetworkConfig) ([]string, error) {
715+
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error) {
711716
caps := []string{}
712717
for c, ok := range net.Network.Capabilities {
713718
if ok {
@@ -819,7 +824,7 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList,
819824
return errors.Join(errs...)
820825
}
821826

822-
func (c *CNIConfig) gcNetwork(ctx context.Context, net *NetworkConfig) error {
827+
func (c *CNIConfig) gcNetwork(ctx context.Context, net *PluginConfig) error {
823828
c.ensureExec()
824829
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
825830
if err != nil {
@@ -854,7 +859,7 @@ func (c *CNIConfig) GetStatusNetworkList(ctx context.Context, list *NetworkConfi
854859
return nil
855860
}
856861

857-
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *NetworkConfig) error {
862+
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *PluginConfig) error {
858863
c.ensureExec()
859864
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
860865
if err != nil {

Diff for: libcni/api_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ var _ = Describe("Invoking plugins", func() {
176176
pluginConfig []byte
177177
cniConfig *libcni.CNIConfig
178178
runtimeConfig *libcni.RuntimeConf
179-
netConfig *libcni.NetworkConfig
179+
netConfig *libcni.PluginConfig
180180
ctx context.Context
181181
)
182182

@@ -295,7 +295,7 @@ var _ = Describe("Invoking plugins", func() {
295295
debug *noop_debug.Debug
296296
pluginConfig string
297297
cniConfig *libcni.CNIConfig
298-
netConfig *libcni.NetworkConfig
298+
netConfig *libcni.PluginConfig
299299
runtimeConfig *libcni.RuntimeConf
300300
ctx context.Context
301301

@@ -1625,7 +1625,7 @@ var _ = Describe("Invoking plugins", func() {
16251625
cniBinPath string
16261626
pluginConfig string
16271627
cniConfig *libcni.CNIConfig
1628-
netConfig *libcni.NetworkConfig
1628+
netConfig *libcni.PluginConfig
16291629
runtimeConfig *libcni.RuntimeConf
16301630
netConfigList *libcni.NetworkConfigList
16311631
)
@@ -1798,7 +1798,7 @@ var _ = Describe("Invoking plugins", func() {
17981798
cniBinPath string
17991799
pluginConfig string
18001800
cniConfig *libcni.CNIConfig
1801-
netConfig *libcni.NetworkConfig
1801+
netConfig *libcni.PluginConfig
18021802
runtimeConfig *libcni.RuntimeConf
18031803

18041804
ctx context.Context
@@ -1920,14 +1920,14 @@ var _ = Describe("Invoking plugins", func() {
19201920
Context("when the RuntimeConf is incomplete", func() {
19211921
var (
19221922
testRt *libcni.RuntimeConf
1923-
testNetConf *libcni.NetworkConfig
1923+
testNetConf *libcni.PluginConfig
19241924
testNetConfList *libcni.NetworkConfigList
19251925
)
19261926

19271927
BeforeEach(func() {
19281928
testRt = &libcni.RuntimeConf{}
1929-
testNetConf = &libcni.NetworkConfig{
1930-
Network: &types.NetConf{},
1929+
testNetConf = &libcni.PluginConfig{
1930+
Network: &types.PluginConf{},
19311931
}
19321932
testNetConfList = &libcni.NetworkConfigList{}
19331933
})

0 commit comments

Comments
 (0)