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

🌱 Update golint-ci, fix warnings #3120

Merged
merged 1 commit into from
Jun 3, 2020

Conversation

benmoss
Copy link

@benmoss benmoss commented May 29, 2020

What this PR does / why we need it:
Bumps golangci-lint. I noticed on #3107 that my editor was giving me some useful lint warnings that aren't being picked up by our CI, so I went to figure out why and discovered we're just a few versions behind.

I am ignoring these three linters since they produce new errors and I'm not sure if we want to fix/enforce them:

  • godot: comments should end in a period
  • goerr113: errors on dynamic error creation via errors.New and fmt.Errorf
  • nestif: errors on deeply nested if statements

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 29, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 29, 2020
controllers/mdutil/util.go Outdated Show resolved Hide resolved
controllers/mdutil/util.go Outdated Show resolved Hide resolved
@@ -47,11 +47,12 @@ func NewFilterableMachineCollection(machines ...*clusterv1.Machine) FilterableMa

// NewFilterableMachineCollectionFromMachineList creates a FilterableMachineCollection from the given MachineList
func NewFilterableMachineCollectionFromMachineList(machineList *clusterv1.MachineList) FilterableMachineCollection {
if machineList == nil {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Should this return a 0 length FilterableMachineCollection here instead of nil? Not sure if there are any downstream effects of doing so.

Copy link
Member

Choose a reason for hiding this comment

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

Was this reported by a linter?

Copy link
Author

Choose a reason for hiding this comment

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

yeah there's a NPE immediately below this if you pass in a nil MachineList

Copy link
Author

Choose a reason for hiding this comment

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

Maybe log.Fatal? I feel like guarding against nil pointers is almost the wrong thing to do, it seems like a programmer error if we're getting a nil as input here.

Copy link
Member

Choose a reason for hiding this comment

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

If before we were throwing a panic, we can do the same here given that we don't return any errors. That said, if we were to remove the pointer, the function should still work like an empty list?

Copy link
Member

Choose a reason for hiding this comment

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

It might be better to add a variable for the initialization size for the make call below, or to initialize it as 0 length. I believe ass this stands today if one were to pass a nil pointer and they tried to use the FilterableMachineCollection returned by this function and later tried to use the Insert method, they would get a panic on Insert.

This should accomplish what looks like the original intent here:

	var initLength int
	if machineList != nil {
		initLength = len(machineList.Items)
	}
	ss := make(FilterableMachineCollection, initLength)

Copy link
Author

@benmoss benmoss Jun 3, 2020

Choose a reason for hiding this comment

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

Turns out if we just remove the nil check that used to happen here the linter doesn't care anymore. This will result in a panic which I still think is the right behavior. I think the intention of the linter is just to show you that if you want to guard against nils, this code was failing to properly do so. If we want to just let it fail (since it's not an actual feature of the code that we want to support passing around nil MachineLists) then we do nothing.

@vincepri
Copy link
Member

vincepri commented May 29, 2020

+1 to updating to the latest version, although I'm not in favor of getting so many changes in while we're in v0.3.x — some of which seem to have side effects or change logic.

Can we scope down the changes to the minimum necessary? Let's add the ignored patterns to the excluded list and open issues to deal with it later.

@fabriziopandini
Copy link
Member

do you have any context on these file permissions ones?

TBH no. Most of them are in test, we can start to get them fixed

@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 Jun 1, 2020
@benmoss
Copy link
Author

benmoss commented Jun 1, 2020

TBH no. Most of them are in test, we can start to get them fixed

Yeah I realized I think we can actually update all of these without any impact on the code, they are just writing files for the tests to consume but I don't the perms need to be as wide as they are.

+1 to updating to the latest version, although I'm not in favor of getting so many changes in while we're in v0.3.x — some of which seem to have side effects or change logic.

Can we scope down the changes to the minimum necessary? Let's add the ignored patterns to the excluded list and open issues to deal with it later.

Which are the minimum necessary? None of these seem like dangerous changes to me. We can also just hold off until after 0.3?

@wfernandes
Copy link
Contributor

@benmoss I do not have much context on the file permissions but I don't see the harm in changing them and making sure they run fine on CI. I'm sure it just started somewhere and then copy-pasta elsewhere.

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/milestone v0.3.7

@benmoss Good work here, last changes look good to me. Can we re-categorize as running given that this isn't a user-facing feature or major change?

@k8s-ci-robot k8s-ci-robot added this to the v0.3.7 milestone Jun 2, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benmoss, vincepri

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 Jun 2, 2020
@benmoss benmoss changed the title ✨ [WIP] Update golint-ci, fix warnings 🌱 Update golint-ci, fix warnings Jun 3, 2020
@wfernandes
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 Jun 3, 2020
@k8s-ci-robot k8s-ci-robot merged commit b9f2389 into kubernetes-sigs:master Jun 3, 2020
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

6 participants