diff --git a/go.mod b/go.mod index ea66e80b70..3f863afa6a 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( capnproto.org/go/capnp/v3 v3.0.0-alpha.9 + github.com/blang/semver/v4 v4.0.0 github.com/containers/common v0.51.0 github.com/containers/storage v1.45.3 github.com/google/uuid v1.3.0 @@ -17,7 +18,6 @@ require ( ) require ( - github.com/blang/semver/v4 v4.0.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/cyphar/filepath-securejoin v0.2.3 // indirect github.com/docker/go-units v0.5.0 // indirect diff --git a/pkg/client/client.go b/pkg/client/client.go index 2f297d9c9a..98f4c21a5c 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -17,6 +17,7 @@ import ( "capnproto.org/go/capnp/v3" "capnproto.org/go/capnp/v3/rpc" + "github.com/blang/semver/v4" "github.com/containers/conmon-rs/internal/proto" "github.com/containers/storage/pkg/idtools" "github.com/sirupsen/logrus" @@ -49,6 +50,7 @@ type ConmonClient struct { attachReaders *sync.Map // K: UUID string, V: *attachReaderValue tracingEnabled bool tracer trace.Tracer + serverVersion semver.Version } // ConmonServerConfig is the configuration for the conmon server instance. @@ -537,6 +539,12 @@ func (c *ConmonClient) Version( return nil, fmt.Errorf("set version: %w", err) } + semverVersion, err := semver.Parse(version) + if err != nil { + return nil, fmt.Errorf("parse server version to semver: %w", err) + } + c.serverVersion = semverVersion + tag, err := response.Tag() if err != nil { return nil, fmt.Errorf("set tag: %w", err) @@ -1043,6 +1051,13 @@ func (c *ConmonClient) CreateNamespaces( defer span.End() } + // Feature not supported pre v0.5.0 + const minMinor = 5 + minVersion := semver.Version{Minor: minMinor} + if c.serverVersion.LT(minVersion) { + return nil, fmt.Errorf("requires at least %v: %w", minVersion, ErrUnsupported) + } + conn, err := c.newRPCConn() if err != nil { return nil, fmt.Errorf("create RPC connection: %w", err) diff --git a/pkg/client/consts.go b/pkg/client/consts.go index 58c7fcc5e5..4866a69dd1 100644 --- a/pkg/client/consts.go +++ b/pkg/client/consts.go @@ -38,7 +38,7 @@ const ( type CgroupManager int const ( - // Name specifies to use systemd to create and manage + // CgroupManagerSystemd specifies to use systemd to create and manage // cgroups. CgroupManagerSystemd CgroupManager = iota diff --git a/pkg/client/errors.go b/pkg/client/errors.go index a178879f6f..7a2c9d7e24 100644 --- a/pkg/client/errors.go +++ b/pkg/client/errors.go @@ -2,6 +2,11 @@ package client import "errors" -// ErrMissingIDMappings gets returned if user namespace unsharing is selected -// but no IDMappings being provided. -var ErrMissingIDMappings = errors.New("unsharing user namespace selected but no IDMappings provided") +var ( + // ErrMissingIDMappings gets returned if user namespace unsharing is selected + // but no IDMappings being provided. + ErrMissingIDMappings = errors.New("unsharing user namespace selected but no IDMappings provided") + + // ErrUnsupported gets returned if the server does not the feature. + ErrUnsupported = errors.New("feature not supported by this conmon-rs version") +)