Skip to content

Commit c0cc785

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

File tree

9 files changed

+171
-126
lines changed

9 files changed

+171
-126
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,18 +67,23 @@ 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
80+
Name string
81+
CNIVersion string
82+
DisableCheck bool
7983
DisableGC bool
80-
Plugins []*NetworkConfig
81-
Bytes []byte
84+
LoadOnlyInlinedPlugins bool
85+
Plugins []*PluginConfig
86+
Bytes []byte
8287
}
8388

8489
type NetworkAttachment struct {
@@ -102,14 +107,14 @@ type CNI interface {
102107
GetNetworkListCachedResult(net *NetworkConfigList, rt *RuntimeConf) (types.Result, error)
103108
GetNetworkListCachedConfig(net *NetworkConfigList, rt *RuntimeConf) ([]byte, *RuntimeConf, error)
104109

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

111116
ValidateNetworkList(ctx context.Context, net *NetworkConfigList) ([]string, error)
112-
ValidateNetwork(ctx context.Context, net *NetworkConfig) ([]string, error)
117+
ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error)
113118

114119
GCNetworkList(ctx context.Context, net *NetworkConfigList, args *GCArgs) error
115120
GetStatusNetworkList(ctx context.Context, net *NetworkConfigList) error
@@ -147,7 +152,7 @@ func NewCNIConfigWithCacheDir(path []string, cacheDir string, exec invoke.Exec)
147152
}
148153
}
149154

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

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

189194
rc := make(map[string]interface{})
@@ -404,7 +409,7 @@ func (c *CNIConfig) GetNetworkListCachedResult(list *NetworkConfigList, rt *Runt
404409

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

@@ -416,7 +421,7 @@ func (c *CNIConfig) GetNetworkListCachedConfig(list *NetworkConfigList, rt *Runt
416421

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

@@ -482,7 +487,7 @@ func (c *CNIConfig) GetCachedAttachments(containerID string) ([]*NetworkAttachme
482487
return attachments, nil
483488
}
484489

485-
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
490+
func (c *CNIConfig) addNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) (types.Result, error) {
486491
c.ensureExec()
487492
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
488493
if err != nil {
@@ -524,7 +529,7 @@ func (c *CNIConfig) AddNetworkList(ctx context.Context, list *NetworkConfigList,
524529
return result, nil
525530
}
526531

527-
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
532+
func (c *CNIConfig) checkNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
528533
c.ensureExec()
529534
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
530535
if err != nil {
@@ -566,7 +571,7 @@ func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigLis
566571
return nil
567572
}
568573

569-
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *NetworkConfig, prevResult types.Result, rt *RuntimeConf) error {
574+
func (c *CNIConfig) delNetwork(ctx context.Context, name, cniVersion string, net *PluginConfig, prevResult types.Result, rt *RuntimeConf) error {
570575
c.ensureExec()
571576
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
572577
if err != nil {
@@ -607,7 +612,7 @@ func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList,
607612
return nil
608613
}
609614

610-
func pluginDescription(net *types.NetConf) string {
615+
func pluginDescription(net *types.PluginConf) string {
611616
if net == nil {
612617
return "<missing>"
613618
}
@@ -621,7 +626,7 @@ func pluginDescription(net *types.NetConf) string {
621626
}
622627

623628
// AddNetwork executes the plugin with the ADD command
624-
func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error) {
629+
func (c *CNIConfig) AddNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) (types.Result, error) {
625630
result, err := c.addNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, nil, rt)
626631
if err != nil {
627632
return nil, err
@@ -635,7 +640,7 @@ func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *Runt
635640
}
636641

637642
// CheckNetwork executes the plugin with the CHECK command
638-
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) error {
643+
func (c *CNIConfig) CheckNetwork(ctx context.Context, net *PluginConfig, rt *RuntimeConf) error {
639644
// CHECK was added in CNI spec version 0.4.0 and higher
640645
if gtet, err := version.GreaterThanOrEqualTo(net.Network.CNIVersion, "0.4.0"); err != nil {
641646
return err
@@ -651,7 +656,7 @@ func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *Ru
651656
}
652657

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

657662
// Cached result on DEL was added in CNI spec version 0.4.0 and higher
@@ -711,7 +716,7 @@ func (c *CNIConfig) ValidateNetworkList(ctx context.Context, list *NetworkConfig
711716
// ValidateNetwork checks that a configuration is reasonably valid.
712717
// It uses the same logic as ValidateNetworkList)
713718
// Returns a list of capabilities
714-
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *NetworkConfig) ([]string, error) {
719+
func (c *CNIConfig) ValidateNetwork(ctx context.Context, net *PluginConfig) ([]string, error) {
715720
caps := []string{}
716721
for c, ok := range net.Network.Capabilities {
717722
if ok {
@@ -834,7 +839,7 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList,
834839
return errors.Join(errs...)
835840
}
836841

837-
func (c *CNIConfig) gcNetwork(ctx context.Context, net *NetworkConfig) error {
842+
func (c *CNIConfig) gcNetwork(ctx context.Context, net *PluginConfig) error {
838843
c.ensureExec()
839844
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
840845
if err != nil {
@@ -869,7 +874,7 @@ func (c *CNIConfig) GetStatusNetworkList(ctx context.Context, list *NetworkConfi
869874
return nil
870875
}
871876

872-
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *NetworkConfig) error {
877+
func (c *CNIConfig) getStatusNetwork(ctx context.Context, net *PluginConfig) error {
873878
c.ensureExec()
874879
pluginPath, err := c.exec.FindInPath(net.Network.Type, c.Path)
875880
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

@@ -1636,7 +1636,7 @@ var _ = Describe("Invoking plugins", func() {
16361636
cniBinPath string
16371637
pluginConfig string
16381638
cniConfig *libcni.CNIConfig
1639-
netConfig *libcni.NetworkConfig
1639+
netConfig *libcni.PluginConfig
16401640
runtimeConfig *libcni.RuntimeConf
16411641
netConfigList *libcni.NetworkConfigList
16421642
)
@@ -1809,7 +1809,7 @@ var _ = Describe("Invoking plugins", func() {
18091809
cniBinPath string
18101810
pluginConfig string
18111811
cniConfig *libcni.CNIConfig
1812-
netConfig *libcni.NetworkConfig
1812+
netConfig *libcni.PluginConfig
18131813
runtimeConfig *libcni.RuntimeConf
18141814

18151815
ctx context.Context
@@ -1931,14 +1931,14 @@ var _ = Describe("Invoking plugins", func() {
19311931
Context("when the RuntimeConf is incomplete", func() {
19321932
var (
19331933
testRt *libcni.RuntimeConf
1934-
testNetConf *libcni.NetworkConfig
1934+
testNetConf *libcni.PluginConfig
19351935
testNetConfList *libcni.NetworkConfigList
19361936
)
19371937

19381938
BeforeEach(func() {
19391939
testRt = &libcni.RuntimeConf{}
1940-
testNetConf = &libcni.NetworkConfig{
1941-
Network: &types.NetConf{},
1940+
testNetConf = &libcni.PluginConfig{
1941+
Network: &types.PluginConf{},
19421942
}
19431943
testNetConfList = &libcni.NetworkConfigList{}
19441944
})

0 commit comments

Comments
 (0)