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

⚠️ Minimal Apply Support, Fix Up Client Options #435

Merged

Conversation

DirectXMan12
Copy link
Contributor

This fixes up client options (collapsing nillary functions to not require parens), makes sure that status update takes options, adds status patch, and adds a patch type and relevant options for server-side apply.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 17, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 17, 2019
@DirectXMan12 DirectXMan12 force-pushed the feature/minimal-apply branch 2 times, most recently from 21c61b5 to c6745c7 Compare May 17, 2019 21:54
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Looks good, have few minor comments (I will swing by your desk, we can resolve it there)

return sw.client.typedClient.UpdateStatus(ctx, obj, opts...)
}

// Patch implements client.Client
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit confused about -- does it patches the object or just the status of the object ?

It("should allow setting the field manager", func() {
po := &client.PatchOptions{}
client.FieldOwner("some-owner")(po)
Expect(po.AsPatchOptions().FieldManager).To(Equal("some-owner"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we are mixing owner/manager terms here. would be nice if we can be consistent 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.

for posterity: manager is the term used by the kubernetes API, but I feel it's non-intuitive, so I picked fieldowner for the option name. We do that a couple of places.

Copy link

@apelisse apelisse Jun 4, 2019

Choose a reason for hiding this comment

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

We've had a few discussion, and "official" term is FieldManager, ManagedFields, etc ...


func (sw *fakeStatusWriter) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOptionFunc) error {
// TODO(droot): This results in full update of the obj (spec + status). Need
// a way to update status field only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like I am inheriting something here :)


// Type implements Patch.
func (p applyPatch) Type() types.PatchType {
// TODO(directxman12): when we update to 1.14, just use types.ApplyPatch
Copy link
Contributor

Choose a reason for hiding this comment

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

We are on 1.14 now right ?, so may be can update this.

NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Name(o.GetName()).
SubResource("status").
Copy link
Contributor

Choose a reason for hiding this comment

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

ok (I get it) server-side apply is implemented using patch on status sub-resource, little intuitive but I am sure they must have some reasons for it.
So that means, CRD needs to have status sub-resource enabled (I wonder if we should generate marker for status subresource by default or we already do ?)

Copy link

Choose a reason for hiding this comment

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

ok (I get it) server-side apply is implemented using patch on status sub-resource, little intuitive [clipped]

Not just status, all resources/sub-resources.

@@ -2262,7 +2268,7 @@ var _ = Describe("Patch", func() {
patch := client.MergeFrom(cm.DeepCopy())

By("returning a patch with type MergePatch")
Expect(patch.Type()).To(Equal(types.MergePatchType))
Expect(patch.Type()).To(Equal(types.StrategicMergePatchType))

By("retrieving modifying the config map")
metav1.SetMetaDataAnnotation(&cm.ObjectMeta, annotationKey, annotationValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add any tests for applyPatch ?

Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

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

Other pieces LGTM

@@ -244,8 +244,14 @@ type fakeStatusWriter struct {
client *fakeClient
}

func (sw *fakeStatusWriter) Update(ctx context.Context, obj runtime.Object) error {
func (sw *fakeStatusWriter) Update(ctx context.Context, obj runtime.Object, opts ...client.UpdateOptionFunc) error {
// TODO(droot): This results in full update of the obj (spec + status). Need
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this TODO, since we have status client.

}

func (sw *fakeStatusWriter) Patch(ctx context.Context, obj runtime.Object, patch client.Patch, opts ...client.PatchOptionFunc) error {
// TODO(droot): This results in full update of the obj (spec + status). Need
Copy link
Member

Choose a reason for hiding this comment

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

Same here.


// FieldManager is the name of the user or component submitting
// this request. It must be set with server-side apply.
FieldManager string
Copy link
Member

Choose a reason for hiding this comment

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

All of Create|Update|PatchOptions in upstream has FieldManager.
In CR, only PatchOptions has explicit FieldManager field. Should we make it consistent for all of Create|Update|PatchOptions?

@DirectXMan12 DirectXMan12 force-pushed the feature/minimal-apply branch 2 times, most recently from 1d65338 to b90dec0 Compare May 17, 2019 22:29
This introduces a patch type for server-side apply, and the associated
patch options.
This adds patch options related to server-side apply, and moves options
to their own file.
This switches functional arguments with no variables to not taking
arguments, meaning that they can be called like

```go
r.Update(ctx, obj, client.UpdateDryRunAll)
```

instead of

```go
r.Update(ctx, obj, client.UpdateDryRunAll())
```

Options with arguments still get called as functions.
This adds .Status().Patch to the client for patching status, and makes sure
that .Status().Update takes update options like normal update does.
@droot droot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2019
@k8s-ci-robot k8s-ci-robot merged commit 38483b2 into kubernetes-sigs:master May 17, 2019
@DirectXMan12 DirectXMan12 deleted the feature/minimal-apply branch May 17, 2019 22:44
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants