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

fix: fix pieces of code currently omitted by the linter #1227

Conversation

JasonPowr
Copy link
Contributor

Description

This PR is to Investigate and fix pieces of code currently omitted by the linter, i.e lines that have //nolint
Jira: https://issues.redhat.com/browse/MGDSTRM-900

Checklist (Definition of Done)

  • All acceptance criteria specified in JIRA have been completed
  • Unit and integration tests added that prove the fix is effective or the feature works (tested against emulated and non-emulated OCM environment)
  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer
  • All PR comments are resolved either by addressing them or creating follow up tasks
  • Required metrics/dashboards/alerts have been added (or PR created).
  • Required Standard Operating Procedure (SOP) is added.
  • JIRA has been created for changes required on the client side

@JasonPowr
Copy link
Contributor Author

Most of the //nolint issues are fixed in this PR however there are three that are not.

  1. https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/internal/kafka/test/common/kafka_pollers.go#L67 I’ve looked into this a bit and I believe I am closing the resps body correctly but I am still running into issues with the linter stating that it must be closed.

  2. https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/auth/helper.go#L158 ParseRSAPrivateKeyFromPEMWithPassword() Is Deprecated however the linter is returning this error when it runs:
    jwt.ParseRSAPrivateKeyFromPEMWithPassword is deprecated: This function is deprecated and should not be used anymore. It uses the deprecated x509.DecryptPEMBlock function, which was deprecated since RFC 1423 is regarded insecure by design. Unfortunately, there is no alternative in the Go standard library for now. See https://github.com/golang/go/issues/8860
    So I'm not sure if there is another way around this one.

  3. https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L28 Wasn't sure how to fix this one.

@machi1990
Copy link
Contributor

Thanks @JasonPowr fantastic work.

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/internal/kafka/test/common/kafka_pollers.go#L67 I’ve looked into this a bit and I believe I am closing the resps body correctly but I am still running into issues with the linter stating that it must be closed.

I think this is by design and it's up to the caller to Close the response. @ziccardi is this correct?

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/auth/helper.go#L158 ParseRSAPrivateKeyFromPEMWithPassword() Is Deprecated however the linter is returning this error when it runs:
jwt.ParseRSAPrivateKeyFromPEMWithPassword is deprecated: This function is deprecated and should not be used anymore. It uses the deprecated x509.DecryptPEMBlock function, which was deprecated since RFC 1423 is regarded insecure by design. Unfortunately, there is no alternative in the Go standard library for now. See golang/go#8860
So I'm not sure if there is another way around this one.

This one we need to wait for a drop in replacement implementation to be available or use external libs.
Since it is only used for unit testing, I think we can continue to ignore the deprecated method for linting until we've a replacement.

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L28 Wasn't sure how to fix this one.

For this one, the issue is the string "txid" which is used as key. We need to define a type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L12, the declare the "txid" as of that type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L15 and use it in place.

@ziccardi
Copy link
Contributor

ziccardi commented Aug 5, 2022

Thanks @JasonPowr fantastic work.

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/internal/kafka/test/common/kafka_pollers.go#L67 I’ve looked into this a bit and I believe I am closing the resps body correctly but I am still running into issues with the linter stating that it must be closed.

I think this is by design and it's up to the caller to Close the response. @ziccardi is this correct?

@machi1990 Correct.

Copy link
Contributor

@pawelpaszki pawelpaszki left a comment

Choose a reason for hiding this comment

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

lgtm

@JasonPowr JasonPowr force-pushed the fix-pieces-of-code-currently-omitted-by-the-linter branch from abd04de to c8b7505 Compare August 8, 2022 13:12
@JasonPowr JasonPowr marked this pull request as ready for review August 8, 2022 13:13
@JasonPowr JasonPowr requested review from a team, valdar, dhirajsb and lburgazzoli as code owners August 8, 2022 13:13
@JasonPowr
Copy link
Contributor Author

JasonPowr commented Aug 8, 2022

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L28 Wasn't sure how to fix this one.

For this one, the issue is the string "txid" which is used as key. We need to define a type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L12, the declare the "txid" as of that type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L15 and use it in place.

So I tried to fix this like you said but it still does not seem to work. It fixes the linter Issue all right but seems to break everything else.
@machi1990

@codecov
Copy link

codecov bot commented Aug 8, 2022

Codecov Report

Merging #1227 (de3c8de) into main (e9d79d6) will increase coverage by 0.79%.
The diff coverage is 12.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1227      +/-   ##
==========================================
+ Coverage   82.47%   83.27%   +0.79%     
==========================================
  Files         133      133              
  Lines       11813    11815       +2     
==========================================
+ Hits         9743     9839      +96     
+ Misses       1714     1622      -92     
+ Partials      356      354       -2     
Flag Coverage Δ
unittests 83.27% <12.50%> (+0.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/db/context.go 0.00% <0.00%> (ø)
pkg/api/cluster_types.go 76.66% <100.00%> (-0.20%) ⬇️
internal/kafka/internal/config/kafka.go 53.12% <0.00%> (-0.85%) ⬇️
internal/kafka/internal/config/kafka_quota.go 100.00% <0.00%> (ø)
internal/kafka/internal/services/kafka.go 77.65% <0.00%> (+0.72%) ⬆️
pkg/workers/reconciler_config.go 100.00% <0.00%> (+50.00%) ⬆️
pkg/workers/leader_election_mgr.go 84.00% <0.00%> (+51.20%) ⬆️
pkg/workers/worker_interface.go 100.00% <0.00%> (+100.00%) ⬆️

@machi1990
Copy link
Contributor

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L28 Wasn't sure how to fix this one.

For this one, the issue is the string "txid" which is used as key. We need to define a type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L12, the declare the "txid" as of that type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L15 and use it in place.

So I tried to fix this like you said but it still does not seem to work. It fixes the linter Issue all right but seems to break everything else. @machi1990

@JasonPowr I think we need to change all the other references of txid. There is also a cyclic dependency on the logger.go so we'll need break this cyclic dependency. I can push a follow PR to this or if you are okay I can push a separate commit.

@JasonPowr
Copy link
Contributor Author

https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L28 Wasn't sure how to fix this one.

For this one, the issue is the string "txid" which is used as key. We need to define a type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L12, the declare the "txid" as of that type just like https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/blob/main/pkg/db/context.go#L15 and use it in place.

So I tried to fix this like you said but it still does not seem to work. It fixes the linter Issue all right but seems to break everything else. @machi1990

@JasonPowr I think we need to change all the other references of txid. There is also a cyclic dependency on the logger.go so we'll need break this cyclic dependency. I can push a follow PR to this or if you are okay I can push a separate commit.

Sure yeah work away thanks for the help :)

Also breaks up a cycling dependency issue between context.go and logger.go
@machi1990
Copy link
Contributor

Pushed a commit on top of you change.

Let's see what CI says @JasonPowr , it should be happy :-)

Comment on lines -26 to -28
// adding txid explicitly to context with a simple string key and int value
// due to a cyclical import cycle between pkg/db and pkg/logging
ctx = context.WithValue(ctx, "txid", tx.txid) //nolint
Copy link
Contributor

Choose a reason for hiding this comment

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

@machi1990 machi1990 merged commit 6024feb into bf2fc6cc711aee1a0c2a:main Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants