Skip to content

Commit 8dba382

Browse files
committed
libcni: add specific type for CHECK not supported
Previously, we returned an arbitrary string error if the given CNI version didn't support CHECK. This is not useful for downstream consumption and matching. So, declare an error variable so that users can use `errors.Is()` instead of matching on a string. Signed-off-by: Casey Callendrello <[email protected]>
1 parent 40fa479 commit 8dba382

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

libcni/api.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838

3939
var (
4040
CacheDir = "/var/lib/cni"
41+
// slightly awkward wording to preserve anyone matching on error strings
42+
ErrorCheckNotSupp = fmt.Errorf("does not support the CHECK command")
4143
)
4244

4345
const (
@@ -453,7 +455,7 @@ func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigLis
453455
if gtet, err := version.GreaterThanOrEqualTo(list.CNIVersion, "0.4.0"); err != nil {
454456
return err
455457
} else if !gtet {
456-
return fmt.Errorf("configuration version %q does not support the CHECK command", list.CNIVersion)
458+
return fmt.Errorf("configuration version %q %w", list.CNIVersion, ErrorCheckNotSupp)
457459
}
458460

459461
if list.DisableCheck {
@@ -547,7 +549,7 @@ func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *Ru
547549
if gtet, err := version.GreaterThanOrEqualTo(net.Network.CNIVersion, "0.4.0"); err != nil {
548550
return err
549551
} else if !gtet {
550-
return fmt.Errorf("configuration version %q does not support the CHECK command", net.Network.CNIVersion)
552+
return fmt.Errorf("configuration version %q %w", net.Network.CNIVersion, ErrorCheckNotSupp)
551553
}
552554

553555
cachedResult, err := c.getCachedResult(net.Network.Name, net.Network.CNIVersion, rt)

libcni/api_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ var _ = Describe("Invoking plugins", func() {
12801280
Expect(err).NotTo(HaveOccurred())
12811281
err = cniConfig.CheckNetworkList(ctx, netConfigList, runtimeConfig)
12821282
Expect(err).To(MatchError("configuration version \"0.3.1\" does not support the CHECK command"))
1283+
Expect(errors.Is(err, libcni.ErrorCheckNotSupp)).To(BeTrue())
12831284
})
12841285
})
12851286
})

0 commit comments

Comments
 (0)