Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

use update instead of patch on applying trait #283

Merged
merged 2 commits into from
Nov 8, 2020

Conversation

captainroy-hy
Copy link
Contributor

to fix #272

Solution: Add a new updatingClient to update trait while retain patchingClient to apply workload.

add e2e-test

Signed-off-by: roy wang seiwy2010@gmail.com

Comment on lines 79 to 81
patchingClient resource.Applicator
updatingClient resource.Applicator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should answer why we need two client with same type here. Everyone review this code will have the same question. Add the answer to annotation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

  • patchingClient will be used to patching-apply Workload objs while updatingClient will be used to updating-apply Trait objs. As Trait apply should use update instead of patch #272 described, patching-apply cannot remove fields that are present before applying but absent now, that's not expected for Trait. So we use update instead of patch for applying Trait.
  • The applying strategy on Workload is TBD, so just keep patchingClient unchanged.

@@ -0,0 +1,196 @@
package controllers_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please try refactor it to be unit-test, thanks! Only necessary cases use e2e test, this could be a unit test like dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it.

upgrade crossplane/crossplane-runtime 0.8.0=>0.10.0

add e2e-test

Signed-off-by: roy wang <seiwy2010@gmail.com>
Signed-off-by: roy wang <seiwy2010@gmail.com>
@@ -95,7 +98,7 @@ func (a *workloads) Apply(ctx context.Context, status []v1alpha2.WorkloadStatus,
continue
}
t := trait.Object
if err := a.client.Apply(ctx, &trait.Object, ao...); err != nil {
if err := a.updatingClient.Apply(ctx, &trait.Object, ao...); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not change Apply() to update? That's more clear. Otherwise it still looks similar to kubectl apply.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary concern is that if use client.Update(), we need more code, e.g., Get/Check-IfNotFound-Create/IfFound-SetResourceVersion-Update, just like what underlying of Apply() has done. So maybe we can just re-use Apply() here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Member

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trait apply should use update instead of patch
3 participants