Skip to content

Commit

Permalink
vendor: github.com/docker/docker 59b119f94e6d (master, v27.0-dev)
Browse files Browse the repository at this point in the history
Rewrite local code to use the new container.Ulimit alias to start
transitioning away from direct uses of go-units.Ulimit.

full diff: moby/moby@v27.0.0-rc.2...59b119f

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jun 18, 2024
1 parent 64206ae commit 427782c
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 54 deletions.
3 changes: 1 addition & 2 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
units "github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -81,7 +80,7 @@ func (o buildOptions) contextFromStdin() bool {
}

func newBuildOptions() buildOptions {
ulimits := make(map[string]*units.Ulimit)
ulimits := make(map[string]*container.Ulimit)
return buildOptions{
tags: opts.NewListOpts(validateTag),
buildArgs: opts.NewListOpts(opts.ValidateEnv),
Expand Down
7 changes: 3 additions & 4 deletions cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
units "github.com/docker/go-units"
"github.com/moby/swarmkit/v2/api/defaults"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -710,8 +709,8 @@ func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) {
}
}

func updateUlimits(flags *pflag.FlagSet, ulimits []*units.Ulimit) []*units.Ulimit {
newUlimits := make(map[string]*units.Ulimit)
func updateUlimits(flags *pflag.FlagSet, ulimits []*container.Ulimit) []*container.Ulimit {
newUlimits := make(map[string]*container.Ulimit)

for _, ulimit := range ulimits {
newUlimits[ulimit.Name] = ulimit
Expand All @@ -731,7 +730,7 @@ func updateUlimits(flags *pflag.FlagSet, ulimits []*units.Ulimit) []*units.Ulimi
if len(newUlimits) == 0 {
return nil
}
limits := make([]*units.Ulimit, 0, len(newUlimits))
limits := make([]*container.Ulimit, 0, len(newUlimits))
for _, ulimit := range newUlimits {
limits = append(limits, ulimit)
}
Expand Down
33 changes: 16 additions & 17 deletions cli/command/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-units"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down Expand Up @@ -1600,66 +1599,66 @@ func TestUpdateUlimits(t *testing.T) {

tests := []struct {
name string
spec []*units.Ulimit
spec []*container.Ulimit
rm []string
add []string
expected []*units.Ulimit
expected []*container.Ulimit
}{
{
name: "from scratch",
add: []string{"nofile=512:1024", "core=1024:1024"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "append new",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "nofile", Hard: 1024, Soft: 512},
},
add: []string{"core=1024:1024"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "remove and append new should append",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
rm: []string{"nofile=512:1024"},
add: []string{"nofile=512:1024"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "update existing",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "nofile", Hard: 2048, Soft: 1024},
},
add: []string{"nofile=512:1024"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "update existing twice",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "nofile", Hard: 2048, Soft: 1024},
},
add: []string{"nofile=256:512", "nofile=512:1024"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "remove all",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
Expand All @@ -1668,23 +1667,23 @@ func TestUpdateUlimits(t *testing.T) {
},
{
name: "remove by key",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
rm: []string{"core"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
{
name: "remove by key and different value",
spec: []*units.Ulimit{
spec: []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
},
rm: []string{"core=1234:5678"},
expected: []*units.Ulimit{
expected: []*container.Ulimit{
{Name: "nofile", Hard: 1024, Soft: 512},
},
},
Expand Down
11 changes: 5 additions & 6 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/go-units"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -693,24 +692,24 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
return &swarmCredSpec, nil
}

func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units.Ulimit {
newUlimits := make(map[string]*units.Ulimit)
func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*container.Ulimit {
newUlimits := make(map[string]*container.Ulimit)
for name, u := range origUlimits {
if u.Single != 0 {
newUlimits[name] = &units.Ulimit{
newUlimits[name] = &container.Ulimit{
Name: name,
Soft: int64(u.Single),
Hard: int64(u.Single),
}
} else {
newUlimits[name] = &units.Ulimit{
newUlimits[name] = &container.Ulimit{
Name: name,
Soft: int64(u.Soft),
Hard: int64(u.Hard),
}
}
}
ulimits := make([]*units.Ulimit, 0, len(newUlimits))
ulimits := make([]*container.Ulimit, 0, len(newUlimits))
for _, ulimit := range newUlimits {
ulimits = append(ulimits, ulimit)
}
Expand Down
13 changes: 8 additions & 5 deletions opts/ulimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ import (
"fmt"
"sort"

"github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
)

// UlimitOpt defines a map of Ulimits
type UlimitOpt struct {
values *map[string]*units.Ulimit
values *map[string]*container.Ulimit
}

// NewUlimitOpt creates a new UlimitOpt. Ulimits are not validated.
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
func NewUlimitOpt(ref *map[string]*container.Ulimit) *UlimitOpt {
// TODO(thaJeztah): why do we need a map with pointers here?
if ref == nil {
ref = &map[string]*units.Ulimit{}
ref = &map[string]*container.Ulimit{}
}
return &UlimitOpt{ref}
}

// Set validates a Ulimit and sets its name as a key in UlimitOpt
func (o *UlimitOpt) Set(val string) error {
// FIXME(thaJeztah): these functions also need to be moved over from go-units.
l, err := units.ParseUlimit(val)
if err != nil {
return err
Expand All @@ -43,8 +46,8 @@ func (o *UlimitOpt) String() string {
}

// GetList returns a slice of pointers to Ulimits. Values are sorted by name.
func (o *UlimitOpt) GetList() []*units.Ulimit {
ulimits := make([]*units.Ulimit, 0, len(*o.values))
func (o *UlimitOpt) GetList() []*container.Ulimit {
ulimits := make([]*container.Ulimit, 0, len(*o.values))
for _, v := range *o.values {
ulimits = append(ulimits, v)
}
Expand Down
8 changes: 4 additions & 4 deletions opts/ulimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package opts
import (
"testing"

"github.com/docker/go-units"
"github.com/docker/docker/api/types/container"
"gotest.tools/v3/assert"
)

func TestUlimitOpt(t *testing.T) {
ulimitMap := map[string]*units.Ulimit{
ulimitMap := map[string]*container.Ulimit{
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
}

Expand Down Expand Up @@ -37,12 +37,12 @@ func TestUlimitOpt(t *testing.T) {
}

func TestUlimitOptSorting(t *testing.T) {
ulimitOpt := NewUlimitOpt(&map[string]*units.Ulimit{
ulimitOpt := NewUlimitOpt(&map[string]*container.Ulimit{
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
"core": {Name: "core", Hard: 1024, Soft: 1024},
})

expected := []*units.Ulimit{
expected := []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
}
Expand Down
2 changes: 1 addition & 1 deletion vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/creack/pty v1.1.21
github.com/distribution/reference v0.6.0
github.com/docker/distribution v2.8.3+incompatible
github.com/docker/docker v27.0.0-rc.2+incompatible
github.com/docker/docker v27.0.0-rc.2.0.20240618192555-59b119f94e6d+incompatible // master (v27.0-dev)
github.com/docker/docker-credential-helpers v0.8.2
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v27.0.0-rc.2+incompatible h1:7h252klGbyDOfTpCxKFriEJSj8SpShcOwz9shs1k2n8=
github.com/docker/docker v27.0.0-rc.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v27.0.0-rc.2.0.20240618192555-59b119f94e6d+incompatible h1:I9kqiK7yKadNbnAuBedhX1Y2NrlDtwEn/HlOARO5ERY=
github.com/docker/docker v27.0.0-rc.2.0.20240618192555-59b119f94e6d+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
Expand Down
Loading

0 comments on commit 427782c

Please sign in to comment.