Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume latest crossplane-runtime's fake.Composite to prevent panics caught by CNCF fuzzing tests #3394

Merged
merged 1 commit into from
Oct 20, 2022
Merged
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
3 changes: 2 additions & 1 deletion apis/apiextensions/v1/composition_patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/resource"
)

const (
Expand Down Expand Up @@ -119,7 +120,7 @@ type Patch struct {

// Apply executes a patching operation between the from and to resources.
// Applies all patch types unless an 'only' filter is supplied.
func (c *Patch) Apply(cp, cd runtime.Object, only ...PatchType) error {
func (c *Patch) Apply(cp resource.Composite, cd resource.Composed, only ...PatchType) error {
if c.filterPatch(only...) {
return nil
}
Expand Down
35 changes: 34 additions & 1 deletion apis/apiextensions/v1/composition_patches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/resource/fake"
"github.com/crossplane/crossplane-runtime/pkg/test"
)
Expand Down Expand Up @@ -125,6 +126,38 @@ func TestPatchApply(t *testing.T) {
err: nil,
},
},
"ValidCompositeFieldPathPatchWithNilLastPublishTime": {
reason: "Should correctly apply a CompositeFieldPathPatch with valid settings",
args: args{
patch: Patch{
Type: PatchTypeFromCompositeFieldPath,
FromFieldPath: pointer.StringPtr("objectMeta.labels"),
ToFieldPath: pointer.StringPtr("objectMeta.labels"),
},
cp: &fake.Composite{
ObjectMeta: metav1.ObjectMeta{
Name: "cp",
Labels: map[string]string{
"Test": "blah",
},
},
},
cd: &fake.Composed{
ObjectMeta: metav1.ObjectMeta{Name: "cd"},
},
},
want: want{
cd: &fake.Composed{
ObjectMeta: metav1.ObjectMeta{
Name: "cd",
Labels: map[string]string{
"Test": "blah",
},
},
},
err: nil,
},
},
"ValidCompositeFieldPathPatchWithWildcards": {
reason: "When passed a wildcarded path, adds a field to each element of an array",
args: args{
Expand Down Expand Up @@ -826,7 +859,7 @@ func TestPatchApply(t *testing.T) {
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ncp := tc.args.cp.DeepCopyObject()
ncp := tc.args.cp.DeepCopyObject().(resource.Composite)
err := tc.args.patch.Apply(ncp, tc.args.cd, tc.args.only...)

if tc.want.cp != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/Masterminds/semver v1.5.0
github.com/alecthomas/kong v0.2.17
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221012013934-bce61005a175
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221020071948-fa5545f26b04
github.com/google/go-cmp v0.5.8
github.com/google/go-containerregistry v0.9.0
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20220517194345-84eb52633e96
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221012013934-bce61005a175 h1:qGLew6IazCwfgvY4/xh5lQiumip/WrULpQfW4duol6g=
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221012013934-bce61005a175/go.mod h1:o9ExoilV6k2M3qzSFoRVX4phuww0mLmjs1WrDTvsR4s=
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221020071948-fa5545f26b04 h1:DGu6CsdRk1Eg2BC77pgLqb6qCjw6Ju0c6UIdxfyT6qs=
github.com/crossplane/crossplane-runtime v0.19.0-rc.0.0.20221020071948-fa5545f26b04/go.mod h1:o9ExoilV6k2M3qzSFoRVX4phuww0mLmjs1WrDTvsR4s=
github.com/daixiang0/gci v0.2.9/go.mod h1:+4dZ7TISfSmqfAGv59ePaHfNzgGtIkHAhhdKggP1JAc=
github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7hqDjlFjiygg=
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down