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

🌱 Enabled more golangci linters #1536

Merged
merged 1 commit into from Feb 9, 2024

Conversation

kashifest
Copy link
Member

@kashifest kashifest commented Feb 1, 2024

These linters still were the low hanging fruits. The rest 5 linters which are currently disabled, are expected to create much more noise and code change and I plan to work on them on a followup.

@metal3-io-bot metal3-io-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 1, 2024
@kashifest
Copy link
Member Author

/hold
Seems some more fixing is needed

@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 1, 2024
@kashifest kashifest force-pushed the enable/gonalangci-linter-2 branch 2 times, most recently from 70a0905 to 61b921d Compare February 2, 2024 10:24
@metal3-io-bot metal3-io-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 2, 2024
@kashifest kashifest force-pushed the enable/gonalangci-linter-2 branch 2 times, most recently from 7cc48c2 to 69d5397 Compare February 2, 2024 12:24
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull

@kashifest
Copy link
Member Author

/test-centos-e2e-integration-main

@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull

return ""
}
return host.Labels[name]
}
Copy link
Member Author

Choose a reason for hiding this comment

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

these two fuctions are unused

type PreprovisioningImageStatus struct {
// imageUrl is the URL from which the built image can be downloaded.
ImageUrl string `json:"imageUrl,omitempty"`
ImageUrl string `json:"imageUrl,omitempty"` //nolint:revive,stylecheck
Copy link
Member Author

Choose a reason for hiding this comment

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

ideally this field name should have been ImageURL as asked by the linters, I was not sure if I should do it here since this will cause an API change. I am up for suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest at least a separate PR for this if the consensus is to change .

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 time being the exclusion is justified IMO.


// kernelUrl is the URL from which the kernel of the image can be downloaded.
// Only makes sense for initrd images.
// +optional
KernelUrl string `json:"kernelUrl,omitempty"`
KernelUrl string `json:"kernelUrl,omitempty"` //nolint:revive,stylecheck
Copy link
Member Author

Choose a reason for hiding this comment

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

ideally this type name should have been KernelURL as asked by the linters, I was not sure if I should do it here since this will cause an API change. I am up for suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

same as above

@@ -85,7 +85,7 @@ func (r actionComplete) Dirty() bool {
// deleteComplete is a result indicating that the deletion action has
// completed, and that the resource has now been deleted.
type deleteComplete struct {
actionComplete
actionComplete //nolint:unused
Copy link
Member Author

Choose a reason for hiding this comment

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

I am a bit unsure about this piece of code and how is it used elsewhere. Hence I suppressed the linter.

func (r *BMCEventSubscriptionReconciler) secretManager(log logr.Logger) secretutils.SecretManager {
return secretutils.NewSecretManager(log, r.Client, r.APIReader)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

unused code


// result.RequeueAfter = deprovisionRequeueDelay
p.log.Info("deprovisioning host")
return result, nil
Copy link
Member Author

@kashifest kashifest Feb 2, 2024

Choose a reason for hiding this comment

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

I was not sure how to get rid of this default switch-case only issue, hence I am putting a log message. Open for discussion/suggestions.

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 really get why was this a switch case to begin with...

Copy link
Member

Choose a reason for hiding this comment

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

Is there any significance of accessing the p.objectMeta.Name field, could that have some effect? (I think no but maybe there is some GO magic that I am no considering)

Copy link
Member Author

Choose a reason for hiding this comment

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

me neither and I am not sure if theres any go magic.

Copy link
Member

Choose a reason for hiding this comment

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

This is for the "demo" provisioner, so it was probably meant as a way for developers to play with it. You could add specific cases for what you wanted to happen to the hosts. This is also why there is commented out code below. Just a simple way to make it do different things.
That said, I think we can safely remove it, otherwise it will just rot

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 think it was just copy-and-paste.
(The purpose of the demo provisioner was to test a web UI, by allowing you to create a host that would sit in a certain state. The state it ended up in was determined by the host name.)


// return result, nil
p.log.Info("powering on host")
return result, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

I was not sure how to get rid of this default case only issue, hence I am putting a log message, open for discussion.

Copy link
Member

Choose a reason for hiding this comment

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

same as above


// return result, nil
p.log.Info("powering off host")
return result, nil
Copy link
Member Author

Choose a reason for hiding this comment

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

I was not sure how to get rid of this default case only issue, hence I am putting a log message, open for discussion.

Copy link
Member

Choose a reason for hiding this comment

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

same as above

pkg/provisioner/ironic/testserver/server.go Outdated Show resolved Hide resolved
@metal3-io-bot metal3-io-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 2, 2024
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull
/test-centos-e2e-integration-main

@kashifest
Copy link
Member Author

@kashifest
Copy link
Member Author

/hold cancel

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 2, 2024
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull

1 similar comment
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull

Copy link
Member

@Rozzii Rozzii left a comment

Choose a reason for hiding this comment

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

just few questions and comments in general great work!

type PreprovisioningImageStatus struct {
// imageUrl is the URL from which the built image can be downloaded.
ImageUrl string `json:"imageUrl,omitempty"`
ImageUrl string `json:"imageUrl,omitempty"` //nolint:revive,stylecheck
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest at least a separate PR for this if the consensus is to change .

type PreprovisioningImageStatus struct {
// imageUrl is the URL from which the built image can be downloaded.
ImageUrl string `json:"imageUrl,omitempty"`
ImageUrl string `json:"imageUrl,omitempty"` //nolint:revive,stylecheck
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 time being the exclusion is justified IMO.


// kernelUrl is the URL from which the kernel of the image can be downloaded.
// Only makes sense for initrd images.
// +optional
KernelUrl string `json:"kernelUrl,omitempty"`
KernelUrl string `json:"kernelUrl,omitempty"` //nolint:revive,stylecheck
Copy link
Member

Choose a reason for hiding this comment

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

same as above

cmd/make-virt-host/main.go Show resolved Hide resolved
cmd/make-virt-host/main.go Show resolved Hide resolved

// return result, nil
p.log.Info("powering on host")
return result, nil
Copy link
Member

Choose a reason for hiding this comment

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

same as above


// return result, nil
p.log.Info("powering off host")
return result, nil
Copy link
Member

Choose a reason for hiding this comment

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

same as above

pkg/provisioner/ironic/testserver/ironic.go Show resolved Hide resolved
test/e2e/bmc.go Show resolved Hide resolved

// result.RequeueAfter = deprovisionRequeueDelay
p.log.Info("deprovisioning host")
return result, nil
Copy link
Member

Choose a reason for hiding this comment

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

Is there any significance of accessing the p.objectMeta.Name field, could that have some effect? (I think no but maybe there is some GO magic that I am no considering)

Copy link
Member

@zaneb zaneb left a comment

Choose a reason for hiding this comment

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

Thanks so much for doing this!

pkg/provisioner/demo/demo.go Outdated Show resolved Hide resolved

// result.RequeueAfter = deprovisionRequeueDelay
p.log.Info("deprovisioning host")
return result, nil
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 think it was just copy-and-paste.
(The purpose of the demo provisioner was to test a web UI, by allowing you to create a host that would sit in a certain state. The state it ended up in was determined by the host name.)

controllers/metal3.io/baremetalhost_controller.go Outdated Show resolved Hide resolved
@metal3-io-bot metal3-io-bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 7, 2024
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull
/test-centos-e2e-integration-main

Copy link
Member

@zaneb zaneb left a comment

Choose a reason for hiding this comment

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

/approve

apis/metal3.io/v1alpha1/baremetalhost_types.go Outdated Show resolved Hide resolved
@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zaneb

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

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 7, 2024
@kashifest kashifest force-pushed the enable/gonalangci-linter-2 branch 2 times, most recently from 7b306ef to 48cae68 Compare February 7, 2024 07:24
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull
/test-centos-e2e-integration-main

1 similar comment
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull
/test-centos-e2e-integration-main

Signed-off-by: Kashif Khan <kashif.khan@est.tech>
@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull
/test-centos-e2e-integration-main

@kashifest
Copy link
Member Author

/test metal3-bmo-e2e-test-pull

@kashifest
Copy link
Member Author

/cc @tuminoid @lentzi90

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2024
@metal3-io-bot metal3-io-bot merged commit f06b87b into metal3-io:main Feb 9, 2024
20 checks passed
@metal3-io-bot metal3-io-bot deleted the enable/gonalangci-linter-2 branch February 9, 2024 07:51
@kashifest
Copy link
Member Author

/cherry-pick release-0.5

@metal3-io-bot
Copy link
Contributor

@kashifest: #1536 failed to apply on top of branch "release-0.5":

Applying: Enabled more golangci linters
Using index info to reconstruct a base tree...
M	Makefile
A	apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go
A	apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go
A	config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml
M	config/render/capm3.yaml
A	test/e2e/bmc.go
M	test/e2e/common.go
M	test/e2e/e2e_suite_test.go
M	test/e2e/live_iso_test.go
M	test/e2e/provisioning_and_annotation_test.go
Falling back to patching base and 3-way merge...
Auto-merging test/e2e/provisioning_and_annotation_test.go
CONFLICT (content): Merge conflict in test/e2e/provisioning_and_annotation_test.go
Auto-merging test/e2e/live_iso_test.go
CONFLICT (content): Merge conflict in test/e2e/live_iso_test.go
Auto-merging test/e2e/e2e_suite_test.go
CONFLICT (content): Merge conflict in test/e2e/e2e_suite_test.go
Auto-merging test/e2e/common.go
CONFLICT (modify/delete): test/e2e/bmc.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of test/e2e/bmc.go left in tree.
Auto-merging config/render/capm3.yaml
CONFLICT (modify/delete): config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml left in tree.
CONFLICT (modify/delete): apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go left in tree.
CONFLICT (modify/delete): apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go left in tree.
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Enabled more golangci linters
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-0.5

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/test-infra repository.

@kashifest
Copy link
Member Author

/cherry-pick release-0.5

@metal3-io-bot
Copy link
Contributor

@kashifest: #1536 failed to apply on top of branch "release-0.5":

Applying: Enabled more golangci linters
Using index info to reconstruct a base tree...
M	Makefile
A	apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go
A	apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go
A	config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml
M	config/render/capm3.yaml
A	test/e2e/bmc.go
M	test/e2e/common.go
M	test/e2e/e2e_suite_test.go
M	test/e2e/live_iso_test.go
M	test/e2e/provisioning_and_annotation_test.go
Falling back to patching base and 3-way merge...
Auto-merging test/e2e/provisioning_and_annotation_test.go
CONFLICT (content): Merge conflict in test/e2e/provisioning_and_annotation_test.go
Auto-merging test/e2e/live_iso_test.go
CONFLICT (content): Merge conflict in test/e2e/live_iso_test.go
Auto-merging test/e2e/e2e_suite_test.go
CONFLICT (content): Merge conflict in test/e2e/e2e_suite_test.go
Auto-merging test/e2e/common.go
CONFLICT (modify/delete): test/e2e/bmc.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of test/e2e/bmc.go left in tree.
Auto-merging config/render/capm3.yaml
CONFLICT (modify/delete): config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of config/base/crds/bases/metal3.io_hostfirmwarecomponents.yaml left in tree.
CONFLICT (modify/delete): apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of apis/metal3.io/v1alpha1/hostfirmwarecomponents_types_test.go left in tree.
CONFLICT (modify/delete): apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go deleted in HEAD and modified in Enabled more golangci linters. Version Enabled more golangci linters of apis/metal3.io/v1alpha1/hostfirmwarecomponents_types.go left in tree.
Auto-merging Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Enabled more golangci linters
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-0.5

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/test-infra repository.

@@ -89,9 +88,8 @@ func (a *iLOAccessDetails) BIOSInterface() string {
func (a *iLOAccessDetails) BootInterface() string {
if a.useVirtualMedia {
return "ilo-virtual-media"
Copy link
Member

Choose a reason for hiding this comment

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

Why not constants here?

@@ -8,7 +8,7 @@ import (

func init() {
schemes := []string{"http", "https"}
RegisterFactory("redfish", newRedfishAccessDetails, schemes)
RegisterFactory(redfish, newRedfishAccessDetails, schemes)
RegisterFactory("ilo5-redfish", newRedfishAccessDetails, schemes)
RegisterFactory("idrac-redfish", newRedfishiDracAccessDetails, schemes)
Copy link
Member

Choose a reason for hiding this comment

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

Same question, it's weird to have one thing as a constant and the two other as plain strings.

Copy link
Member

Choose a reason for hiding this comment

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

I'm going to guess it is because the linter complains only after you have N occurrences of the same string.

Copy link
Member Author

Choose a reason for hiding this comment

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

I only fixed those where the linter was unhappy. And linter usually complain when there is around 3 or more mention of the same string.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, understood. Still, I'd prefer us to use constants consistently, regardless of what the linter forces us to.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I will send a patch

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. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants