Skip to content

Commit 02ed4da

Browse files
committed
Merge branch 'master' into dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible
2 parents 960ba8d + 747d70e commit 02ed4da

File tree

11 files changed

+92
-50
lines changed

11 files changed

+92
-50
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
GO := go
16-
GOLANGCI_VER := v1.51.2
16+
GOLANGCI_VER := v1.54.1
1717
GO_TEST ?= $(GO) test $(or $(GO_FLAGS),-race)
1818
arch ?= $(shell go env GOARCH)
1919

cmd/cadvisor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ func init() {
100100
optstr := container.AllMetrics.String()
101101
flag.Var(&ignoreMetrics, "disable_metrics", fmt.Sprintf("comma-separated list of `metrics` to be disabled. Options are %s.", optstr))
102102
flag.Var(&enableMetrics, "enable_metrics", fmt.Sprintf("comma-separated list of `metrics` to be enabled. If set, overrides 'disable_metrics'. Options are %s.", optstr))
103-
104-
// Default logging verbosity to V(2)
105-
_ = flag.Set("v", "2")
106103
}
107104

108105
func main() {
109106
klog.InitFlags(nil)
110107
defer klog.Flush()
108+
// Default logging verbosity to V(2)
109+
_ = flag.Set("v", "2")
111110
flag.Parse()
112111

113112
if *versionFlag {

cmd/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ require (
4747
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
4848
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
4949
github.com/davecgh/go-spew v1.1.1 // indirect
50-
github.com/docker/distribution v2.8.1+incompatible // indirect
50+
github.com/docker/distribution v2.8.2+incompatible // indirect
5151
github.com/docker/docker v20.10.21+incompatible // indirect
5252
github.com/docker/go-connections v0.4.0 // indirect
5353
github.com/docker/go-units v0.5.0 // indirect
@@ -83,7 +83,7 @@ require (
8383
github.com/mrunalp/fileutils v0.5.0 // indirect
8484
github.com/opencontainers/go-digest v1.0.0 // indirect
8585
github.com/opencontainers/image-spec v1.0.2 // indirect
86-
github.com/opencontainers/runc v1.1.7 // indirect
86+
github.com/opencontainers/runc v1.1.9 // indirect
8787
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 // indirect
8888
github.com/opencontainers/selinux v1.10.0 // indirect
8989
github.com/pierrec/lz4/v4 v4.1.17 // indirect

cmd/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
9696
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9797
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9898
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99-
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
100-
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
99+
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
100+
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
101101
github.com/docker/docker v20.10.21+incompatible h1:UTLdBmHk3bEY+w8qeO5KttOhy6OmXWsl/FEet9Uswog=
102102
github.com/docker/docker v20.10.21+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
103103
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
@@ -309,8 +309,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
309309
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
310310
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
311311
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
312-
github.com/opencontainers/runc v1.1.7 h1:y2EZDS8sNng4Ksf0GUYNhKbTShZJPJg1FiXJNH/uoCk=
313-
github.com/opencontainers/runc v1.1.7/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50=
312+
github.com/opencontainers/runc v1.1.9 h1:XR0VIHTGce5eWPkaPesqTBrhW2yAcaraWfsEalNwQLM=
313+
github.com/opencontainers/runc v1.1.9/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50=
314314
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 h1:R5M2qXZiK/mWPMT4VldCOiSL9HIAMuxQZWdG0CSM5+4=
315315
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
316316
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=

container/libcontainer/handler.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
)
4040

4141
var (
42-
whitelistedUlimits = [...]string{"max_open_files"}
4342
referencedResetInterval = flag.Uint64("referenced_reset_interval", 0,
4443
"Reset interval for referenced bytes (container_referenced_bytes metric), number of measurement cycles after which referenced bytes are cleared, if set to 0 referenced bytes are never cleared (default: 0)")
4544

@@ -205,51 +204,53 @@ func parseUlimit(value string) (int64, error) {
205204
return num, nil
206205
}
207206

208-
func isUlimitWhitelisted(name string) bool {
209-
for _, whitelist := range whitelistedUlimits {
210-
if name == whitelist {
211-
return true
212-
}
213-
}
214-
return false
215-
}
216-
217207
func processLimitsFile(fileData string) []info.UlimitSpec {
208+
const maxOpenFilesLinePrefix = "Max open files"
209+
218210
limits := strings.Split(fileData, "\n")
219211
ulimits := make([]info.UlimitSpec, 0, len(limits))
220212
for _, lim := range limits {
221213
// Skip any headers/footers
222-
if strings.HasPrefix(lim, "Max") {
223-
224-
// Line format: Max open files 16384 16384 files
225-
fields := regexp.MustCompile(`[\s]{2,}`).Split(lim, -1)
226-
name := strings.Replace(strings.ToLower(strings.TrimSpace(fields[0])), " ", "_", -1)
227-
228-
found := isUlimitWhitelisted(name)
229-
if !found {
230-
continue
231-
}
232-
233-
soft := strings.TrimSpace(fields[1])
234-
softNum, softErr := parseUlimit(soft)
235-
236-
hard := strings.TrimSpace(fields[2])
237-
hardNum, hardErr := parseUlimit(hard)
238-
239-
// Omit metric if there were any parsing errors
240-
if softErr == nil && hardErr == nil {
241-
ulimitSpec := info.UlimitSpec{
242-
Name: name,
243-
SoftLimit: int64(softNum),
244-
HardLimit: int64(hardNum),
245-
}
246-
ulimits = append(ulimits, ulimitSpec)
214+
if strings.HasPrefix(lim, "Max open files") {
215+
// Remove line prefix
216+
ulimit, err := processMaxOpenFileLimitLine(
217+
"max_open_files",
218+
lim[len(maxOpenFilesLinePrefix):],
219+
)
220+
if err == nil {
221+
ulimits = append(ulimits, ulimit)
247222
}
248223
}
249224
}
250225
return ulimits
251226
}
252227

228+
// Any caller of processMaxOpenFileLimitLine must ensure that the name prefix is already removed from the limit line.
229+
// with the "Max open files" prefix.
230+
func processMaxOpenFileLimitLine(name, line string) (info.UlimitSpec, error) {
231+
// Remove any leading whitespace
232+
line = strings.TrimSpace(line)
233+
// Split on whitespace
234+
fields := strings.Fields(line)
235+
if len(fields) != 3 {
236+
return info.UlimitSpec{}, fmt.Errorf("unable to parse max open files line: %s", line)
237+
}
238+
// The first field is the soft limit, the second is the hard limit
239+
soft, err := parseUlimit(fields[0])
240+
if err != nil {
241+
return info.UlimitSpec{}, err
242+
}
243+
hard, err := parseUlimit(fields[1])
244+
if err != nil {
245+
return info.UlimitSpec{}, err
246+
}
247+
return info.UlimitSpec{
248+
Name: name,
249+
SoftLimit: soft,
250+
HardLimit: hard,
251+
}, nil
252+
}
253+
253254
func processRootProcUlimits(rootFs string, rootPid int) []info.UlimitSpec {
254255
filePath := path.Join(rootFs, "/proc", strconv.Itoa(rootPid), "limits")
255256
out, err := os.ReadFile(filePath)

container/libcontainer/handler_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,28 @@ func TestClearReferencedBytesWhenClearRefsMissing(t *testing.T) {
296296
err := clearReferencedBytes(pids, 0, 1)
297297
assert.Nil(t, err)
298298
}
299+
300+
var ulimits []info.UlimitSpec
301+
302+
func BenchmarkProcessLimitsFile(b *testing.B) {
303+
content, err := os.ReadFile("testdata/limits")
304+
assert.Nil(b, err)
305+
306+
b.ResetTimer()
307+
for i := 0; i < b.N; i++ {
308+
ulimits = processLimitsFile(string(content))
309+
}
310+
311+
// Ensure the compiler doesn't optimize away the benchmark
312+
_ = ulimits
313+
}
314+
315+
func TestProcessMaxOpenFileLimitLine(t *testing.T) {
316+
line := " 1073741816 1073741816 files "
317+
318+
ulimit, err := processMaxOpenFileLimitLine("max_open_files", line)
319+
assert.Nil(t, err)
320+
assert.Equal(t, "max_open_files", ulimit.Name)
321+
assert.Equal(t, int64(1073741816), ulimit.SoftLimit)
322+
assert.Equal(t, int64(1073741816), ulimit.HardLimit)
323+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Limit Soft Limit Hard Limit Units
2+
Max cpu time unlimited unlimited seconds
3+
Max file size unlimited unlimited bytes
4+
Max data size unlimited unlimited bytes
5+
Max stack size 8388608 unlimited bytes
6+
Max core file size unlimited unlimited bytes
7+
Max resident set unlimited unlimited bytes
8+
Max processes 119958 119958 processes
9+
Max open files 1073741816 1073741816 files
10+
Max locked memory 3932852224 3932852224 bytes
11+
Max address space unlimited unlimited bytes
12+
Max file locks unlimited unlimited locks
13+
Max pending signals 119958 119958 signals
14+
Max msgqueue size 819200 819200 bytes
15+
Max nice priority 0 0
16+
Max realtime priority 0 0
17+
Max realtime timeout unlimited unlimited us

fs/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ func GetDirUsage(dir string) (UsageInfo, error) {
636636

637637
rootStat, ok := rootInfo.Sys().(*syscall.Stat_t)
638638
if !ok {
639-
return usage, fmt.Errorf("unsuported fileinfo for getting inode usage of %q", dir)
639+
return usage, fmt.Errorf("unsupported fileinfo for getting inode usage of %q", dir)
640640
}
641641

642642
rootDevID := rootStat.Dev

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible
2222
github.com/moby/sys/mountinfo v0.6.2
2323
github.com/opencontainers/go-digest v1.0.0
24-
github.com/opencontainers/runc v1.1.7
24+
github.com/opencontainers/runc v1.1.9
2525
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78
2626
github.com/pkg/errors v0.9.1
2727
github.com/prometheus/client_golang v1.14.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
227227
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
228228
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
229229
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
230-
github.com/opencontainers/runc v1.1.7 h1:y2EZDS8sNng4Ksf0GUYNhKbTShZJPJg1FiXJNH/uoCk=
231-
github.com/opencontainers/runc v1.1.7/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50=
230+
github.com/opencontainers/runc v1.1.9 h1:XR0VIHTGce5eWPkaPesqTBrhW2yAcaraWfsEalNwQLM=
231+
github.com/opencontainers/runc v1.1.9/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50=
232232
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78 h1:R5M2qXZiK/mWPMT4VldCOiSL9HIAMuxQZWdG0CSM5+4=
233233
github.com/opencontainers/runtime-spec v1.0.3-0.20220909204839-494a5a6aca78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
234234
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=

0 commit comments

Comments
 (0)