Solve G115 Linter Errors #4193
Hi @HoustonBoston. Thanks for your PR.
PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.
I understand the commands that are listed here.
<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.
</details>
/test all

coverage: 49.807% (-0.05%) from 49.859% — HoustonBoston:fix-g115-linting into kubevirt:main
/test all
/test pull-containerized-data-importer-e2e-s390x
/cc
Thanks for tackling this!
We're definitely going to keep nolints on some specific cases, but I was wondering if we
could get rid of the nolints where the value is known to be non-negative by domain (lengths, sizes, offsets)?
Here's a reference to a large project enabling G115 that may help - https://github.com/elastic/cloud-on-k8s/pull/9302
/test pull-containerized-data-importer-e2e-ceph
Approved these changes.
do you still need the nolint? that's weird
shouldn't we tackle this properly instead of nolint? i.e. ensure that both individually and their product does not overflow?
i think we can avoid the nolint here too by performing checks on n
thanks! some thoughts plus I think some of the nolints are not needed post your changes, did you try removing them?
Pull requests that are marked with lgtm should receive a review
from an approver within 1 week.
After that period the bot marks them with the label needs-approver-review.
/label needs-approver-review
Yeah, it's pretty bizarre it's still needed
this reads a little worse than avail * bsize > maxint, no?
I think we should just error out for all those funky cases instead of returning maxint
does this check not eliminate the need for the nolint below?
i honestly dont mind keeping nolints on the vddk/imageio data source - mainly curious about nolint being needed. so just file.go comments really🙏
What number should I return and what should the error be?
Doesn't the multiplication cause overflow though?
yes it does!
/retest-required
right
I think you need this guard later on when converting back (copyrange)
the current revision looks ok to me
Added it back at the end of the function
any reason to not check it at the top? before storing?
/approve
thank you!
/cc @dsanatar
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/kubevirt/containerized-data-importer/pull/4193#pullrequestreview-5077200054" title="Approved">akalenyu</a>
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
</details>
<!-- META={"approvers":[]} -->
I don't really understand the value of removing the G115 linter exception from the global rule file if we are just going to add the exception back at each impacted line.
I did some research and apparently for older versions of the golangci-lint package (like the one we are using in cdi) is more strict and produces more false positives for type conversions. I think the linter engine expects these type conversions to occur within the conditional that asserts that the conversion will be safe. I would suggest trying that to see if you can then remove the nolint comments. alternatively, perhaps a package bump could also resolve some of these
do we need to take the minimum here? it makes the second part of the conditional always true. seems like we can drop one of the two.
also if the the passed in verbosityLevel is negative, this check fails and we default to 0 which is different from the previously defined defVerbose which is 1
same comments apply from the controller block
does it still throw a linting error if we just changed this to an else block since it's the direct inverse of the previous check?
this line would never be hit, if it's larger than the max int64 it would be caught in the prior conditional
seems like Bsize is already of type int64, do we need this?
can this be an else?
is this all even necessary? the fields used to be be int64s before your updates, is there a good reason they should now be uint64s to justify all these extra conditionals just to convert them back into int64s?
also curious about this choice, seems related to my previous comment in imageio-datasource
just have some general questions about some changes you made to certain types in some struct fields but then are seemingly writing guards to allow for converting them back to their original type?
this should probably get another round of reviews from an approver before it can be merged since there have been a lot of new changes since the prior approval from @awels
/hold
Nope :smile:
Questionable, but AI says it's different on each platform... maybe input from someone who's well-versed with this is required?
ah ok I see this is from a golang pkg which does seem to vary by platform, I thought this was a structure we defined.
is there a reason this check and conversion of offset was moved from the beginning of the function? I don't think we need this check for ever iteration of the loop since it won't change
if u leave convert the offset value at the beginning, you can remove this check and conversion for length
do we need this guard if we aren't doing any type conversion?
change to else?
looks a lot cleaner, just some extra things I noticed
/retest-required
/unhold
@HoustonBoston: 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-containerized-data-importer-e2e-s390x | 81a97e68675dcaeea0b88b667c7a57a50adabbd9 | link | false | /test pull-containerized-data-importer-e2e-s390x
<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.
</details>
<!-- test report -->
Approved these changes.
/remove-label needs-approver-review
awels
HoustonBoston
<!-- Thanks for sending a pull request! Here are some tips for you:
1. Follow the instructions for writing a release note from k8s: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
What this PR does / why we need it:
Rather than excluding G115 for linting globally, this fix evaluates type conversions on a case-by-case basis, changing types of variables and completely ignoring the integer conversion where applicable so that linting succeeds.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #3656.
Special notes for your reviewer:
Release note:
<!-- Write your release note:
1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
2. If no release note is required, just write "NONE".
-->
``
release-note
``NONE