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 golangci-lint, add more linters #1267

Merged
merged 1 commit into from
Jan 13, 2020

Conversation

aLekSer
Copy link
Collaborator

@aLekSer aLekSer commented Jan 10, 2020

Fix minor issues, but plenty of them. Add new linters.
Add pointers when it is necessary for the sake of performance (avoid coping structures over 512 B in size).
Most fixes come from gocritic linter.
https://go-critic.github.io/overview.html

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: fe238fe9-c5ea-4282-8699-3d0e44f90102

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 363b095d-97cc-4fe5-8cd5-12b42f6faffd

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1267/head:pr_1267 && git checkout pr_1267
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-6f37730

@aLekSer aLekSer marked this pull request as ready for review January 10, 2020 14:09
Copy link
Member

@roberthbailey roberthbailey left a comment

Choose a reason for hiding this comment

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

The only change I'm not sure about is adding in named return values (which I generally try to avoid). This happened in a couple of files (but not in a bunch of other places) so I can't tell what heuristic is being used to suggest the changes.

@@ -212,21 +212,21 @@ func newServiceHandler(kubeClient kubernetes.Interface, agonesClient versioned.I
}

// Set up our client which we will use to call the API
func getClients() (*kubernetes.Clientset, *versioned.Clientset, error) {
func getClients() (kubeClient *kubernetes.Clientset, agonesClient *versioned.Clientset, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the suggested changes to this function; the old way looks more correct to me stylistically. Do you know which check triggered this?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm not a fan of named return variables either.

Copy link
Collaborator Author

@aLekSer aLekSer Jan 11, 2020

Choose a reason for hiding this comment

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

I think the idea behind this check was to make function signature more readable from the first line, especially when it returns same 3 types for instance, which can be misleading without names.
But as we have 3 votes to not use them I will disable unnamedResult and update the PR.

- performance
- opinionated
- diagnostic
disabled-checks:
Copy link
Member

Choose a reason for hiding this comment

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

Did these checks produce too many diffs or did they produce diffs that you didn't agree with?

Copy link
Collaborator Author

@aLekSer aLekSer Jan 11, 2020

Choose a reason for hiding this comment

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

Most of the changes was from test helper functions, that's why I have added:

      rangeValCopy:
        sizeThreshold: 512

to filter them a bit, and to split the changes into 2 PRs also, but I can include these changes here.
For instance, I don't like paramTypeCombine, especially in this case:

pkg/gameservers/controller.go:91:1: paramTypeCombine: func(
        wh *webhooks.WebHook,
        health healthcheck.Handler,
        minPort, maxPort int32,
        sidecarImage string,
        alwaysPullSidecarImage bool,
        sidecarCPURequest resource.Quantity,
        sidecarCPULimit resource.Quantity,
        sdkServiceAccount string,
        kubeClient kubernetes.Interface,
        kubeInformerFactory informers.SharedInformerFactory,
        extClient extclientset.Interface,
        agonesClient versioned.Interface,
        agonesInformerFactory externalversions.SharedInformerFactory) *Controller could be replaced with func(wh *webhooks.WebHook,
        health healthcheck.Handler,
        minPort, maxPort int32,
        sidecarImage string,
        alwaysPullSidecarImage bool,
        sidecarCPURequest,
        sidecarCPULimit resource.Quantity,

        sdkServiceAccount string,
        kubeClient kubernetes.Interface,
        kubeInformerFactory informers.SharedInformerFactory,
        extClient extclientset.Interface,
        agonesClient versioned.Interface,
        agonesInformerFactory externalversions.SharedInformerFactory) *Controller (gocritic)

Seems it just combined sidecarCPURequest, sidecarCPULimit resource.Quantity,, but I can add this check also if it is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sloppyReassign example:

pkg/gameservers/controller.go:389:5: sloppyReassign: re-assignment to `err` can be replaced with `err := c.syncGameServerShutdownState(gs)` (gocritic)
        if err = c.syncGameServerShutdownState(gs); err != nil {

Copy link
Member

Choose a reason for hiding this comment

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

For the paramTypeCombine check, the common suggestion I've heard is that when parameter lists get that long you should create a struct and pass the struct instead of a list of individual parameters. The reason being that it adds better type checking, and when the parameter list gets long it becomes easy to pass things in the wrong order, especially if parameters have the same type. This check seems to make that worse, so I agree that we shouldn't enable it.

The change in sloppyReassign looks correct to me.

@roberthbailey roberthbailey self-assigned this Jan 10, 2020
@aLekSer aLekSer force-pushed the update-golangci-lint branch 2 times, most recently from 8682e06 to 644935d Compare January 11, 2020 09:55
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 064f2294-b852-4371-b7b3-1c7b3f0bf93f

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: fe688c0b-22cf-4af7-8fc9-9d475f0075c7

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@aLekSer aLekSer force-pushed the update-golangci-lint branch 2 times, most recently from f1bc763 to cb01d82 Compare January 11, 2020 10:19
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: b999bdd2-b381-450e-b99b-42bb60dbfa86

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: cad4e15f-ac27-49b8-b5de-464334492120

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1267/head:pr_1267 && git checkout pr_1267
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-cb01d82

@aLekSer
Copy link
Collaborator Author

aLekSer commented Jan 11, 2020

Some error on TestAllocatorCrossNamespace E2E:

Step #21: allocator_test.go:210: failed to unmarshall response body:
 Post https://34.82.102.232/v1alpha1/gameserverallocation:
 remote error: tls: bad certificate

https://gist.github.com/aLekSer/87c8f03ce7af07063866f994f30bad2f

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: eff681ad-c1ee-4ec4-964e-d170dc78acaf

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1267/head:pr_1267 && git checkout pr_1267
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-f65c6e8

cmd/allocator/main.go Outdated Show resolved Hide resolved
test/e2e/allocator_test.go Outdated Show resolved Hide resolved
test/e2e/allocator_test.go Outdated Show resolved Hide resolved
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a5a6372f-7234-4bcd-8e8b-64a489d04201

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1267/head:pr_1267 && git checkout pr_1267
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-1a3c089

Fix minor issues, but plenty of them. Add new linters.
Most changes come from gocritic. Performance was optimised for changing
copy of big structures like GameServerSpec into to using a pointer.
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: f65a7360-13c7-42d0-bae8-6f45626e82c3

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1267/head:pr_1267 && git checkout pr_1267
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-816fc1d

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aLekSer, roberthbailey

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

@roberthbailey roberthbailey merged commit c1ba572 into googleforgames:master Jan 13, 2020
@markmandel markmandel added this to the 1.3.0 milestone Jan 14, 2020
@markmandel markmandel added area/build-tools Development tooling. I.e. pretty much everything in the `build` directory. kind/cleanup Refactoring code, fixing up documentation, etc labels Jan 14, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Fix minor issues, but plenty of them. Add new linters.
Most changes come from gocritic. Performance was optimised for changing
copy of big structures like GameServerSpec into to using a pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/build-tools Development tooling. I.e. pretty much everything in the `build` directory. kind/cleanup Refactoring code, fixing up documentation, etc lgtm size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants