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

Use ReadUIntFromLabel to validate index label. #3666

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mbobrovskyi
Copy link
Contributor

@mbobrovskyi mbobrovskyi commented Nov 27, 2024

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Use ReadUIntFromLabel to validate index label.

Which issue(s) this PR fixes:

Fixes #3651

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 Nov 27, 2024
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 27, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mbobrovskyi
Once this PR has been reviewed and has the lgtm label, please assign kerthcet for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 27, 2024
Copy link

netlify bot commented Nov 27, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit 1680a2a
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/67476a0a1ec19800084dc889

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 27, 2024
@mbobrovskyi mbobrovskyi marked this pull request as draft November 27, 2024 09:50
@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 Nov 27, 2024
pkg/util/pod/pod.go Outdated Show resolved Hide resolved
pkg/util/pod/pod.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 27, 2024
@mbobrovskyi mbobrovskyi marked this pull request as ready for review November 27, 2024 11:02
@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 Nov 27, 2024
@mbobrovskyi mbobrovskyi force-pushed the cleanup/read-uint-from-label branch 2 times, most recently from 1141ea5 to 463b739 Compare November 27, 2024 11:12
@mbobrovskyi
Copy link
Contributor Author

/cc @mimowo

func readUIntFromStringWithMax(value string, max int) (*int, error) {
uintValue, err := strconv.ParseUint(value, 10, 0)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, maybe we could re-package the error into errInvalidInt so that it is easier to assert?

IIUC this could work: return nil, fmt.Sprintf("%w, message: %v", errInvalidInt, err.Error()), then we could assert on errInvalidInt rather than strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @PBundyra as it may impact also your approach to testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@mimowo mimowo Nov 27, 2024

Choose a reason for hiding this comment

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

Can you check if return nil, fmt.Sprintf("%w, message: %s", errInvalidInt, err.Error()) works? I think it might be useful to get contextual information.

Copy link
Contributor

@mimowo mimowo left a comment

Choose a reason for hiding this comment

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

Overall lgtm, proposing some improvements to usability of the new functions

pkg/controller/tas/topology_ungater.go Outdated Show resolved Hide resolved
pkg/controller/tas/topology_ungater.go Outdated Show resolved Hide resolved
pkg/util/pod/pod.go Outdated Show resolved Hide resolved
pkg/util/pod/pod.go Outdated Show resolved Hide resolved
@mbobrovskyi mbobrovskyi force-pushed the cleanup/read-uint-from-label branch 2 times, most recently from ceda57f to 6c30cf2 Compare November 27, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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.

TAS: Validate that the pod's index in the topology ungater falls within the expected range
4 participants