-
Notifications
You must be signed in to change notification settings - Fork 42
CORENET-6500: fix lint job and linting failures #201
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
base: main
Are you sure you want to change the base?
Conversation
there is no lint job for this project so nobody knew that lint issues were creeping in. In fact, golangci-lint was not even working because it was using an old/outdated config. this allows the linter to run, although there are failures to fix Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
|
@jluhrsen: This pull request references CORENET-6500 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this: 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 openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughThe PR renames exported error sentinels to Go-idiomatic names (e.g., Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes ✨ Finishing touches
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jluhrsen The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
the lint job was never there so linting failures have been creeping in over time. This PR[0] in CNCC fixes the job and failures. [0] openshift/cloud-network-config-controller#201 Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
0a2d2db to
dbe388f
Compare
|
/retest-required |
|
@arkadeepsen @pliurh , could you PTAL at this? once we get this in, I have the release PR ready to get the lint job running as a pre-submit and we can use /pj-rehearse on that PR to double check it's ok. |
the lint job was never there so linting failures have been creeping in over time. This PR[0] in CNCC fixes the job and failures. [0] openshift/cloud-network-config-controller#201 Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
| - gofmt | ||
| - errcheck | ||
| - gofmt | ||
| - gosimple | ||
| - govet | ||
| - ineffassign | ||
| - nosprintfhostport | ||
| - staticcheck | ||
| - typecheck | ||
| - unused | ||
| - exportloopref |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are some of the linters removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is moving to v2. here are the details:
gosimpleit's now been merged inside ofstaticcheck(docs)typecheckis no longer a linter (docs)exportlooprefis deprecated entirely (docs)
BUT, thanks for questioning this because I realized that I removed both cases of gofmt. I've updated this PR adding it back, although now it's called a formatter and not a linter. (docs)
| // Because we're dealing with a pointer here for matchingSubnet: | ||
| // we must reassign s:= s or we'd overwrite the content that we point | ||
| // to. | ||
| s := s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use subnetCopy here rater than removing this assignment completely.
| // Because we're dealing with a pointer here for matchingSubnet: | |
| // we must reassign s:= s or we'd overwrite the content that we point | |
| // to. | |
| s := s | |
| // Because we're dealing with a pointer here for matchingSubnet: | |
| // we must reassign subnetCopy := s or we'd overwrite the content that we point | |
| // to. | |
| subnetCopy := s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change explicitly from what I learned by running the v2 linters. these loop variables now have a per-iteration scope so there is no need to make a copy:
https://go.dev/blog/loopvar-preview#the-fix
| workqueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), resourceControllerKey) | ||
| workqueue := workqueue.NewTypedRateLimitingQueueWithConfig( | ||
| workqueue.DefaultTypedControllerRateLimiter[string](), | ||
| workqueue.TypedRateLimitingQueueConfig[string]{ | ||
| Name: resourceControllerKey, | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a lint issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it showed up as a typecheck failure:
pkg/cloudprovider/openstack.go:792:11: undefined: AlreadyExistingIPError) (typecheck)
cloudprovider "github.com/openshift/cloud-network-config-controller/pkg/cloudprovider"
so it's changed to NewTypedRateLimitingQueueWithConfig needing explicit types passed to it.
| err := func(obj interface{}) error { | ||
| err := func(obj string) error { | ||
| // We call Done here so the workqueue knows we have finished | ||
| // processing this item. We also must remember to call Forget if we | ||
| // do not want this work item being re-queued. For example, we do | ||
| // not call Forget if a transient error occurs, instead the item is | ||
| // put back on the workqueue and attempted again after a back-off | ||
| // period. | ||
| defer c.workqueue.Done(obj) | ||
| var key string | ||
| var ok bool | ||
| // We expect strings to come off the workqueue. These are of the | ||
| // form namespace/name. We do this as the delayed nature of the | ||
| // workqueue means the items in the informer cache may actually be | ||
| // more up to date that when the item was initially put onto the | ||
| // workqueue. | ||
| if key, ok = obj.(string); !ok { | ||
| // As the item in the workqueue is actually invalid, we call | ||
| // Forget here else we'd go into a loop of attempting to | ||
| // process a work item that is invalid. | ||
| c.workqueue.Forget(obj) | ||
| klog.Errorf("expected string in %s workqueue but got %#v", c.controllerKey, obj) | ||
| return nil | ||
| } | ||
| // Run the syncHandler, passing it the namespace/name string of the | ||
| // Foo resource to be synced. | ||
| if err := c.SyncHandler(key); err != nil && c.workqueue.NumRequeues(key) <= maxRetries { | ||
| if err := c.SyncHandler(obj); err != nil && c.workqueue.NumRequeues(obj) <= maxRetries { | ||
| // Put the item back on the workqueue to handle any transient errors. | ||
| c.workqueue.AddRateLimited(key) | ||
| return fmt.Errorf("error syncing '%s': %s, requeuing in %s workqueue", key, err.Error(), c.controllerKey) | ||
| c.workqueue.AddRateLimited(obj) | ||
| return fmt.Errorf("error syncing '%s': %s, requeuing in %s workqueue", obj, err.Error(), c.controllerKey) | ||
| } | ||
| // Finally, if no error occurs or if we supersede maxRetries we Forget | ||
| // this item so it does not get queued again until another change happens. | ||
| c.workqueue.Forget(obj) | ||
| klog.Infof("Dropping key '%s' from the %s workqueue", key, c.controllerKey) | ||
| klog.Infof("Dropping key '%s' from the %s workqueue", obj, c.controllerKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to change the implementation logic a little bit. Why is this a lint issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a result of the NewTypedRateLimitingQueueWithConfig expecting strict types now. we no longer have to check if it's a string now, it has to be
dbe388f to
1f72184
Compare
lint failures have creeped in over time because there was no lint
presubmit job to gate them. A job is being created here[0] which
will prevent this creep in the future.
this commit cleans up the existing failures
summary:
- Rename error variables to follow Go convention (ErrFoo instead of FooError)
- Remove duplicate package imports that caused type checking failures
- Update to typed workqueue API (generics-based client-go v0.32+)
- Remove loop variable copies (unnecessary in Go 1.22+)
- Add explicit error ignoring with _ where errors don't matter
- Use keyed struct literal fields for v1.Time initialization
- Simplify embedded field access patterns
[0] openshift/release#73766
Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
1f72184 to
9f72b56
Compare
|
/test e2e-azure-ovn |
1 similar comment
|
/test e2e-azure-ovn |
|
@jluhrsen: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
No description provided.