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 managedFields time when field value is modified #110058

Merged
merged 1 commit into from May 23, 2022

Conversation

glebiller
Copy link
Contributor

@glebiller glebiller commented May 15, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

The managedFields.time is not updated if only the value of a managed field is changed during apply. According to the doc, the time field should be updated during creation, when a field is added or removed, or when a field value is changed.
This PR detects if a managed field has been modified and updates the time accordingly.

Which issue(s) this PR fixes:

Fixes #109576

Special notes for your reviewer:

I had to remove the unit test validating that when a non-managed field is updated, the time is not changed. It seems impossible to validate that we either have a conflict exception if a non-managed field is updated or the time should be updated.

Does this PR introduce a user-facing change?

ManagedFields time is correctly updated when the value of a managed field is modified.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 15, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @glebiller. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 15, 2022
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 15, 2022
@glebiller
Copy link
Contributor Author

/assign @apelisse

Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

I left a comment, can you also double-check that the behavior with Apply is consistent?

Thank you for working on this!

@MikeSpreitzer
Copy link
Member

Thanks for working on this!

@glebiller glebiller force-pushed the managed-fields-time branch 3 times, most recently from 455bf7c to e2b3c97 Compare May 17, 2022 09:49
@glebiller
Copy link
Contributor Author

Following the feedback, I simplified the code and added the following unit tests for both apply & update:

  • A change to a managed field should update the time
  • No changes to managed fields should not update the time
  • A change to a non-managed field should not update the time

For Update

It looks like managed.Fields()[self] is defined only if there is a change to a managed field.
I, therefore, removed the second check to always update the time.

For Apply

The server-side-apply seems to be functional during my test in a live cluster. With the unit tests, I noticed that the object is either nil when the time does not need to be updated or not-nil when the update is required. I removed the extra condition.

Note for the reviewer

I notice that in the unit test TestNonManagedFieldsUpdateDoesNotModifyTime, after the third Update, the ManagedFields only have the fields from one manager (fieldmanager_a_test) and is missing the ManagedFields entry for the second manager ('fieldmanager_b_test'). Is this an intended behavior?

The Apply behavior is different, as the third Apply correctly returns the ManagedFields for both managers with the time changed accordingly.

@roycaihw
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 17, 2022
Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

One thing that we have in the doc but isn't tested here, is that when a field is removed from a set (because it's stolen by someone else), that set's timestamp doesn't change, i.e.

In mostly pseudo-code:

applyObject("managerA", `{fieldA: true, fieldB: true}`)
time.Sleep(1)
applyObject("managerB", `{fieldA: false}`)
// Check that managerA timestamp hasn't changed.

@glebiller
Copy link
Contributor Author

One thing that we have in the doc but isn't tested here, is that when a field is removed from a set (because it's stolen by someone else), that set's timestamp doesn't change, i.e.

In mostly pseudo-code:

applyObject("managerA", `{fieldA: true, fieldB: true}`)
time.Sleep(1)
applyObject("managerB", `{fieldA: false}`)
// Check that managerA timestamp hasn't changed.

According to the Server-Side-Apply doc, this is not possible because it raises a conflict error. I tried creating a unit test for that case, but I got the following error:
failed to apply object: Apply failed with 1 conflict: conflict with "fieldmanager_a_test": .data.key_b

The use case that could be tested, is during the Update instead of Apply.

@apelisse
Copy link
Member

According to the Server-Side-Apply doc, this is not possible because it raises a conflict error. I tried creating a unit test for that case, but I got the following error: failed to apply object: Apply failed with 1 conflict: conflict with "fieldmanager_a_test": .data.key_b

The use case that could be tested, is during the Update instead of Apply.

There is a "Force" field to steal ownership with Apply, which will let you test the same scenario!

@apelisse
Copy link
Member

Thanks, LGTM once you add the TestTakingOverManagedFieldsDuringApplyDoesNotModifyPreviousManagerTime

@glebiller
Copy link
Contributor Author

glebiller commented May 19, 2022

That's on me, I should have thought about the force as it's similar to the kubectl command line :)
I added the unit test and all the UT are now passing! Thanks for your help @apelisse

@glebiller glebiller requested a review from apelisse May 21, 2022 06:21
Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, glebiller

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 23, 2022
@k8s-ci-robot k8s-ci-robot merged commit 31a1024 into kubernetes:master May 23, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone May 23, 2022
@MikeSpreitzer
Copy link
Member

Thanks!

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. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

client-side apply does not cause managedFields update
5 participants