From 639a1a0293dda6aa8fbd039fe9cb35aecf70cecf Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 12 Sep 2023 14:59:27 +0200 Subject: [PATCH] bump c/common to latest main Includes the fixes for the search filter changes. [NO NEW TESTS NEEDED] Signed-off-by: Paul Holzinger --- go.mod | 2 +- go.sum | 6 +- pkg/domain/infra/abi/images.go | 3 +- pkg/domain/infra/tunnel/images.go | 4 +- .../common/libimage/filter/filter.go | 55 ++++++++++++++++++ .../containers/common/libimage/search.go | 58 ++----------------- .../containers/common/pkg/cgroups/cgroups.go | 4 +- .../common/pkg/cgroups/cgroups_linux.go | 4 +- .../common/pkg/cgroups/memory_linux.go | 21 ++++++- .../containers/common/pkg/cgroups/utils.go | 2 +- vendor/modules.txt | 3 +- 11 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 vendor/github.com/containers/common/libimage/filter/filter.go diff --git a/go.mod b/go.mod index c40994da2a..3eb9120250 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/containernetworking/cni v1.1.2 github.com/containernetworking/plugins v1.3.0 github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6 - github.com/containers/common v0.55.1-0.20230909082937-1e47d4e270e1 + github.com/containers/common v0.55.1-0.20230912125309-7fa3c55bd517 github.com/containers/conmon v2.0.20+incompatible github.com/containers/image/v5 v5.27.1-0.20230911141411-81c35e010bab github.com/containers/libhvee v0.4.1-0.20230905135638-56fb23533417 diff --git a/go.sum b/go.sum index f6289561bd..e8cccc3fa4 100644 --- a/go.sum +++ b/go.sum @@ -246,8 +246,8 @@ github.com/containernetworking/plugins v1.3.0 h1:QVNXMT6XloyMUoO2wUOqWTC1hWFV62Q github.com/containernetworking/plugins v1.3.0/go.mod h1:Pc2wcedTQQCVuROOOaLBPPxrEXqqXBFt3cZ+/yVg6l0= github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6 h1:K/S8SFQsnnNTF0Ws58SrBD9L0EuClzAG8Zp08d7+6AA= github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6/go.mod h1:0sptTFBBtSznLqoTh80DfvMOCNbdRsNRgVOKhBhrupA= -github.com/containers/common v0.55.1-0.20230909082937-1e47d4e270e1 h1:TwJj9XnzJ9fKSWP8OuWGOKc+35AO5tKIP77+GAVJZGs= -github.com/containers/common v0.55.1-0.20230909082937-1e47d4e270e1/go.mod h1:xqpiSX5MKEG0ACDNMeCwLz+VZpD6mhg5ThJxBIJQ9Go= +github.com/containers/common v0.55.1-0.20230912125309-7fa3c55bd517 h1:VbCiDKqzPx8N1gyB1vtXKbI0HpX7QaFK9/9d0n4HgU4= +github.com/containers/common v0.55.1-0.20230912125309-7fa3c55bd517/go.mod h1:udRQMEx9cbPslGo/yCKmnBr7NJ6aVrqGOLKLs/c1Lqc= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/image/v5 v5.27.1-0.20230911141411-81c35e010bab h1:bAK5q9Coo11AMbtK/rojwOssSa+kXqAVhPYlHNmBZPE= @@ -897,8 +897,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rootless-containers/rootlesskit v1.1.1 h1:F5psKWoWY9/VjZ3ifVcaosjvFZJOagX85U22M0/EQZE= github.com/rootless-containers/rootlesskit v1.1.1/go.mod h1:UD5GoA3dqKCJrnvnhVgQQnweMF2qZnf9KLw8EewcMZI= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go index a5b163788c..235f4db2a7 100644 --- a/pkg/domain/infra/abi/images.go +++ b/pkg/domain/infra/abi/images.go @@ -16,6 +16,7 @@ import ( "syscall" "github.com/containers/common/libimage" + "github.com/containers/common/libimage/filter" "github.com/containers/common/pkg/config" "github.com/containers/common/pkg/ssh" "github.com/containers/image/v5/docker" @@ -462,7 +463,7 @@ func (ir *ImageEngine) Import(ctx context.Context, options entities.ImageImportO // Search for images using term and filters func (ir *ImageEngine) Search(ctx context.Context, term string, opts entities.ImageSearchOptions) ([]entities.ImageSearchReport, error) { - filter, err := libimage.ParseSearchFilter(opts.Filters) + filter, err := filter.ParseSearchFilter(opts.Filters) if err != nil { return nil, err } diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 55a01a07c0..abf3f59bcb 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/containers/common/libimage" + "github.com/containers/common/libimage/filter" "github.com/containers/common/pkg/config" "github.com/containers/common/pkg/ssh" "github.com/containers/image/v5/docker/reference" @@ -339,7 +339,7 @@ func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string, func (ir *ImageEngine) Search(ctx context.Context, term string, opts entities.ImageSearchOptions) ([]entities.ImageSearchReport, error) { mappedFilters := make(map[string][]string) - filters, err := libimage.ParseSearchFilter(opts.Filters) + filters, err := filter.ParseSearchFilter(opts.Filters) if err != nil { return nil, err } diff --git a/vendor/github.com/containers/common/libimage/filter/filter.go b/vendor/github.com/containers/common/libimage/filter/filter.go new file mode 100644 index 0000000000..098d2998dd --- /dev/null +++ b/vendor/github.com/containers/common/libimage/filter/filter.go @@ -0,0 +1,55 @@ +package filter + +import ( + "fmt" + "strconv" + "strings" + + "github.com/containers/common/libimage/define" + "github.com/containers/image/v5/types" +) + +// SearchFilter allows filtering images while searching. +type SearchFilter struct { + // Stars describes the minimal amount of starts of an image. + Stars int + // IsAutomated decides if only images from automated builds are displayed. + IsAutomated types.OptionalBool + // IsOfficial decides if only official images are displayed. + IsOfficial types.OptionalBool +} + +// ParseSearchFilter turns the filter into a SearchFilter that can be used for +// searching images. +func ParseSearchFilter(filter []string) (*SearchFilter, error) { + sFilter := new(SearchFilter) + for _, f := range filter { + arr := strings.SplitN(f, "=", 2) + switch arr[0] { + case define.SearchFilterStars: + if len(arr) < 2 { + return nil, fmt.Errorf("invalid filter %q, should be stars=", filter) + } + stars, err := strconv.Atoi(arr[1]) + if err != nil { + return nil, fmt.Errorf("incorrect value type for stars filter: %w", err) + } + sFilter.Stars = stars + case define.SearchFilterAutomated: + if len(arr) == 2 && arr[1] == "false" { + sFilter.IsAutomated = types.OptionalBoolFalse + } else { + sFilter.IsAutomated = types.OptionalBoolTrue + } + case define.SearchFilterOfficial: + if len(arr) == 2 && arr[1] == "false" { + sFilter.IsOfficial = types.OptionalBoolFalse + } else { + sFilter.IsOfficial = types.OptionalBoolTrue + } + default: + return nil, fmt.Errorf("invalid filter type %q", f) + } + } + return sFilter, nil +} diff --git a/vendor/github.com/containers/common/libimage/search.go b/vendor/github.com/containers/common/libimage/search.go index 132307d13b..618850e6e1 100644 --- a/vendor/github.com/containers/common/libimage/search.go +++ b/vendor/github.com/containers/common/libimage/search.go @@ -3,11 +3,10 @@ package libimage import ( "context" "fmt" - "strconv" "strings" "sync" - "github.com/containers/common/libimage/define" + "github.com/containers/common/libimage/filter" registryTransport "github.com/containers/image/v5/docker" "github.com/containers/image/v5/pkg/sysregistriesv2" "github.com/containers/image/v5/transports/alltransports" @@ -46,7 +45,7 @@ type SearchResult struct { // SearchOptions customize searching images. type SearchOptions struct { // Filter allows to filter the results. - Filter SearchFilter + Filter filter.SearchFilter // Limit limits the number of queries per index (default: 25). Must be // greater than 0 to overwrite the default value. Limit int @@ -77,51 +76,6 @@ type SearchOptions struct { Registries []string } -// SearchFilter allows filtering images while searching. -type SearchFilter struct { - // Stars describes the minimal amount of starts of an image. - Stars int - // IsAutomated decides if only images from automated builds are displayed. - IsAutomated types.OptionalBool - // IsOfficial decides if only official images are displayed. - IsOfficial types.OptionalBool -} - -// ParseSearchFilter turns the filter into a SearchFilter that can be used for -// searching images. -func ParseSearchFilter(filter []string) (*SearchFilter, error) { - sFilter := new(SearchFilter) - for _, f := range filter { - arr := strings.SplitN(f, "=", 2) - switch arr[0] { - case define.SearchFilterStars: - if len(arr) < 2 { - return nil, fmt.Errorf("invalid filter %q, should be stars=", filter) - } - stars, err := strconv.Atoi(arr[1]) - if err != nil { - return nil, fmt.Errorf("incorrect value type for stars filter: %w", err) - } - sFilter.Stars = stars - case define.SearchFilterAutomated: - if len(arr) == 2 && arr[1] == "false" { - sFilter.IsAutomated = types.OptionalBoolFalse - } else { - sFilter.IsAutomated = types.OptionalBoolTrue - } - case define.SearchFilterOfficial: - if len(arr) == 2 && arr[1] == "false" { - sFilter.IsOfficial = types.OptionalBoolFalse - } else { - sFilter.IsOfficial = types.OptionalBoolTrue - } - default: - return nil, fmt.Errorf("invalid filter type %q", f) - } - } - return sFilter, nil -} - // Search searches term. If term includes a registry, only this registry will // be used for searching. Otherwise, the unqualified-search registries in // containers-registries.conf(5) or the ones specified in the options will be @@ -261,7 +215,7 @@ func (r *Runtime) searchImageInRegistry(ctx context.Context, term, registry stri paramsArr := []SearchResult{} for i := 0; i < limit; i++ { // Check whether query matches filters - if !(options.Filter.matchesAutomatedFilter(results[i]) && options.Filter.matchesOfficialFilter(results[i]) && options.Filter.matchesStarFilter(results[i])) { + if !(filterMatchesAutomatedFilter(&options.Filter, results[i]) && filterMatchesOfficialFilter(&options.Filter, results[i]) && filterMatchesStarFilter(&options.Filter, results[i])) { continue } official := "" @@ -330,18 +284,18 @@ func searchRepositoryTags(ctx context.Context, sys *types.SystemContext, registr return paramsArr, nil } -func (f *SearchFilter) matchesStarFilter(result registryTransport.SearchResult) bool { +func filterMatchesStarFilter(f *filter.SearchFilter, result registryTransport.SearchResult) bool { return result.StarCount >= f.Stars } -func (f *SearchFilter) matchesAutomatedFilter(result registryTransport.SearchResult) bool { +func filterMatchesAutomatedFilter(f *filter.SearchFilter, result registryTransport.SearchResult) bool { if f.IsAutomated != types.OptionalBoolUndefined { return result.IsAutomated == (f.IsAutomated == types.OptionalBoolTrue) } return true } -func (f *SearchFilter) matchesOfficialFilter(result registryTransport.SearchResult) bool { +func filterMatchesOfficialFilter(f *filter.SearchFilter, result registryTransport.SearchResult) bool { if f.IsOfficial != types.OptionalBoolUndefined { return result.IsOfficial == (f.IsOfficial == types.OptionalBoolTrue) } diff --git a/vendor/github.com/containers/common/pkg/cgroups/cgroups.go b/vendor/github.com/containers/common/pkg/cgroups/cgroups.go index 73dc36ee40..10b70b8f92 100644 --- a/vendor/github.com/containers/common/pkg/cgroups/cgroups.go +++ b/vendor/github.com/containers/common/pkg/cgroups/cgroups.go @@ -582,7 +582,7 @@ func (c *CgroupControl) Stat() (*Metrics, error) { return &m, nil } -func readCgroup2MapPath(path string) (map[string][]string, error) { +func readCgroupMapPath(path string) (map[string][]string, error) { ret := map[string][]string{} f, err := os.Open(path) if err != nil { @@ -610,5 +610,5 @@ func readCgroup2MapPath(path string) (map[string][]string, error) { func readCgroup2MapFile(ctr *CgroupControl, name string) (map[string][]string, error) { p := filepath.Join(cgroupRoot, ctr.path, name) - return readCgroup2MapPath(p) + return readCgroupMapPath(p) } diff --git a/vendor/github.com/containers/common/pkg/cgroups/cgroups_linux.go b/vendor/github.com/containers/common/pkg/cgroups/cgroups_linux.go index 4269c7fbda..e778b0e896 100644 --- a/vendor/github.com/containers/common/pkg/cgroups/cgroups_linux.go +++ b/vendor/github.com/containers/common/pkg/cgroups/cgroups_linux.go @@ -542,7 +542,7 @@ func (c *CgroupControl) Stat() (*cgroups.Stats, error) { return &m, nil } -func readCgroup2MapPath(path string) (map[string][]string, error) { +func readCgroupMapPath(path string) (map[string][]string, error) { ret := map[string][]string{} f, err := os.Open(path) if err != nil { @@ -570,5 +570,5 @@ func readCgroup2MapPath(path string) (map[string][]string, error) { func readCgroup2MapFile(ctr *CgroupControl, name string) (map[string][]string, error) { p := filepath.Join(cgroupRoot, ctr.config.Path, name) - return readCgroup2MapPath(p) + return readCgroupMapPath(p) } diff --git a/vendor/github.com/containers/common/pkg/cgroups/memory_linux.go b/vendor/github.com/containers/common/pkg/cgroups/memory_linux.go index 5d2bf5d0e1..3335cdffe5 100644 --- a/vendor/github.com/containers/common/pkg/cgroups/memory_linux.go +++ b/vendor/github.com/containers/common/pkg/cgroups/memory_linux.go @@ -4,7 +4,9 @@ package cgroups import ( + "fmt" "path/filepath" + "strconv" "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups/fs" @@ -63,9 +65,26 @@ func (c *linuxMemHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error { } else { memoryRoot = ctr.getCgroupv1Path(Memory) limitFilename = "memory.limit_in_bytes" - if memUsage.Usage.Usage, err = readFileAsUint64(filepath.Join(memoryRoot, "memory.usage_in_bytes")); err != nil { + + path := filepath.Join(memoryRoot, "memory.stat") + values, err := readCgroupMapPath(path) + if err != nil { return err } + + // cgroup v1 does not have a single "anon" field, but we can calculate it + // from total_active_anon and total_inactive_anon + memUsage.Usage.Usage = 0 + for _, key := range []string{"total_active_anon", "total_inactive_anon"} { + if _, found := values[key]; !found { + continue + } + res, err := strconv.ParseUint(values[key][0], 10, 64) + if err != nil { + return fmt.Errorf("parse %s from %s: %w", key, path, err) + } + memUsage.Usage.Usage += res + } } memUsage.Usage.Limit, err = readFileAsUint64(filepath.Join(memoryRoot, limitFilename)) diff --git a/vendor/github.com/containers/common/pkg/cgroups/utils.go b/vendor/github.com/containers/common/pkg/cgroups/utils.go index 8ade67878d..a77ba4a272 100644 --- a/vendor/github.com/containers/common/pkg/cgroups/utils.go +++ b/vendor/github.com/containers/common/pkg/cgroups/utils.go @@ -64,7 +64,7 @@ func GetSystemCPUUsage() (uint64, error) { } p := filepath.Join(cgroupRoot, file.Name(), "cpu.stat") - values, err := readCgroup2MapPath(p) + values, err := readCgroupMapPath(p) if err != nil { return 0, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index a056c7e76b..3d384185e7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -157,10 +157,11 @@ github.com/containers/buildah/pkg/rusage github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/util -# github.com/containers/common v0.55.1-0.20230909082937-1e47d4e270e1 +# github.com/containers/common v0.55.1-0.20230912125309-7fa3c55bd517 ## explicit; go 1.18 github.com/containers/common/libimage github.com/containers/common/libimage/define +github.com/containers/common/libimage/filter github.com/containers/common/libimage/manifests github.com/containers/common/libnetwork/cni github.com/containers/common/libnetwork/etchosts