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

Strip .meta.managedFields for kubectl edit command #91946

Merged
merged 1 commit into from
Jul 9, 2020

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Jun 9, 2020

What type of PR is this?
/kind feature
/sig cli
/priority backlog

What this PR does / why we need it:
With the introduction of .meta.managedFields it's cumbersome to edit any resource due to the size of that additional fields. This PR hides those fields, since they should not even be modified by consumers directly.

Which issue(s) this PR fixes:
Fixes #90066

Special notes for your reviewer:
/assign @sttts @apelisse

Does this PR introduce a user-facing change?:

Hide managedFields from kubectl edit command

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Jun 9, 2020
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/cli Categorizes an issue or PR as relevant to SIG CLI. priority/backlog Higher priority than priority/awaiting-more-evidence. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/kubectl labels Jun 9, 2020
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 9, 2020
@lavalamp
Copy link
Member

lavalamp commented Jun 9, 2020

This field is editable and we shouldn't make that impossible. Can we get a flag for not stripping it?

@@ -437,6 +439,22 @@ func (o *EditOptions) Run() error {
}
}

func stripManagedFields(obj runtime.Object) error {
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 technically this should work, however I am not sure it is future proof if we e.g. add another field format. I would greatly prefer it if you put them back before constructing the patch that will be sent to apiserver.

@apelisse
Copy link
Member

apelisse commented Jun 9, 2020

@soltysh Discussion is going on about this general topic here: #90066

Would be nice if we had a more general solution.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 7, 2020
@soltysh soltysh changed the title WIP: Strip .meta.managedFields for kubectl edit command Strip .meta.managedFields for kubectl edit command Jul 7, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 7, 2020
@soltysh
Copy link
Contributor Author

soltysh commented Jul 7, 2020

@apelisse @lavalamp updated per your comments, ptal

@soltysh
Copy link
Contributor Author

soltysh commented Jul 7, 2020

/retest

if err != nil {
return err
}
mf := o.managedFields[metaObjs.GetUID()]
Copy link
Member

Choose a reason for hiding this comment

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

I recommend detecting if the user tried to add something here and failing with a message if so, e.g. "you can't use kubectl edit to edit the managed field list".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, there's a mergepatch.PreconditionFunc which I wanted to update and I forgot, updated.

@@ -437,6 +454,49 @@ func (o *EditOptions) Run() error {
}
}

func (o *EditOptions) extractManagedFields(obj runtime.Object) error {
Copy link
Member

Choose a reason for hiding this comment

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

A test for extract / clear / restore would be good?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return metaObjs.GetUID(), mf, nil
}

func (o *EditOptions) reAddManagedFields(infos []*resource.Info) error {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I suggest "restore" rather than "reAdd"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 7, 2020
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2020
@lavalamp
Copy link
Member

lavalamp commented Jul 7, 2020

This looks to me like it does the right thing now. 👍

Maybe you want an official LGTM from someone a bit closer to the kubectl code though?

@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@apelisse
Copy link
Member

apelisse commented Jul 7, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 7, 2020
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

2 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@soltysh
Copy link
Contributor Author

soltysh commented Jul 8, 2020

/hold
the verify failure is real

@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 Jul 8, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 8, 2020
@soltysh
Copy link
Contributor Author

soltysh commented Jul 8, 2020

/hold cancel
the gofmt was fixed

@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 Jul 8, 2020
@p0lyn0mial
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 8, 2020
@soltysh
Copy link
Contributor Author

soltysh commented Jul 8, 2020

/milestone v1.19

@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Jul 8, 2020
@apelisse
Copy link
Member

apelisse commented Jul 8, 2020

/retest

1 similar comment
@soltysh
Copy link
Contributor Author

soltysh commented Jul 8, 2020

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

managedFields options are very verbose, making kubectl usage a bit
7 participants