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

Ensure all group members own the workload [pod groups] #1683

Conversation

mimowo
Copy link
Contributor

@mimowo mimowo commented Feb 5, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

The root cause for the workload removal was that the workload was only owned by the originally created pods, but not replacements. Once the job completes the workload is marked finished, and finalizers from all pods are removed.
Now, the preempted pods (originally created) are getting removed from the API server at this point, and because they are the only owners of the workloads, the workload has no more owners. As a consequence the workload gets removed by the garbage-collector.

This is inconsistent with workloads completing without getting preempted. In that case the originally created pods are not deleted (even though they have their finalizers removed), and thus the workload is not removed.

Which issue(s) this PR fixes:

Fixes #1557

Special notes for your reviewer:

This PR will conflict with #1667 in TestReconcile in pod_controller_test.go, because both add a test case. The other PR introduces asserts on events in the unit test, which will be handy to verify the event introduced in this PR.

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Feb 5, 2024
Copy link

netlify bot commented Feb 5, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit c8fffd9
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/65c21a481a0d6d00088578a7

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 5, 2024
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 5, 2024
@mimowo
Copy link
Contributor Author

mimowo commented Feb 5, 2024

/assign @yaroslava-serdiuk
cc @alculquicondor

@mimowo mimowo changed the title Ensure all group members own the workload Ensure all group members own the workload [pod groups] Feb 5, 2024
@yaroslava-serdiuk
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 Feb 5, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: f29ecfebd83643e59760f1b1f44f7b4910f79c04

BlockOwnerDeletion: &blockDeletion,
},
}
func (w *WorkloadWrapper) OwnerReference(gvk schema.GroupVersionKind, name, uid string, controller, blockDeletion *bool) *WorkloadWrapper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change necessary? This new approach leads to much more code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, I reverted them by keeping the OwnerReference function. For the need of my unit test I now introduce SetOwnerReference and SetControllerReference. These are analogs of the controllerutil functions, which either pass (nil, nil) or (true, true). So now, the changes are scoped to the TestReconcile unit test. If you like this approach I could have a follow up to eliminate the OwnerReference function and replace it with either of the two new functions.

Still, inside this test I add a bunch of "SetOwnerReference" and "SetControllerReference" lines. The alternatives I see:

  1. have an extra param in the unit test like "verifyOwnerReferences" that would (1) skip the code of adding owner references, (2) use another set of cmpopts for the workload.
  2. have a dedicated unit test for this scenario, say TestReconcileWithOwnerReferences
  3. do not add unit tests for owner references

IMO none of the alternatives is tempting. Indeed adding a bunch of lines seems like a lot of code, but easy to understand. WDYT?

pkg/controller/jobs/pod/pod_controller.go Outdated Show resolved Hide resolved
pkg/controller/jobs/pod/pod_controller.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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 needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 5, 2024
@mimowo mimowo force-pushed the fix-workload-deletion-with-unit-tests branch from 574a95e to e160356 Compare February 6, 2024 10:57
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2024
@mimowo mimowo force-pushed the fix-workload-deletion-with-unit-tests branch from e160356 to 0f52368 Compare February 6, 2024 11:08
# Conflicts:
#	pkg/controller/jobframework/interface.go
@mimowo mimowo force-pushed the fix-workload-deletion-with-unit-tests branch from 0f52368 to 312157f Compare February 6, 2024 11:10
Comment on lines 229 to +242
func (w *WorkloadWrapper) OwnerReference(gvk schema.GroupVersionKind, name, uid string, controller, blockDeletion bool) *WorkloadWrapper {
w.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: gvk.GroupVersion().String(),
Kind: gvk.Kind,
Name: name,
UID: types.UID(uid),
Controller: &controller,
BlockOwnerDeletion: &blockDeletion,
},
}
w.appendOwnerReference(gvk, name, uid, ptr.To(controller), ptr.To(blockDeletion))
return w
}

func (w *WorkloadWrapper) SetControllerReference(gvk schema.GroupVersionKind, name, uid string) *WorkloadWrapper {
w.appendOwnerReference(gvk, name, uid, ptr.To(true), ptr.To(true))
return w
}

func (w *WorkloadWrapper) SetOwnerReference(gvk schema.GroupVersionKind, name, uid string) *WorkloadWrapper {
w.appendOwnerReference(gvk, name, uid, nil, nil)
return w
}
Copy link
Contributor

Choose a reason for hiding this comment

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

for a follow up: we should only have OwnerReference and ControllerReference

Copy link
Contributor

@alculquicondor alculquicondor 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 k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7a1292bfcc8bbf49a205835f2e980616ce24a240

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, mimowo

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 Feb 6, 2024
@k8s-ci-robot k8s-ci-robot merged commit 8b4c2e3 into kubernetes-sigs:main Feb 6, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.6 milestone Feb 6, 2024
@mimowo mimowo deleted the fix-workload-deletion-with-unit-tests branch February 10, 2024 11:47
@alculquicondor
Copy link
Contributor

/release-note-edit

NONE

Unreleased feature.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Feb 13, 2024
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. 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-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. 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.

Pod group: Replacement Pods should be added as Workload owners
4 participants