Skip to content

Commit 5d96e63

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

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
@@ -68,7 +68,7 @@ func main() {
6868
if netdir == "" {
6969
netdir = DefaultNetDir
7070
}
71-
netconf, err := libcni.LoadConfList(netdir, os.Args[2])
71+
netconf, err := libcni.LoadNetworkConf(netdir, os.Args[2])
7272
if err != nil {
7373
exit(err)
7474
}

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
@@ -146,7 +151,7 @@ func NewCNIConfigWithCacheDir(path []string, cacheDir string, exec invoke.Exec)
146151
}
147152
}
148153

149-
func buildOneConfig(name, cniVersion string, orig *NetworkConfig, prevResult types.Result, rt *RuntimeConf) (*NetworkConfig, error) {
154+
func buildOneConfig(name, cniVersion string, orig *PluginConfig, prevResult types.Result, rt *RuntimeConf) (*PluginConfig, error) {
150155
var err error
151156

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

188193
rc := make(map[string]interface{})
@@ -403,7 +408,7 @@ func (c *CNIConfig) GetNetworkListCachedResult(list *NetworkConfigList, rt *Runt
403408

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

@@ -415,7 +420,7 @@ func (c *CNIConfig) GetNetworkListCachedConfig(list *NetworkConfigList, rt *Runt
415420

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

@@ -478,7 +483,7 @@ func (c *CNIConfig) GetCachedAttachments(containerID string) ([]*NetworkAttachme
478483
return attachments, nil
479484
}
480485

481-
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
486+
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
482487
c.ensureExec()
483488
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
484489
if err != nil {
@@ -520,7 +525,7 @@ func (c *CNIConfig) AddNetworkList(ctx context.Context, list *NetworkConfigList,
520525
return result, nil
521526
}
522527

523-
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
528+
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
524529
c.ensureExec()
525530
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
526531
if err != nil {
@@ -562,7 +567,7 @@ func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigLis
562567
return nil
563568
}
564569

565-
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
570+
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
566571
c.ensureExec()
567572
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
568573
if err != nil {
@@ -605,7 +610,7 @@ func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList,
605610
return nil
606611
}
607612

608-
func pluginDescription(net *types.NetConf) string {
613+
func pluginDescription(net *types.PluginConf) string {
609614
if net == nil {
610615
return "<missing>"
611616
}
@@ -619,7 +624,7 @@ func pluginDescription(net *types.NetConf) string {
619624
}
620625

621626
// AddNetwork executes the plugin with the ADD command
622-
func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error) {
627+
func (c *CNIConfig) AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error) {
623628
result, err := c.addNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, nil, rt)
624629
if err != nil {
625630
return nil, err
@@ -633,7 +638,7 @@ func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *Runt
633638
}
634639

635640
// CheckNetwork executes the plugin with the CHECK command
636-
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error {
641+
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error {
637642
// CHECK was added in CNI spec version 0.4.0 and higher
638643
if gtet, err := version.GreaterThanOrEqualTo(net.Network.CNIVersion, "0.4.0"); err != nil {
639644
return err
@@ -649,7 +654,7 @@ func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *Ru
649654
}
650655

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

655660
// Cached result on DEL was added in CNI spec version 0.4.0 and higher
@@ -709,7 +714,7 @@ func (c *CNIConfig) ValidateNetworkList(ctx context.Context, list *NetworkConfig
709714
// ValidateNetwork checks that a configuration is reasonably valid.
710715
// It uses the same logic as ValidateNetworkList)
711716
// Returns a list of capabilities
712-
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *NetworkConfig) ([]string, error) {
717+
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error) {
713718
caps := []string{}
714719
for c, ok := range net.Network.Capabilities {
715720
if ok {
@@ -827,7 +832,7 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList,
827832
return errors.Join(errs...)
828833
}
829834

830-
func (c *CNIConfig) gcNetwork(ctx context.Context, net *NetworkConfig) error {
835+
func (c *CNIConfig) gcNetwork(ctx context.Context, net *PluginConfig) error {
831836
c.ensureExec()
832837
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
833838
if err != nil {
@@ -862,7 +867,7 @@ func (c *CNIConfig) GetStatusNetworkList(ctx context.Context, list *NetworkConfi
862867
return nil
863868
}
864869

865-
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *NetworkConfig) error {
870+
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *PluginConfig) error {
866871
c.ensureExec()
867872
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
868873
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)