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 fake client deletionTimestamp behavior #2316

Merged
merged 1 commit into from May 17, 2023

Conversation

lleshchi
Copy link
Contributor

@lleshchi lleshchi commented May 10, 2023

Closes #2184

The current fake client methods diverge from the behavior of real k8s. This results in scenarios where an object can be created or modified to have a deletionTimestamp and no finalizers, with a delay in garbage collection, causing inaccurate or ambiguous behavior in test cases that use the fake client.

Bring fake client behavior closer in line with real k8s behavior by modifying the following:

  • Update() and Patch() will reject changes that set a previously-unset deletionTimestamp
  • Create() will ignore a deletionTimestamp on an object
  • Build() will error if initialized with an object that has a deletionTimestamp but no finalizers; but will accept a deletionTimestamp if it has finalizers.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 10, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: lleshchi / name: Leah Leshchinsky (d83c801)

@k8s-ci-robot
Copy link
Contributor

Welcome @lleshchi!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 10, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @lleshchi. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 10, 2023
@vincepri
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 10, 2023
@lleshchi lleshchi force-pushed the deletion_timestamp branch 2 times, most recently from 8522ea3 to eeea5bb Compare May 10, 2023 16:50
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2023
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
@sbueringer sbueringer added this to the v0.15.x milestone May 15, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 15, 2023
@2uasimojo
Copy link
Contributor

This is looking solid to me. One minor query inline. Also, I'm not digging deep into the test cases -- leaving that for the experts :)

pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client_test.go Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Outdated Show resolved Hide resolved
pkg/client/fake/client.go Show resolved Hide resolved
pkg/client/fake/client.go Show resolved Hide resolved
pkg/client/fake/client_test.go Outdated Show resolved Hide resolved
pkg/client/fake/client_test.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

@lleshchi Could it be that you forgot to push the new version? :)

@lleshchi
Copy link
Contributor Author

@sbueringer Was waiting on a clarification from @vincepri regarding one of the review comments. Otherwise, pushing changes now :)

@vincepri
Copy link
Member

Which one? :)

@lleshchi
Copy link
Contributor Author

@vincepri #2316 (comment)

Apologies, I reach out in slack about this. Should have posted here as well

The current fake client methods diverge from the behavior of real k8s.
This results in scenarios where an object can be created or modified to
have a deletionTimestamp and no finalizers, with a delay in garbage
collection, causing inaccurate or ambiguous behavior in  test cases that
use the fake client.

Bring fake client behavior closer in line with real k8s behavior by
modifying the following:
- Update() and Patch() will reject changes that set a previously-unset deletionTimestamp
- Create() will ignore a deletionTimestamp on an object
- Build() will error if initialized with an object that has a deletionTimestamp but no finalizers;
but will accept a deletionTimestamp if it has finalizers.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
@sbueringer
Copy link
Member

Thank you!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 17, 2023
@sbueringer
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lleshchi, sbueringer

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 17, 2023
@k8s-ci-robot k8s-ci-robot merged commit c6570c2 into kubernetes-sigs:main May 17, 2023
9 checks passed
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 10, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 14, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 15, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 15, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 16, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
lleshchi added a commit to lleshchi/hive that referenced this pull request Aug 16, 2023
Rewrite unittests to accommodate changes in controller-runtime
v0.15.0 and create a hive specific scheme.

One such major change involves the behavior of the fake client
deletionTimestamp. The fake client will panic if initialized with an
object that has a DeletionTimestamp and no finalizer, and will
silently ignore a DeletionTimestamp on an object in a Create request,
matching the behavior of the kube-apiserver. Tests have been rewritten
to work with this new behavior.
kubernetes-sigs/controller-runtime#2316

This update also includes a requirement to register a fake client
WithStatusSubresource in order to successfully update the Status
subresource of an object. Due to this change, the helper function
NewFakeClientBuilder() is added to pkg/test/fake to allow for easier
setup of a fake client with the necessary sub-resources.
kubernetes-sigs/controller-runtime#2259

Lastly, a new singleton scheme has been introduced to the codebase.
The hive specific scheme is registered once, with all necessary
packages, and used throughout the codebase, removing the need to specify
unique schemes for each use case, and decreasing the overall amount of
imports.

Signed-off-by: Leah Leshchinsky <lleshchi@redhat.com>
ahmedwaleedmalik added a commit to ahmedwaleedmalik/machine-controller that referenced this pull request Aug 16, 2023
Fake client won't create objects after kubernetes-sigs/controller-runtime#2316 if they have DeletionTimeStamp without finalizers

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
kubermatic-bot pushed a commit to kubermatic/machine-controller that referenced this pull request Aug 17, 2023
* Update k8s APIs to v1.28

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>

* Satisfy fake clients requirement of finalizers with DeletionTimeStamp

Fake client won't create objects after kubernetes-sigs/controller-runtime#2316 if they have DeletionTimeStamp without finalizers

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>

* Revert change in all_e2e_test.go

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>

* Refactored code

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>

---------

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Fake client does not delete objects containing deletion timestamp
5 participants