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

UT: workload marked as finished when job completes #1089

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

alculquicondor
Copy link
Contributor

@alculquicondor alculquicondor commented Aug 30, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Add unit test for marking workloads as finished when a job completes.

The mock client simulates SSA using strategic merge, which only looks at the patchStrategy and not mapType.

Then, this PR also introduces the patchStrategy:"merge". This also allows external controllers or CLIs to do client-side apply, merging two lists of conditions.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Add mergeStrategy:merge to all conditions of API objects

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Aug 30, 2023
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2023
@netlify
Copy link

netlify bot commented Aug 30, 2023

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 55da13a
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/64f230d3935e8e00086c8e15

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 30, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor

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

@alculquicondor alculquicondor changed the title [WIP] UT: workload marked as finished when job completes UT: workload marked as finished when job completes Sep 1, 2023
@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 Sep 1, 2023
@alculquicondor
Copy link
Contributor Author

/assign @tenzen-y

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Sep 1, 2023
Comment on lines +208 to +210
// +patchStrategy=merge
// +patchMergeKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
Copy link
Member

@tenzen-y tenzen-y Sep 1, 2023

Choose a reason for hiding this comment

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

Why do we need these markers to add unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the mock client uses StrategicMerge to implement SSA, which only looks at the patchStrategy, not the mapType.

There is an open issue to fix the mock client to be more like the real apiserver kubernetes/kubernetes#115598

However, in the meantime, @apelisse suggested that I add a patchStrategy. This also gives the ability for external controllers to use client-side apply and easily merge two lists of conditions.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying. I'm a bit confused since IIUC, the StrategicMergePatch can be used only for Client Side Apply (CSA), right?

However, by this PR, the controller uses SSA with StarategicMergePatch to update workload condition:

return c.Status().Patch(ctx, newWl, client.Apply, client.FieldOwner(managerPrefix+"-"+condition.Type))

Which apply strategy will the controller use to update workload conditions? CSA vs SSA
Should we use a customized fake patch client to avoid performance issues instead of adding these markers if CSA is used?

kubernetes-sigs/controller-runtime#2341 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apply means that it will use SSA.
It's only the fake client that implements SSA as it was CSA.

This is enough for our purposes for now.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. So, CSA would be used only when unit tests.
Thanks again.

@tenzen-y
Copy link
Member

tenzen-y commented Sep 4, 2023

UT looks good to me.

@tenzen-y
Copy link
Member

tenzen-y commented Sep 5, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 5, 2023
@k8s-ci-robot k8s-ci-robot merged commit 1a3bcca into kubernetes-sigs:main Sep 5, 2023
15 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.5 milestone Sep 5, 2023
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants