Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/Masterminds/semver/v3 v3.5.0
github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29
github.com/Microsoft/hcsshim v0.15.0-rc.4
github.com/compose-spec/compose-go/v2 v2.15.0 //gomodjail:unconfined
github.com/compose-spec/compose-go/v2 v2.16.1 //gomodjail:unconfined
github.com/containernetworking/cni v1.3.1 //gomodjail:unconfined
github.com/containernetworking/plugins v1.9.1 //gomodjail:unconfined
github.com/coreos/go-iptables v0.8.0 //gomodjail:unconfined
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
github.com/cilium/ebpf v0.22.0/go.mod h1:CDzZbe2hC5JjlDC+CY3KFCzlYwN4gbxppYM+Z10bQt4=
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
github.com/compose-spec/compose-go/v2 v2.15.0 h1:tdQw+eMyT+P6ZIb09JfcIVvbMmIa+PjST7cWezVLf00=
github.com/compose-spec/compose-go/v2 v2.15.0/go.mod h1:Q1+qtN4vhzEjGrnqRtzx1xa8raDZQlMUe3WJxndYNiQ=
github.com/compose-spec/compose-go/v2 v2.16.1 h1:xuEQu32ghB2AK023Beumm//K8bz8u1AHC9P0zKp8jlw=

Check warning on line 23 in go.sum

View workflow job for this annotation

GitHub Actions / deps / dependencies

gosocialcheck

import 'github.com/compose-spec/compose-go/v2/types': module 'github.com/compose-spec/compose-go/v2@v2.16.1' does not seem adopted by a trusted project (negligible if you trust the module)
github.com/compose-spec/compose-go/v2 v2.16.1/go.mod h1:Q1+qtN4vhzEjGrnqRtzx1xa8raDZQlMUe3WJxndYNiQ=
github.com/containerd/accelerated-container-image v1.4.5 h1:m3dw34J2qVq36TGOg0GCHUewwx2L3U2B8dgfSaA7Mmc=
github.com/containerd/accelerated-container-image v1.4.5/go.mod h1:vCgrmhBDiF4dLRPLSHrcwGTrrW/ooioV+xQhTzwUUxk=
github.com/containerd/cgroups/v3 v3.1.3 h1:eUNflyMddm18+yrDmZPn3jI7C5hJ9ahABE5q6dyLYXQ=
Expand Down
40 changes: 23 additions & 17 deletions pkg/composer/serviceparser/serviceparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,25 +668,29 @@ func TestParseImageVolumeServiceNameIsLiteral(t *testing.T) {
{
name: "build service",
referencedService: types.ServiceConfig{
Name: "builder",
Build: &types.BuildConfig{},
Platform: "linux/amd64",
Name: "builder",
ContainerSpec: types.ContainerSpec{Platform: "linux/amd64"},
WorkloadSpec: types.WorkloadSpec{Build: &types.BuildConfig{}},
},
},
{
name: "explicit image",
referencedService: types.ServiceConfig{
Name: "builder",
Image: "nginx:alpine",
Platform: "linux/amd64",
Name: "builder",
ContainerSpec: types.ContainerSpec{
Image: "nginx:alpine",
Platform: "linux/amd64",
},
},
},
{
name: "disabled explicit image service",
referencedService: types.ServiceConfig{
Name: "builder",
Image: "nginx:alpine",
Platform: "linux/amd64",
Name: "builder",
ContainerSpec: types.ContainerSpec{
Image: "nginx:alpine",
Platform: "linux/amd64",
},
},
disabled: true,
},
Expand All @@ -696,14 +700,16 @@ func TestParseImageVolumeServiceNameIsLiteral(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
app := types.ServiceConfig{
Name: "app",
Image: "alpine",
Platform: "linux/arm64",
Volumes: []types.ServiceVolumeConfig{{
Type: types.VolumeTypeImage,
Source: "builder",
Target: "/website",
}},
Name: "app",
ContainerSpec: types.ContainerSpec{
Image: "alpine",
Platform: "linux/arm64",
Volumes: []types.ServiceVolumeConfig{{
Type: types.VolumeTypeImage,
Source: "builder",
Target: "/website",
}},
},
}
project := &types.Project{
Name: "project",
Expand Down
21 changes: 19 additions & 2 deletions pkg/reflectutil/reflectutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
)

func UnknownNonEmptyFields(structOrStructPtr interface{}, knownNames ...string) []string {
var unknown []string
knownNamesMap := make(map[string]struct{}, len(knownNames))
for _, name := range knownNames {
knownNamesMap[name] = struct{}{}
Expand All @@ -37,12 +36,30 @@ func UnknownNonEmptyFields(structOrStructPtr interface{}, knownNames ...string)
default:
panic(fmt.Errorf("expected Ptr or Struct, got %+v", kind))
}
return unknownNonEmptyFields(val, knownNamesMap)
}

func unknownNonEmptyFields(val reflect.Value, knownNamesMap map[string]struct{}) []string {
var unknown []string
for i := 0; i < val.NumField(); i++ {
iField := val.Field(i)
if isEmpty(iField) {
continue
}
iName := val.Type().Field(i).Name
iStructField := val.Type().Field(i)
// Walk embedded structs, so that their promoted fields are checked by their own names.
// e.g., compose-go v2.16 moved ServiceConfig.Image to ServiceConfig.ContainerSpec.Image .
if iStructField.Anonymous {
embedded := iField
if embedded.Kind() == reflect.Ptr {
embedded = embedded.Elem()
}
if embedded.Kind() == reflect.Struct {
unknown = append(unknown, unknownNonEmptyFields(embedded, knownNamesMap)...)
continue
}
}
iName := iStructField.Name
if _, ok := knownNamesMap[iName]; !ok {
unknown = append(unknown, iName)
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/reflectutil/reflectutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,37 @@ func TestUnknownNonEmptyFields(t *testing.T) {
[]string{"FooStr", "FooStr3"},
UnknownNonEmptyFields(&foo3, "FooBool"))
}

func TestUnknownNonEmptyFieldsEmbedded(t *testing.T) {
type Inner struct {
InnerStr string
InnerStr2 string
}
type Inner2 struct {
Inner2Str string
}
type outer struct {
OuterStr string
Inner
*Inner2
}

o := outer{
OuterStr: "foo",
Inner: Inner{
InnerStr: "bar",
InnerStr2: "baz",
},
Inner2: &Inner2{
Inner2Str: "qux",
},
}
assert.DeepEqual(t,
[]string{"InnerStr2", "Inner2Str"},
UnknownNonEmptyFields(&o, "OuterStr", "InnerStr"))

o.Inner2 = nil
assert.DeepEqual(t,
[]string{"OuterStr", "InnerStr", "InnerStr2"},
UnknownNonEmptyFields(o))
}
Loading