Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated error if no PID namespace should be unshared #1085

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ linters:
# - wsl
linters-settings:
funlen:
lines: 155
lines: 200
statements: 50
varnamelen:
min-name-length: 1
cyclop:
max-complexity: 35
max-complexity: 40
gocognit:
min-complexity: 50
min-complexity: 55
gocyclo:
min-complexity: 50
min-complexity: 55
nestif:
min-complexity: 15
errcheck:
Expand Down
14 changes: 14 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,20 @@ func (c *ConmonClient) CreateNamespaces(
return nil, fmt.Errorf("requires at least %v: %w", minVersion, ErrUnsupported)
}

// The pause process is only required if a PID namespace should be unshared.
foundPIDNamespace := false
for _, ns := range cfg.Namespaces {
if ns == NamespacePID {
foundPIDNamespace = true

break
}
}

if !foundPIDNamespace {
return nil, ErrNoPIDNamespaceSpecified
}

conn, err := c.newRPCConn()
if err != nil {
return nil, fmt.Errorf("create RPC connection: %w", err)
Expand Down
27 changes: 23 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client_test
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -522,7 +521,7 @@ var _ = Describe("ConmonClient", func() {
})

Describe("CreateNamespaces", func() {
It("should succeed without namespaces", func() {
It("should succeed with PID namespace", func() {
tr = newTestRunner()
tr.createRuntimeConfig(false)
sut = tr.configGivenEnv()
Expand All @@ -532,13 +531,32 @@ var _ = Describe("ConmonClient", func() {
response, err := sut.CreateNamespaces(
context.Background(),
&client.CreateaNamespacesConfig{
PodID: podID,
PodID: podID,
Namespaces: []client.Namespace{client.NamespacePID},
},
)
Expect(err).To(BeNil())
Expect(response).NotTo(BeNil())
})

It("should fail without PID namespace", func() {
tr = newTestRunner()
tr.createRuntimeConfig(false)
sut = tr.configGivenEnv()

podID := uuid.New().String()

response, err := sut.CreateNamespaces(
context.Background(),
&client.CreateaNamespacesConfig{
PodID: podID,
},
)
Expect(err).NotTo(Succeed())
Expect(err).To(MatchError(client.ErrNoPIDNamespaceSpecified))
Expect(response).To(BeNil())
})

It("should fail without pod ID", func() {
tr = newTestRunner()
tr.createRuntimeConfig(false)
Expand Down Expand Up @@ -661,12 +679,13 @@ var _ = Describe("ConmonClient", func() {
context.Background(),
&client.CreateaNamespacesConfig{
Namespaces: []client.Namespace{
client.NamespacePID,
client.NamespaceUser,
},
},
)
Expect(err).NotTo(BeNil())
Expect(errors.Is(err, client.ErrMissingIDMappings)).To(BeTrue())
Expect(err).To(MatchError(client.ErrMissingIDMappings))
Expect(response).To(BeNil())
})
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ var (

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

// ErrNoPIDNamespaceSpecified gets returned if no PID namespace should be
// unshared via the CreateaNamespacesConfig in the CreateNamespaces method.
ErrNoPIDNamespaceSpecified = errors.New("no PID namespace specified")
)