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 27, 2023
1 parent 2dfd8fa commit 187ea17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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/sirupsen/logrus"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -48,6 +49,7 @@ type ConmonClient struct {
attachReaders *sync.Map // K: UUID string, V: *attachReaderValue
tracingEnabled bool
tracer trace.Tracer
version semver.Version
}

// ConmonServerConfig is the configuration for the conmon server instance.
Expand Down Expand Up @@ -536,6 +538,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.version = semverVersion

tag, err := response.Tag()
if err != nil {
return nil, fmt.Errorf("set tag: %w", err)
Expand Down Expand Up @@ -1038,6 +1046,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.version.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
6 changes: 6 additions & 0 deletions pkg/client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package client

import "errors"

// ErrUnsupported gets returned if the server does not the feature.
var ErrUnsupported = errors.New("feature not supported by this conmon-rs version")

0 comments on commit 187ea17

Please sign in to comment.