Skip to content

WIP: Make a reciever of FlavorResourceQuantites.For pointer#2689

Closed
tenzen-y wants to merge 1 commit intokubernetes-sigs:mainfrom
tenzen-y:make-flavor-resource-quantities-pointer
Closed

WIP: Make a reciever of FlavorResourceQuantites.For pointer#2689
tenzen-y wants to merge 1 commit intokubernetes-sigs:mainfrom
tenzen-y:make-flavor-resource-quantities-pointer

Conversation

@tenzen-y
Copy link
Copy Markdown
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

For the FlavorResourceQuantities, Add uses the pointer receiver, For uses the non pointer receiver.
But, it would be better to use either a pointer or nonpointer receiver across all functions for the struct.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added 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 Jul 25, 2024
@k8s-ci-robot k8s-ci-robot requested a review from mimowo July 25, 2024 06:01
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tenzen-y

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 requested a review from trasc July 25, 2024 06:01
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 25, 2024
@netlify
Copy link
Copy Markdown

netlify Bot commented Jul 25, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 004ad6c
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/66a209eaa6bb960008e67ca6

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 25, 2024
@gabesaba
Copy link
Copy Markdown
Contributor

Is this an improvement? Since FlavorResourceQuantities is a map type, I don't think we gain anything by using a pointer, and the new code is a less clean - 3 lines instead of 1, and have to deref inside ()

The only reason we used pointer receiver in the Add method is so that it could handle the null map case

@tenzen-y
Copy link
Copy Markdown
Member Author

Is this an improvement? Since FlavorResourceQuantities is a map type, I don't think we gain anything by using a pointer, and the new code is a less clean - 3 lines instead of 1, and have to deref inside ()

That sounds reasonable.

The only reason we used pointer receiver in the Add method is so that it could handle the null map case

If so, shouldn't we use the non pointer f for Add function like the following since map type already pointer type, right?

func (f FlavorResourceQuantities) Add(fr FlavorResource, v int64) {
	if f == nil {
		f = make(FlavorResourceQuantities)
	}
...

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
@tenzen-y tenzen-y force-pushed the make-flavor-resource-quantities-pointer branch from 78b9bff to 004ad6c Compare July 25, 2024 08:16
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 25, 2024
@tenzen-y
Copy link
Copy Markdown
Member Author

tenzen-y commented Jul 25, 2024

Is this an improvement? Since FlavorResourceQuantities is a map type, I don't think we gain anything by using a pointer, and the new code is a less clean - 3 lines instead of 1, and have to deref inside ()

That sounds reasonable.

The only reason we used pointer receiver in the Add method is so that it could handle the null map case

If so, shouldn't we use the non pointer f for Add function like the following since map type already pointer type, right?

func (f FlavorResourceQuantities) Add(fr FlavorResource, v int64) {
	if f == nil {
		f = make(FlavorResourceQuantities)
	}
...

Oh, I found the above code doesn't work well. NVM.

@trasc
Copy link
Copy Markdown
Contributor

trasc commented Jul 25, 2024

Is this an improvement? Since FlavorResourceQuantities is a map type, I don't think we gain anything by using a pointer, and the new code is a less clean - 3 lines instead of 1, and have to deref inside ()

That sounds reasonable.

The only reason we used pointer receiver in the Add method is so that it could handle the null map case

If so, shouldn't we use the non pointer f for Add function like the following since map type already pointer type, right?

func (f FlavorResourceQuantities) Add(fr FlavorResource, v int64) {
	if f == nil {
		f = make(FlavorResourceQuantities)
	}
...

You only change the local f , not the caller.

we can replace the Add method with something like append, and.

f = Append(f, k, v)

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@tenzen-y: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kueue-test-unit-main 004ad6c link true /test pull-kueue-test-unit-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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-sigs/prow repository. I understand the commands that are listed here.

@tenzen-y
Copy link
Copy Markdown
Member Author

tenzen-y commented Jul 25, 2024

Is this an improvement? Since FlavorResourceQuantities is a map type, I don't think we gain anything by using a pointer, and the new code is a less clean - 3 lines instead of 1, and have to deref inside ()

That sounds reasonable.

The only reason we used pointer receiver in the Add method is so that it could handle the null map case

If so, shouldn't we use the non pointer f for Add function like the following since map type already pointer type, right?

func (f FlavorResourceQuantities) Add(fr FlavorResource, v int64) {
	if f == nil {
		f = make(FlavorResourceQuantities)
	}
...

You only change the local f , not the caller.

Yeah, that's right. The reason why failure.

we can replace the Add method with something like append, and.

f = Append(f, k, v)

My motivation was to consistently use either a pointer or non-pointer receiver across all functions for the same struct and avoid the pointer map receiver.
Passing the f instance could work fine, but it may reduce its convenience of it compared with Add.

Let me think another better way...

@tenzen-y tenzen-y changed the title Make a reciever of FlavorResourceQuantites.For pointer WIP: Make a reciever of FlavorResourceQuantites.For pointer Jul 25, 2024
@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 Jul 25, 2024
@tenzen-y tenzen-y marked this pull request as draft July 25, 2024 08:43
@gabesaba
Copy link
Copy Markdown
Contributor

Relevant code is deleted in #2721, so we can close this PR

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 30, 2024
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

PR needs rebase.

Details

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-sigs/prow repository.

@mimowo
Copy link
Copy Markdown
Contributor

mimowo commented Aug 9, 2024

/close
based on #2689 (comment)

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@mimowo: Closed this PR.

Details

In response to this:

/close
based on #2689 (comment)

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-sigs/prow repository.

@tenzen-y tenzen-y deleted the make-flavor-resource-quantities-pointer branch October 7, 2024 16:39
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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants