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

kubectl: apply --server-side managed fields migration #112905

Merged

Conversation

alexzielenski
Copy link
Contributor

@alexzielenski alexzielenski commented Oct 6, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR will transparently take ownership of any client-side-apply fields when --server-side apply is used. If this is not done, then it will not be possible to remove fields previously used by client-side-apply with server-side-apply (without manually patching managed fields yourself).

Previously this change was proposed in a KEP, but during discussion with the SIG we have scoped it down to a bug fix.

Which issue(s) this PR fixes:

addresses issues brought up in the following and likely more bug reports

Fixes #107980
Fixes #108081
Fixes #107417
Fixes #112826
Fixed #99003

Special notes for your reviewer:

Does this PR introduce a user-facing change?

For `kubectl`, `--server-side` now migrates ownership of all fields used by client-side-apply to the specified `--fieldmanager`. This prevents fields previously specified using kubectl from being able to live outside of server-side-apply's management and become undeleteable.

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

- [Discussion]: https://github.com/kubernetes/enhancements/pull/3518#discussion_r984724392

/sig cli
/cc @soltysh @KnVerey @apelisse

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Oct 6, 2022
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubectl sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Oct 6, 2022
@alexzielenski
Copy link
Contributor Author

/hold still doing some manual testing, but sharing this PR to show general approach

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 6, 2022
Copy link
Contributor Author

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

left some comments/discussion points

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/client-go/util/csaupgrade/upgrade.go Outdated Show resolved Hide resolved
Copy link
Member

@ardaguclu ardaguclu left a comment

Choose a reason for hiding this comment

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

I'm very happy to see that this known problem is being fixed.

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/client-go/util/csaupgrade/upgrade.go Outdated Show resolved Hide resolved
@sftim
Copy link
Contributor

sftim commented Oct 10, 2022

For the release note, can I suggest:

For `kubectl`, `--server-side` now migrates ownership of all fields used by client-side-apply to the specified `--fieldmanager`. This prevents fields previously specified using kubectl from being able to live outside of server-side-apply's management and become undeleteable.

?

@fedebongio
Copy link
Contributor

/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 Oct 11, 2022
@apelisse
Copy link
Member

apelisse commented Oct 12, 2022

I would definitely love to have @seans3 review this.

Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

This PR is in a good place. This PR has a lot of useful comments -- we probably need more. It would be useful to describe the migration process high level somewhere. Something like:

field ownership metadata is stored in three places: server-side-manager
fields, client-side-manager fields, and the last_applied_configuration annotation.
The migration merges the client-side-manager fields into the server-side-manager
fields, and removes the last_applied_annotation (if keepLastApplied is false), so
the only remaining metadata is server-side-manager fields.

Warnings will be fine in the places you've enumerated. There are examples in the apply.go file showing how to print warnings.

The one area that we'll need to work on is the tests. Current kubectl apply unit tests are dense, but we'll need to add significant unit tests to ensure proper coverage. As a general rule, we should not have lower unit test coverage numbers after a PR. Including before/after unit test coverage numbers in the PR would be useful. Integration tests will be helpful, but the
focus should be on unit tests. Let's get together to see how to test this.

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.

Mostly good, thanks, missing test-cmd as discussed offline.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 20, 2022
@alexzielenski
Copy link
Contributor Author

/retest

Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

I have a couple more very minor suggestions, but no concerns. LGTM!

/lgtm
/approve

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go Outdated Show resolved Hide resolved
test/cmd/apply.sh Outdated Show resolved Hide resolved
test/cmd/apply.sh Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 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.

/approve

I can lgtm once Katrina's comments have been addressed, thanks

// the fields in the given set
//
// If there is an error decoding one of the fieldsets for any reason, it is ignored
// and assumed not to match the query.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a TODO here that we need to account for subresource. And maybe specifically look for empty subresource in the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo was added here:

//!TODO: some users may want to migrate subresources.
// should thread through the args at some point.
entry.Subresource == "" &&

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
in discussion with SIG, there is a strong interest in keeping the last-applied-configuration around for a bit longer as other tools transition for of it. This is OK since SSA maintains the annotation on kubectl's behalf on the server-side if it exists

migrate client-side-apply fields to SSA when --serverside-side is used

kubernetes#107980

kubernetes#108081

kubernetes#107417

kubernetes#112826

add test to make sure only one apply is needed after migration
@alexzielenski
Copy link
Contributor Author

/retest

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
"value": filteredManagers,
},
{
// Use "replace" instead of "test" operation so that etcd rejects with
Copy link
Member

Choose a reason for hiding this comment

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

We don't write this field to etcd so I don't think this explanation is right?

Copy link
Member

@apelisse apelisse Nov 7, 2022

Choose a reason for hiding this comment

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

So if we do a json-patch test of resourceVersion, the patch fails to apply without much details. If we set the resourceVersion, then the compare-and-switch etcd performs to write the object fails, and we get a proper 409 conflict. The comment reads fine to me.

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 it's the "etcd rejects" part that threw me off, I thought it was implying that etcd was checking the field instead of this being passed as metadata on the request.

Maybe open an issue about improving error messages from test directives in patches?

Copy link
Member

@apelisse apelisse Nov 7, 2022

Choose a reason for hiding this comment

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

We could improve the error messages, but I don't know if the apiserver will ever interpret/return a failure to apply the patch as a 409 Conflict? Also, applying that patch is done from a third-party dependency.

@lavalamp
Copy link
Member

lavalamp commented Nov 7, 2022

/approve

for client-go

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/approve
for vendor/modules.txt

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, apelisse, BenTheElder, KnVerey, lavalamp

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 Nov 7, 2022
@alexzielenski
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 7, 2022
@k8s-ci-robot
Copy link
Contributor

@alexzielenski: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-integration ff5e44f link unknown /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@alexzielenski
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 2f837dc into kubernetes:master Nov 8, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 8, 2022
@alexzielenski alexzielenski deleted the kubectl-apply-csa-migration branch November 16, 2022 18:49
@fjolublar
Copy link

Hi @alexzielenski,
Are there any plans to bring this fix to 1.25?

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/kubectl area/test 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. 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. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet