Skip to content

Conversation

@jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Jun 22, 2020

Implements the first part of the WG Apply: Unsetting fields design:

Omitting a shared field from an applied configuration:

  • Applier gives up ownership but the field remains unchanged.

Omit an exclusively owned field from an applied configuration:

  • Optional field: field is removed or defaulted.
  • Required field: the apply operation will fail with a validation error.

This makes fields consistent with how associative list/map items already behave.

Added a test converter that renames fields (e.g. conversion of v1 to v2 renames "field_v1" to "field_v2") and used it to ensure that fields are unset when the unset is applied at a different version than the previous apply.

cc @apelisse @jennybuckley @lavalamp

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 22, 2020
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 22, 2020
@jpbetz jpbetz changed the title Remove fields when unset from applied configuration if there are no other owners Remove fields that are omitted from applied configurations if there are no other owners Jun 22, 2020
@apelisse
Copy link
Contributor

Could you please specifically pinpoint the limitation of the code in this pull-request? I'm assuming it won't work perfectly across versions?

@apelisse
Copy link
Contributor

By the way, while you're looking at this code, we should understand and fix the bug with "complex nested types".

@jpbetz jpbetz changed the title Remove fields that are omitted from applied configurations if there are no other owners WIP: Remove fields that are omitted from applied configurations if there are no other owners Jun 22, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 22, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 22, 2020

Could you please specifically pinpoint the limitation of the code in this pull-request? I'm assuming it won't work perfectly across versions?

This goes through Updater.prune which does the required conversions and field set comparisons to handle multi version. I‘ll add more tests to showcase this.

@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 22, 2020

By the way, while you're looking at this code, we should understand and fix the bug with "complex nested types".

Complex types should be handled properly. I’ll add test cases for this too. If there are specific bugs I should be aware of please send them my way.

@apelisse
Copy link
Contributor

This goes through Updater.prune which does the required conversions and field set comparisons to handle multi version. I‘ll add more tests to showcase this.

Awesome yes, I'd be very surprised if this actually works to be honest. Let me think about it for a minute.

@apelisse
Copy link
Contributor

@jpbetz Let me know if I can help you write additional tests!

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 24, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 25, 2020

This goes through Updater.prune which does the required conversions and field set comparisons to handle multi version. I‘ll add more tests to showcase this.

Awesome yes, I'd be very surprised if this actually works to be honest. Let me think about it for a minute.

I spend a while with venn diagrams and couldn't find anything wrong with it. Let me know if you find any problems.

@jpbetz jpbetz force-pushed the remove-unowned-fields branch from cf88031 to ca99bda Compare June 25, 2020 20:04
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 25, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 26, 2020

@jpbetz Let me know if I can help you write additional tests!

I added field unsetting tests for scalar and complex fields. I also added multi version testing with a converter that does field renames to make sure that prune handles multi version apply correctly.

@jpbetz jpbetz force-pushed the remove-unowned-fields branch 2 times, most recently from c8bbc6d to e4fddb1 Compare June 26, 2020 07:18
@jpbetz jpbetz changed the title WIP: Remove fields that are omitted from applied configurations if there are no other owners Remove fields that are omitted from applied configurations if there are no other owners Jun 26, 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 Jun 26, 2020
@apelisse
Copy link
Contributor

I added field unsetting tests for scalar and complex fields. I also added multi version testing with a converter that does field renames to make sure that prune handles multi version apply correctly.

Awesome, I was looking forward to it, and will definitely look closely at that code!

@jpbetz jpbetz force-pushed the remove-unowned-fields branch from e4fddb1 to 1ce4a77 Compare June 26, 2020 16:19
@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 27, 2020

@apelisse I had a look at how defaulting w/r/t this PR.

So it looks like this approach is safe?

@apelisse
Copy link
Contributor

As discussed offline, this is probably because we don't run the conversion (and defaulting) if the version is the same in k8s:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/versionconverter.go#L78-L80.

@jpbetz
Copy link
Contributor Author

jpbetz commented Jun 30, 2020

As discussed offline, this is probably because we don't run the conversion (and defaulting) if the version is the same in k8s:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/versionconverter.go#L78-L80.

I checked and we don't do defaulting when converting across versions either. I've added some test cases to the design doc showing that we get the behavior we want.

I also instrumented a default function and verified that it is not called from within Updater.Apply (in SMD), even when multiple conversions are called from prune, but that it is called from the defaulter.Default call in structuredMergeManager.Apply (in k8s), after Updater.Applycompletes.

E0629 21:07:50.056798    3186 update.go:164] Start Apply
E0629 21:07:50.056903    3186 update.go:229] prune: Converting merged to apiextensions.k8s.io/v1beta1
E0629 21:07:50.057022    3186 update.go:265] addBackOwnedItems: Converting merged to apiextensions.k8s.io/v1
E0629 21:07:50.060735    3186 update.go:273] addBackOwnedItems: Converting pruned to apiextensions.k8s.io/v1
E0629 21:07:50.060894    3186 update.go:298] addBackDanglingItems: Converting pruned to apiextensions.k8s.io/v1beta1
E0629 21:07:50.061051    3186 update.go:247] prune: Converting pruned to apiextensions.k8s.io/v1
E0629 21:07:50.061167    3186 update.go:210] End Apply

If defaulting happens, we would see "setDefaults_CustomResourceDefinitionSpec called" logged in the above output.

Here's the output of defaulter.Default being called (which happens after SMD apply is completed):

E0629 21:07:21.335972    3186 structuredmerge.go:176] Start Calling default
E0629 21:07:21.336211    3186 defaults.go:46] setDefaults_CustomResourceDefinitionSpec called
E0629 21:07:21.336663    3186 defaults.go:46] setDefaults_CustomResourceDefinitionSpec called
E0629 21:07:21.336676    3186 structuredmerge.go:178] End calling default

Co-authored-by: Antoine Pelisse <[email protected]>
@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 Jun 30, 2020
@jpbetz jpbetz force-pushed the remove-unowned-fields branch from 5753bf2 to 9f09075 Compare June 30, 2020 22:31
@jpbetz
Copy link
Contributor Author

jpbetz commented Jul 2, 2020

/hold

k8s CI has been a bit flaky, but existing k8s unit tests and integration are passing for this change (kubernetes/kubernetes#92661). I'm going to remove this hold once I've added a couple of integration tests in k8s that ensure unsetting fields happens as expected for native types, and they are passing.

Feel free to tag this when it looks ready.

@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 2, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Jul 6, 2020

Tests added to kubernetes/kubernetes#92661

/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 Jul 6, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Jul 6, 2020

This is ready to be merged once reviewers are happy with it. I'd like to get it going today if possible so we can bump k8s to use it for 1.19.

Copy link
Contributor

@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

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 6, 2020
@k8s-ci-robot k8s-ci-robot merged commit 43c19bb into kubernetes-sigs:master Jul 6, 2020
This was referenced Mar 25, 2021
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.

3 participants