Skip to content

Commit

Permalink
Change method signature of Patch.Apply
Browse files Browse the repository at this point in the history
- Consume crossplane-runtime where fake.ConnectionDetailsLastPublishedTimer.Time has
  an `omitempty` json tag so that we keep runtime.DefaultUnstructuredConverter.ToUnstructured
  happy.

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Oct 20, 2022
1 parent e8d1166 commit d49d028
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
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
6 changes: 4 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 Expand Up @@ -983,6 +983,8 @@ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqri
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA=
github.com/ulucinar/crossplane-runtime v0.13.1-0.20221019204607-31279534ed17 h1:BWyh48bCpox/IMESDTp1Fwj9H88LxkUE57acHZ0ch34=
github.com/ulucinar/crossplane-runtime v0.13.1-0.20221019204607-31279534ed17/go.mod h1:o9ExoilV6k2M3qzSFoRVX4phuww0mLmjs1WrDTvsR4s=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
Expand Down

0 comments on commit d49d028

Please sign in to comment.