Skip to content

Commit 2fee28c

Browse files
authored
Merge pull request #5170 from thaJeztah/bump_engine2
vendor: github.com/docker/docker 1a1f3cff45ec (master, v27.0-dev)
2 parents aebdf50 + 2088c59 commit 2fee28c

File tree

24 files changed

+230
-149
lines changed

24 files changed

+230
-149
lines changed

cli/command/container/stats_helpers.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/container"
1111
"github.com/docker/docker/client"
1212
"github.com/pkg/errors"
1313
"github.com/sirupsen/logrus"
@@ -50,7 +50,7 @@ func (s *stats) isKnownContainer(cid string) (int, bool) {
5050
return -1, false
5151
}
5252

53-
func collect(ctx context.Context, s *Stats, cli client.APIClient, streamStats bool, waitFirst *sync.WaitGroup) {
53+
func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, streamStats bool, waitFirst *sync.WaitGroup) {
5454
logrus.Debugf("collecting stats for %s", s.Container)
5555
var (
5656
getFirst bool
@@ -78,7 +78,7 @@ func collect(ctx context.Context, s *Stats, cli client.APIClient, streamStats bo
7878
go func() {
7979
for {
8080
var (
81-
v *types.StatsJSON
81+
v *container.StatsResponse
8282
memPercent, cpuPercent float64
8383
blkRead, blkWrite uint64 // Only used on Linux
8484
mem, memLimit float64
@@ -163,7 +163,7 @@ func collect(ctx context.Context, s *Stats, cli client.APIClient, streamStats bo
163163
}
164164
}
165165

166-
func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64 {
166+
func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *container.StatsResponse) float64 {
167167
var (
168168
cpuPercent = 0.0
169169
// calculate the change for the cpu usage of the container in between readings
@@ -182,7 +182,7 @@ func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJ
182182
return cpuPercent
183183
}
184184

185-
func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
185+
func calculateCPUPercentWindows(v *container.StatsResponse) float64 {
186186
// Max number of 100ns intervals between the previous time read and now
187187
possIntervals := uint64(v.Read.Sub(v.PreRead).Nanoseconds()) // Start with number of ns intervals
188188
possIntervals /= 100 // Convert to number of 100ns intervals
@@ -198,7 +198,7 @@ func calculateCPUPercentWindows(v *types.StatsJSON) float64 {
198198
return 0.00
199199
}
200200

201-
func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) {
201+
func calculateBlockIO(blkio container.BlkioStats) (uint64, uint64) {
202202
var blkRead, blkWrite uint64
203203
for _, bioEntry := range blkio.IoServiceBytesRecursive {
204204
if len(bioEntry.Op) == 0 {
@@ -214,7 +214,7 @@ func calculateBlockIO(blkio types.BlkioStats) (uint64, uint64) {
214214
return blkRead, blkWrite
215215
}
216216

217-
func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) {
217+
func calculateNetwork(network map[string]container.NetworkStats) (float64, float64) {
218218
var rx, tx float64
219219

220220
for _, v := range network {
@@ -236,7 +236,7 @@ func calculateNetwork(network map[string]types.NetworkStats) (float64, float64)
236236
//
237237
// On Docker 19.03 and older, the result was `mem.Usage - mem.Stats["cache"]`.
238238
// See https://github.com/moby/moby/issues/40727 for the background.
239-
func calculateMemUsageUnixNoCache(mem types.MemoryStats) float64 {
239+
func calculateMemUsageUnixNoCache(mem container.MemoryStats) float64 {
240240
// cgroup v1
241241
if v, isCgroup1 := mem.Stats["total_inactive_file"]; isCgroup1 && v < mem.Usage {
242242
return float64(mem.Usage - v)

cli/command/container/stats_helpers_test.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/docker/docker/api/types"
7+
"github.com/docker/docker/api/types/container"
88
"gotest.tools/v3/assert"
99
)
1010

1111
func TestCalculateMemUsageUnixNoCache(t *testing.T) {
12-
// Given
13-
stats := types.MemoryStats{Usage: 500, Stats: map[string]uint64{"total_inactive_file": 400}}
14-
15-
// When
16-
result := calculateMemUsageUnixNoCache(stats)
17-
18-
// Then
12+
result := calculateMemUsageUnixNoCache(container.MemoryStats{Usage: 500, Stats: map[string]uint64{"total_inactive_file": 400}})
1913
assert.Assert(t, inDelta(100.0, result, 1e-6))
2014
}
2115

@@ -36,6 +30,28 @@ func TestCalculateMemPercentUnixNoCache(t *testing.T) {
3630
})
3731
}
3832

33+
func TestCalculateBlockIO(t *testing.T) {
34+
blkRead, blkWrite := calculateBlockIO(container.BlkioStats{
35+
IoServiceBytesRecursive: []container.BlkioStatEntry{
36+
{Major: 8, Minor: 0, Op: "read", Value: 1234},
37+
{Major: 8, Minor: 1, Op: "read", Value: 4567},
38+
{Major: 8, Minor: 0, Op: "Read", Value: 6},
39+
{Major: 8, Minor: 1, Op: "Read", Value: 8},
40+
{Major: 8, Minor: 0, Op: "write", Value: 123},
41+
{Major: 8, Minor: 1, Op: "write", Value: 456},
42+
{Major: 8, Minor: 0, Op: "Write", Value: 6},
43+
{Major: 8, Minor: 1, Op: "Write", Value: 8},
44+
{Major: 8, Minor: 1, Op: "", Value: 456},
45+
},
46+
})
47+
if blkRead != 5815 {
48+
t.Fatalf("blkRead = %d, want 5815", blkRead)
49+
}
50+
if blkWrite != 593 {
51+
t.Fatalf("blkWrite = %d, want 593", blkWrite)
52+
}
53+
}
54+
3955
func inDelta(x, y, delta float64) func() (bool, string) {
4056
return func() (bool, string) {
4157
diff := x - y

cli/command/container/stats_unit_test.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

cli/command/image/build.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/docker/docker/pkg/jsonmessage"
3030
"github.com/docker/docker/pkg/progress"
3131
"github.com/docker/docker/pkg/streamformatter"
32-
units "github.com/docker/go-units"
3332
"github.com/pkg/errors"
3433
"github.com/spf13/cobra"
3534
)
@@ -81,7 +80,7 @@ func (o buildOptions) contextFromStdin() bool {
8180
}
8281

8382
func newBuildOptions() buildOptions {
84-
ulimits := make(map[string]*units.Ulimit)
83+
ulimits := make(map[string]*container.Ulimit)
8584
return buildOptions{
8685
tags: opts.NewListOpts(validateTag),
8786
buildArgs: opts.NewListOpts(opts.ValidateEnv),

cli/command/service/update.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/docker/docker/api/types/swarm"
1818
"github.com/docker/docker/api/types/versions"
1919
"github.com/docker/docker/client"
20-
units "github.com/docker/go-units"
2120
"github.com/moby/swarmkit/v2/api/defaults"
2221
"github.com/pkg/errors"
2322
"github.com/spf13/cobra"
@@ -710,8 +709,8 @@ func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) {
710709
}
711710
}
712711

713-
func updateUlimits(flags *pflag.FlagSet, ulimits []*units.Ulimit) []*units.Ulimit {
714-
newUlimits := make(map[string]*units.Ulimit)
712+
func updateUlimits(flags *pflag.FlagSet, ulimits []*container.Ulimit) []*container.Ulimit {
713+
newUlimits := make(map[string]*container.Ulimit)
715714

716715
for _, ulimit := range ulimits {
717716
newUlimits[ulimit.Name] = ulimit
@@ -731,7 +730,7 @@ func updateUlimits(flags *pflag.FlagSet, ulimits []*units.Ulimit) []*units.Ulimi
731730
if len(newUlimits) == 0 {
732731
return nil
733732
}
734-
limits := make([]*units.Ulimit, 0, len(newUlimits))
733+
limits := make([]*container.Ulimit, 0, len(newUlimits))
735734
for _, ulimit := range newUlimits {
736735
limits = append(limits, ulimit)
737736
}

cli/command/service/update_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
mounttypes "github.com/docker/docker/api/types/mount"
1414
"github.com/docker/docker/api/types/network"
1515
"github.com/docker/docker/api/types/swarm"
16-
"github.com/docker/go-units"
1716
"gotest.tools/v3/assert"
1817
is "gotest.tools/v3/assert/cmp"
1918
)
@@ -1600,66 +1599,66 @@ func TestUpdateUlimits(t *testing.T) {
16001599

16011600
tests := []struct {
16021601
name string
1603-
spec []*units.Ulimit
1602+
spec []*container.Ulimit
16041603
rm []string
16051604
add []string
1606-
expected []*units.Ulimit
1605+
expected []*container.Ulimit
16071606
}{
16081607
{
16091608
name: "from scratch",
16101609
add: []string{"nofile=512:1024", "core=1024:1024"},
1611-
expected: []*units.Ulimit{
1610+
expected: []*container.Ulimit{
16121611
{Name: "core", Hard: 1024, Soft: 1024},
16131612
{Name: "nofile", Hard: 1024, Soft: 512},
16141613
},
16151614
},
16161615
{
16171616
name: "append new",
1618-
spec: []*units.Ulimit{
1617+
spec: []*container.Ulimit{
16191618
{Name: "nofile", Hard: 1024, Soft: 512},
16201619
},
16211620
add: []string{"core=1024:1024"},
1622-
expected: []*units.Ulimit{
1621+
expected: []*container.Ulimit{
16231622
{Name: "core", Hard: 1024, Soft: 1024},
16241623
{Name: "nofile", Hard: 1024, Soft: 512},
16251624
},
16261625
},
16271626
{
16281627
name: "remove and append new should append",
1629-
spec: []*units.Ulimit{
1628+
spec: []*container.Ulimit{
16301629
{Name: "core", Hard: 1024, Soft: 1024},
16311630
{Name: "nofile", Hard: 1024, Soft: 512},
16321631
},
16331632
rm: []string{"nofile=512:1024"},
16341633
add: []string{"nofile=512:1024"},
1635-
expected: []*units.Ulimit{
1634+
expected: []*container.Ulimit{
16361635
{Name: "core", Hard: 1024, Soft: 1024},
16371636
{Name: "nofile", Hard: 1024, Soft: 512},
16381637
},
16391638
},
16401639
{
16411640
name: "update existing",
1642-
spec: []*units.Ulimit{
1641+
spec: []*container.Ulimit{
16431642
{Name: "nofile", Hard: 2048, Soft: 1024},
16441643
},
16451644
add: []string{"nofile=512:1024"},
1646-
expected: []*units.Ulimit{
1645+
expected: []*container.Ulimit{
16471646
{Name: "nofile", Hard: 1024, Soft: 512},
16481647
},
16491648
},
16501649
{
16511650
name: "update existing twice",
1652-
spec: []*units.Ulimit{
1651+
spec: []*container.Ulimit{
16531652
{Name: "nofile", Hard: 2048, Soft: 1024},
16541653
},
16551654
add: []string{"nofile=256:512", "nofile=512:1024"},
1656-
expected: []*units.Ulimit{
1655+
expected: []*container.Ulimit{
16571656
{Name: "nofile", Hard: 1024, Soft: 512},
16581657
},
16591658
},
16601659
{
16611660
name: "remove all",
1662-
spec: []*units.Ulimit{
1661+
spec: []*container.Ulimit{
16631662
{Name: "core", Hard: 1024, Soft: 1024},
16641663
{Name: "nofile", Hard: 1024, Soft: 512},
16651664
},
@@ -1668,23 +1667,23 @@ func TestUpdateUlimits(t *testing.T) {
16681667
},
16691668
{
16701669
name: "remove by key",
1671-
spec: []*units.Ulimit{
1670+
spec: []*container.Ulimit{
16721671
{Name: "core", Hard: 1024, Soft: 1024},
16731672
{Name: "nofile", Hard: 1024, Soft: 512},
16741673
},
16751674
rm: []string{"core"},
1676-
expected: []*units.Ulimit{
1675+
expected: []*container.Ulimit{
16771676
{Name: "nofile", Hard: 1024, Soft: 512},
16781677
},
16791678
},
16801679
{
16811680
name: "remove by key and different value",
1682-
spec: []*units.Ulimit{
1681+
spec: []*container.Ulimit{
16831682
{Name: "core", Hard: 1024, Soft: 1024},
16841683
{Name: "nofile", Hard: 1024, Soft: 512},
16851684
},
16861685
rm: []string{"core=1234:5678"},
1687-
expected: []*units.Ulimit{
1686+
expected: []*container.Ulimit{
16881687
{Name: "nofile", Hard: 1024, Soft: 512},
16891688
},
16901689
},

cli/compose/convert/service.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/docker/docker/api/types/swarm"
1515
"github.com/docker/docker/api/types/versions"
1616
"github.com/docker/docker/client"
17-
"github.com/docker/go-units"
1817
"github.com/pkg/errors"
1918
)
2019

@@ -693,24 +692,24 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
693692
return &swarmCredSpec, nil
694693
}
695694

696-
func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units.Ulimit {
697-
newUlimits := make(map[string]*units.Ulimit)
695+
func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*container.Ulimit {
696+
newUlimits := make(map[string]*container.Ulimit)
698697
for name, u := range origUlimits {
699698
if u.Single != 0 {
700-
newUlimits[name] = &units.Ulimit{
699+
newUlimits[name] = &container.Ulimit{
701700
Name: name,
702701
Soft: int64(u.Single),
703702
Hard: int64(u.Single),
704703
}
705704
} else {
706-
newUlimits[name] = &units.Ulimit{
705+
newUlimits[name] = &container.Ulimit{
707706
Name: name,
708707
Soft: int64(u.Soft),
709708
Hard: int64(u.Hard),
710709
}
711710
}
712711
}
713-
ulimits := make([]*units.Ulimit, 0, len(newUlimits))
712+
ulimits := make([]*container.Ulimit, 0, len(newUlimits))
714713
for _, ulimit := range newUlimits {
715714
ulimits = append(ulimits, ulimit)
716715
}

opts/ulimit.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@ import (
44
"fmt"
55
"sort"
66

7+
"github.com/docker/docker/api/types/container"
78
"github.com/docker/go-units"
89
)
910

1011
// UlimitOpt defines a map of Ulimits
1112
type UlimitOpt struct {
12-
values *map[string]*units.Ulimit
13+
values *map[string]*container.Ulimit
1314
}
1415

1516
// NewUlimitOpt creates a new UlimitOpt. Ulimits are not validated.
16-
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
17+
func NewUlimitOpt(ref *map[string]*container.Ulimit) *UlimitOpt {
18+
// TODO(thaJeztah): why do we need a map with pointers here?
1719
if ref == nil {
18-
ref = &map[string]*units.Ulimit{}
20+
ref = &map[string]*container.Ulimit{}
1921
}
2022
return &UlimitOpt{ref}
2123
}
2224

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

4548
// GetList returns a slice of pointers to Ulimits. Values are sorted by name.
46-
func (o *UlimitOpt) GetList() []*units.Ulimit {
47-
ulimits := make([]*units.Ulimit, 0, len(*o.values))
49+
func (o *UlimitOpt) GetList() []*container.Ulimit {
50+
ulimits := make([]*container.Ulimit, 0, len(*o.values))
4851
for _, v := range *o.values {
4952
ulimits = append(ulimits, v)
5053
}

0 commit comments

Comments
 (0)