Skip to content

Commit

Permalink
driver(container): fix conditional statement for error handling
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jan 5, 2024
1 parent 671347d commit 8eeada0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions driver/docker-container/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (f *factory) New(ctx context.Context, cfg driver.InitConfig) (driver.Driver
case k == "image":
d.image = v
case k == "memory":
if err := d.memory.Set(v); err == nil {
if err := d.memory.Set(v); err != nil {
return nil, err
}
case k == "memory-swap":
if err := d.memorySwap.Set(v); err == nil {
if err := d.memorySwap.Set(v); err != nil {
return nil, err
}
case k == "cpu-period":
Expand Down
42 changes: 42 additions & 0 deletions tests/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tests

import (
"strings"
"testing"

"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
)

func createCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
opts = append([]cmdOpt{withArgs("create")}, opts...)
cmd := buildxCmd(sb, opts...)
out, err := cmd.CombinedOutput()
return string(out), err
}

var createTests = []func(t *testing.T, sb integration.Sandbox){
testCreateMemoryLimit,
}

func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker-container" {
t.Skip("only testing for docker-container driver")
}

var builderName string
t.Cleanup(func() {
if builderName == "" {
return
}
out, err := rmCmd(sb, withArgs(builderName))
require.NoError(t, err, out)
})

out, err := createCmd(sb, withArgs("--driver", "docker-container", "--driver-opt", "memory=1g"))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)

out, err = inspectCmd(sb, withArgs(builderName, "--bootstrap"))
require.NoError(t, err, out)

Check failure on line 41 in tests/create.go

View workflow job for this annotation

GitHub Actions / test (docker-container, ./tests)

Failed: tests/TestIntegration/TestCreateMemoryLimit/worker=docker-container

=== RUN TestIntegration/TestCreateMemoryLimit/worker=docker-container === PAUSE TestIntegration/TestCreateMemoryLimit/worker=docker-container === CONT TestIntegration/TestCreateMemoryLimit/worker=docker-container create.go:41: Error Trace: /src/tests/create.go:41 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:91 /src/vendor/github.com/moby/buildkit/util/testutil/integration/run.go:205 Error: Received unexpected error: exit status 1 Test: TestIntegration/TestCreateMemoryLimit/worker=docker-container Messages: #1 [internal] booting buildkit #1 pulling image moby/buildkit:buildx-stable-1 0.0s done #1 creating container buildx_buildkit_zealous_ramanujan0 #1 creating container buildx_buildkit_zealous_ramanujan0 0.2s done #1 ERROR: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: cannot enter cgroupv2 "/sys/fs/cgroup/docker" with domain controllers -- it is in threaded mode: unknown ------ > [internal] booting buildkit: ------ ERROR: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: cannot enter cgroupv2 "/sys/fs/cgroup/docker" with domain controllers -- it is in threaded mode: unknown --- FAIL: TestIntegration/TestCreateMemoryLimit/worker=docker-container (6.06s)
}
1 change: 1 addition & 0 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestIntegration(t *testing.T) {
tests = append(tests, lsTests...)
tests = append(tests, imagetoolsTests...)
tests = append(tests, versionTests...)
tests = append(tests, createTests...)
testIntegration(t, tests...)
}

Expand Down
12 changes: 12 additions & 0 deletions tests/rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tests

import (
"github.com/moby/buildkit/util/testutil/integration"
)

func rmCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
opts = append([]cmdOpt{withArgs("rm")}, opts...)
cmd := buildxCmd(sb, opts...)
out, err := cmd.CombinedOutput()
return string(out), err
}

0 comments on commit 8eeada0

Please sign in to comment.