Skip to content

Commit

Permalink
Check supported version for CreateNamespaces RPC
Browse files Browse the repository at this point in the history
We now pre-check if conmon-rs supports the `CreateNamespaces` RPC and
return a wrapped defined error if not.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jan 30, 2023
1 parent d1e4340 commit 251ff8d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions pkg/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

0 comments on commit 251ff8d

Please sign in to comment.