From 07d58782b8238c4a3b6c7f9b661f2d3006a6a291 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 21 Nov 2024 10:31:25 -0800 Subject: [PATCH] vendor: update compose to v2.4.4 Signed-off-by: Tonis Tiigi --- go.mod | 2 +- go.sum | 4 +- .../compose-spec/compose-go/v2/cli/options.go | 2 +- .../compose-go/v2/loader/loader.go | 7 ++ .../compose-go/v2/loader/reset.go | 68 ++++++++++++++----- .../compose-go/v2/types/config.go | 4 ++ vendor/modules.txt | 2 +- 7 files changed, 67 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index fdddf176..90d096fd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/Microsoft/go-winio v0.6.2 github.com/aws/aws-sdk-go-v2/config v1.26.6 - github.com/compose-spec/compose-go/v2 v2.4.2 + github.com/compose-spec/compose-go/v2 v2.4.4 github.com/containerd/console v1.0.4 github.com/containerd/containerd v1.7.22 github.com/containerd/continuity v0.4.4 diff --git a/go.sum b/go.sum index adee6d93..80a60d45 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,8 @@ github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnTh github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4= -github.com/compose-spec/compose-go/v2 v2.4.2 h1:RaZv+ZKZVNmxi4Cww1EKiJRLSZLiqVxIqhLUdH92dz4= -github.com/compose-spec/compose-go/v2 v2.4.2/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc= +github.com/compose-spec/compose-go/v2 v2.4.4 h1:cvHBl5Jf1iNBmRrZCICmHvaoskYc1etTPEMLKVwokAY= +github.com/compose-spec/compose-go/v2 v2.4.4/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups/v3 v3.0.2 h1:f5WFqIVSgo5IZmtTT3qVBo6TzI1ON6sycSBKkymb9L0= github.com/containerd/cgroups/v3 v3.0.2/go.mod h1:JUgITrzdFqp42uI2ryGA+ge0ap/nxzYgkGmIcetmErE= diff --git a/vendor/github.com/compose-spec/compose-go/v2/cli/options.go b/vendor/github.com/compose-spec/compose-go/v2/cli/options.go index b2ab60e8..caa07666 100644 --- a/vendor/github.com/compose-spec/compose-go/v2/cli/options.go +++ b/vendor/github.com/compose-spec/compose-go/v2/cli/options.go @@ -414,7 +414,7 @@ func (o *ProjectOptions) ReadConfigFiles(ctx context.Context, workingDir string, for i, c := range config.ConfigFiles { var err error var b []byte - if c.Filename == "-" { + if c.IsStdin() { b, err = io.ReadAll(os.Stdin) if err != nil { return nil, err diff --git a/vendor/github.com/compose-spec/compose-go/v2/loader/loader.go b/vendor/github.com/compose-spec/compose-go/v2/loader/loader.go index 62030f23..8fb95088 100644 --- a/vendor/github.com/compose-spec/compose-go/v2/loader/loader.go +++ b/vendor/github.com/compose-spec/compose-go/v2/loader/loader.go @@ -318,6 +318,13 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir strin opts.ResourceLoaders = append(opts.ResourceLoaders, localResourceLoader{}) for i, p := range configFiles { + if p == "-" { + config.ConfigFiles[i] = types.ConfigFile{ + Filename: p, + } + continue + } + for _, loader := range opts.ResourceLoaders { _, isLocalResourceLoader := loader.(localResourceLoader) if !loader.Accept(p) { diff --git a/vendor/github.com/compose-spec/compose-go/v2/loader/reset.go b/vendor/github.com/compose-spec/compose-go/v2/loader/reset.go index 8dd5e1bb..33ea4c2c 100644 --- a/vendor/github.com/compose-spec/compose-go/v2/loader/reset.go +++ b/vendor/github.com/compose-spec/compose-go/v2/loader/reset.go @@ -28,11 +28,12 @@ import ( type ResetProcessor struct { target interface{} paths []tree.Path - visitedNodes map[*yaml.Node]string + visitedNodes map[*yaml.Node][]string } // UnmarshalYAML implement yaml.Unmarshaler func (p *ResetProcessor) UnmarshalYAML(value *yaml.Node) error { + p.visitedNodes = make(map[*yaml.Node][]string) resolved, err := p.resolveReset(value, tree.NewPath()) p.visitedNodes = nil if err != nil { @@ -49,24 +50,12 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No path = tree.NewPath(strings.Replace(pathStr, ".<<", "", 1)) } - // Check for cycle - if p.visitedNodes == nil { - p.visitedNodes = make(map[*yaml.Node]string) - } - - // Check for cycle by seeing if the node has already been visited at this path - if previousPath, found := p.visitedNodes[node]; found { - // If the current node has been visited, we have a cycle if the previous path is a prefix - if strings.HasPrefix(pathStr, previousPath) { - return nil, fmt.Errorf("cycle detected at path: %s", pathStr) - } - } - - // Mark the current node as visited - p.visitedNodes[node] = pathStr + "." - // If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags if node.Kind == yaml.AliasNode { + if err := p.checkForCycle(node.Alias, path); err != nil { + return nil, err + } + return p.resolveReset(node.Alias, path) } @@ -154,3 +143,48 @@ func (p *ResetProcessor) applyNullOverrides(target any, path tree.Path) error { } return nil } + +func (p *ResetProcessor) checkForCycle(node *yaml.Node, path tree.Path) error { + paths := p.visitedNodes[node] + pathStr := path.String() + + for _, prevPath := range paths { + // If we're visiting the exact same path, it's not a cycle + if pathStr == prevPath { + continue + } + + // If either path is using a merge key, it's legitimate YAML merging + if strings.Contains(prevPath, "<<") || strings.Contains(pathStr, "<<") { + continue + } + + // Only consider it a cycle if one path is contained within the other + // and they're not in different service definitions + if (strings.HasPrefix(pathStr, prevPath+".") || + strings.HasPrefix(prevPath, pathStr+".")) && + !areInDifferentServices(pathStr, prevPath) { + return fmt.Errorf("cycle detected: node at path %s references node at path %s", pathStr, prevPath) + } + } + + p.visitedNodes[node] = append(paths, pathStr) + return nil +} + +// areInDifferentServices checks if two paths are in different service definitions +func areInDifferentServices(path1, path2 string) bool { + // Split paths into components + parts1 := strings.Split(path1, ".") + parts2 := strings.Split(path2, ".") + + // Look for the services component and compare the service names + for i := 0; i < len(parts1) && i < len(parts2); i++ { + if parts1[i] == "services" && i+1 < len(parts1) && + parts2[i] == "services" && i+1 < len(parts2) { + // If they're different services, it's not a cycle + return parts1[i+1] != parts2[i+1] + } + } + return false +} diff --git a/vendor/github.com/compose-spec/compose-go/v2/types/config.go b/vendor/github.com/compose-spec/compose-go/v2/types/config.go index a2382fb3..d73d2b9f 100644 --- a/vendor/github.com/compose-spec/compose-go/v2/types/config.go +++ b/vendor/github.com/compose-spec/compose-go/v2/types/config.go @@ -67,6 +67,10 @@ type ConfigFile struct { Config map[string]interface{} } +func (cf ConfigFile) IsStdin() bool { + return cf.Filename == "-" +} + func ToConfigFiles(path []string) (f []ConfigFile) { for _, p := range path { f = append(f, ConfigFile{Filename: p}) diff --git a/vendor/modules.txt b/vendor/modules.txt index 9432eb5a..03a119da 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -128,7 +128,7 @@ github.com/cenkalti/backoff/v4 # github.com/cespare/xxhash/v2 v2.3.0 ## explicit; go 1.11 github.com/cespare/xxhash/v2 -# github.com/compose-spec/compose-go/v2 v2.4.2 +# github.com/compose-spec/compose-go/v2 v2.4.4 ## explicit; go 1.21 github.com/compose-spec/compose-go/v2/cli github.com/compose-spec/compose-go/v2/consts