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

Update existing resources #243

Closed
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 build
2 changes: 1 addition & 1 deletion internal/controller/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
v1.LastAppliedConfigAnnotation: string(cr.Spec.ForProvider.Manifest.Raw),
})

if err := c.client.Apply(ctx, obj); err != nil {
if err := c.client.Update(ctx, obj); err != nil {
bradkwadsworth-mw marked this conversation as resolved.
Show resolved Hide resolved
return managed.ExternalUpdate{}, errors.Wrap(CleanErr(err), errApplyObject)
}

Expand Down
36 changes: 22 additions & 14 deletions internal/controller/object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ func Test_helmExternal_Update(t *testing.T) {
args: args{
mg: kubernetesObject(),
client: resource.ClientApplicator{
Applicator: resource.ApplyFn(func(context.Context, client.Object, ...resource.ApplyOption) error {
return errBoom
}),
Client: &test.MockClient{
MockUpdate: test.NewMockUpdateFn(errBoom),
},
},
},
want: want{
Expand All @@ -829,16 +829,18 @@ func Test_helmExternal_Update(t *testing.T) {
args: args{
mg: kubernetesObject(func(obj *v1alpha2.Object) {
obj.Spec.ForProvider.Manifest.Raw = []byte(`{
"apiVersion": "v1",
"kind": "Namespace" }`)
"apiVersion": "v1",
"kind": "Namespace" }`)
}),
client: resource.ClientApplicator{
Applicator: resource.ApplyFn(func(ctx context.Context, obj client.Object, op ...resource.ApplyOption) error {
if obj.GetName() != testObjectName {
t.Errorf("Name should default to object name when not provider in manifest")
}
return nil
}),
Client: &test.MockClient{
MockUpdate: test.NewMockUpdateFn(nil, func(obj client.Object) error {
if obj.GetName() != testObjectName {
t.Errorf("Name should default to object name when not provider in manifest")
}
return nil
}),
},
},
},
want: want{
Expand All @@ -849,9 +851,15 @@ func Test_helmExternal_Update(t *testing.T) {
args: args{
mg: kubernetesObject(),
client: resource.ClientApplicator{
Applicator: resource.ApplyFn(func(context.Context, client.Object, ...resource.ApplyOption) error {
return nil
}),
Client: &test.MockClient{
MockUpdate: test.NewMockUpdateFn(nil, func(obj client.Object) error {
_, ok := obj.GetAnnotations()[corev1.LastAppliedConfigAnnotation]
if !ok {
t.Errorf("Last applied annotation not set with create")
}
return nil
}),
},
},
},
want: want{
Expand Down