Skip to content

Lint Fixes#14

Open
hsri-pf9 wants to merge 11 commits intoprivate/pf9-oidc/harsh/lintfrom
private/harsh/lint-fix
Open

Lint Fixes#14
hsri-pf9 wants to merge 11 commits intoprivate/pf9-oidc/harsh/lintfrom
private/harsh/lint-fix

Conversation

@hsri-pf9
Copy link
Collaborator

@hsri-pf9 hsri-pf9 commented Aug 19, 2025

Stacked on PR #13

Summary by Bito

This pull request implements comprehensive lint fixes and code modernization throughout the codebase. It replaces deprecated functions and dot imports with explicit ginkgo and gomega calls, while updating outdated I/O operations with modern alternatives. The changes enhance error handling, resource management, and test reliability across build scripts and core proxy functionalities.

@hsri-pf9 hsri-pf9 requested a review from a team August 19, 2025 13:59
@bito-code-review
Copy link

bito-code-review bot commented Aug 19, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Code Modernization and Lint Fixes

Makefile - Updated dependency management, download commands, and lint configuration to replace deprecated methods with modern alternatives.

options.go - Improved logging and error handling by switching to more robust output functions.

context.go - Replaced deprecated context functions with genericapirequest methods for consistent and clearer context propagation.

handlers.go - Updated authentication user references and error handling to align with modern standards.

namespace_round_tripper.go - Replaced ioutil with io and improved resource management using deferred closures for file and watcher operations.

proxy.go - Modernized error messages and replaced outdated I/O functions with os and io, enhancing code reliability.

port.go - Improved port retrieval logic with better resource cleanup using inline deferred function calls.

image.go - Refactored temporary directory creation and file reading using os functions for better resource management.

kind.go - Enhanced error checking and updated node/pod readiness polling with context timeouts and proper resource closures.

sink.go - Updated file reading and deferred resource closure to ensure robust audit logging operations.

server.go - Replaced deprecated ioutil calls with io and os functions, ensuring graceful error handling in server operations.

issuer.go - Refined file reading and managed deferred closures to improve issuer initialization flows.

tls.go - Optimized temporary directory creation, file writing, and cleanup with modern os functions for enhanced TLS setup.

Testing - Enhanced Testing Practices

proxy_test.go - Replaced ioutil calls with io functions to streamline test performance.

subjectaccessreview_test.go - Adjusted impersonation header verification logic to improve test accuracy.

framework.go - Updated testing scripts to use explicit ginkgo and gomega calls, enhancing clarity and consistency in test execution.

poll.go - Refined polling mechanisms by incorporating context timeouts and improved error handling in deployment and pod readiness checks.

requester.go - Modernized HTTP body reading by replacing deprecated ioutil usage with io.ReadAll.

secrets.go - Updated service account token request configuration to align with newer Kubernetes standards.

util.go - Updated e2e framework utility to use context-based polling for namespace existence checks.

audit.go - Refactored audit tests to use explicit ginkgo/gomega calls for better clarity.

headers.go - Updated header tests with explicit ginkgo/gomega calls and improved error assertions.

impersonation.go - Modernized impersonation tests using explicit ginkgo/gomega for improved error handling.

passthrough.go - Replaced dot imports and updated assertion functions to use explicit ginkgo and gomega calls.

probe.go - Updated import style and unified test setup calls with explicit ginkgo/gomega usage.

rbac.go - Refactored RBAC tests to use explicit ginkgo/gomega calls for improved error handling and clarity.

token.go - Modernized token tests by replacing dot imports and updating error assertions with gomega.

upgrade.go - Enhanced upgrade tests by modernizing ginkgo/gomega calls for better error handling and reliability.

suite.go - Modernized Ginkgo function declarations and improved suite setup with explicit and context-aware initialization.

Copy link

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #894caf

Actionable Suggestions - 1
  • test/e2e/framework/helper/poll.go - 1
    • Network connection not properly closed on error · Line 134-142
Additional Suggestions - 7
  • test/e2e/suite/cases/upgrade/upgrade.go - 1
    • Using context.TODO() instead of proper context · Line 135-135
      The code is replacing `exec.Stream(sopt)` with `exec.StreamWithContext(context.TODO(), sopt)` which is good, but using `context.TODO()` is not ideal. Consider using a proper context from the test function or creating one with timeout.
      Code suggestion
       @@ -134,2 +134,3 @@
        		ginkgo.By("Running exec into pod and runing curl on local host")
      -		err = exec.StreamWithContext(context.TODO(), sopt)
      +		ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
      +		defer cancel()
      +		err = exec.StreamWithContext(ctx, sopt)
  • test/e2e/framework/util.go - 1
    • Incorrect context type for long-running operation · Line 39-46
      The `ctx` variable is created with `context.TODO()` but should use `context.Background()` for long-running operations like polling. `TODO()` is intended for temporary placeholders during development.
      Code suggestion
       @@ -39,1 +39,1 @@
      -	ctx := context.TODO()
      +	ctx := context.Background()
  • test/e2e/suite/cases/impersonation/impersonation.go - 1
    • Semantic duplication in ginkgo/gomega import aliases · Line 9-10
      Removing dot imports (`.`) but still using the same package names creates semantic duplication. The code now has both `ginkgo` and `gomega` as explicit imports but still uses them with the same names in the code.
      Code suggestion
       @@ -9,2 +9,2 @@
      -	ginkgo "github.com/onsi/ginkgo"
      -	gomega "github.com/onsi/gomega"
      +	g "github.com/onsi/ginkgo"
      +	o "github.com/onsi/gomega"
  • test/e2e/framework/helper/poll.go - 2
    • Redundant timeout in polling function call · Line 22-25
      The code creates a context with timeout and then passes the same timeout to `PollUntilContextTimeout`, which is redundant. The context already has the timeout, so passing it again to the polling function is unnecessary.
      Code suggestion
       @@ -22,5 +22,5 @@
        	ctx, cancel := context.WithTimeout(context.Background(), timeout)
        	defer cancel()
       
      -	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
      +	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, 0, true, func(ctx context.Context) (bool, error) {
    • Redundant timeout in pod ready polling function · Line 49-52
      Same redundant timeout issue in `WaitForPodReady` function. The context already has a timeout, so passing the same timeout to `PollUntilContextTimeout` is unnecessary.
      Code suggestion
       @@ -49,5 +49,5 @@
        	ctx, cancel := context.WithTimeout(context.Background(), timeout)
        	defer cancel()
       
      -	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
      +	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, 0, true, func(ctx context.Context) (bool, error) {
  • test/kind/kind.go - 2
    • Redundant timeout in PollUntilContextTimeout function call · Line 221-225
      The code creates a context with timeout but then also passes a timeout duration to `PollUntilContextTimeout`. This creates redundant timeout mechanisms as the function already uses the context timeout.
      Code suggestion
       @@ -221,5 +221,5 @@
      -	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
      -	defer cancel()
      -
      -	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
      +	ctx := context.Background()
      +
      +
      +	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
    • Redundant timeout in context and poll function · Line 265-269
      The code creates a context with timeout but then also passes a separate timeout to `PollUntilContextTimeout`. This creates redundant timeout mechanisms as the context timeout and poll timeout are both set to 10 minutes.
      Code suggestion
       @@ -265,7 +265,7 @@ func (k *Kind) waitForPodsReady(namespace, labelSelector string) error {
        	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
        	defer cancel()
       
      -	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
      +	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 0, true, func(ctx context.Context) (bool, error) {
        		pods, err := k.client.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
        			LabelSelector: labelSelector,
        		})
Review Details
  • Files reviewed - 28 · Commit Range: 52e37bc..a34776e
    • cmd/app/options/options.go
    • pkg/proxy/context/context.go
    • pkg/proxy/handlers.go
    • pkg/proxy/namespace_round_tripper.go
    • pkg/proxy/proxy.go
    • pkg/proxy/proxy_test.go
    • pkg/proxy/subjectaccessreview/subjectaccessreview_test.go
    • pkg/util/port.go
    • test/e2e/framework/framework.go
    • test/e2e/framework/helper/poll.go
    • test/e2e/framework/helper/requester.go
    • test/e2e/framework/helper/secrets.go
    • test/e2e/framework/util.go
    • test/e2e/suite/cases/audit/audit.go
    • test/e2e/suite/cases/headers/headers.go
    • test/e2e/suite/cases/impersonation/impersonation.go
    • test/e2e/suite/cases/passthrough/passthrough.go
    • test/e2e/suite/cases/probe/probe.go
    • test/e2e/suite/cases/rbac/rbac.go
    • test/e2e/suite/cases/token/token.go
    • test/e2e/suite/cases/upgrade/upgrade.go
    • test/e2e/suite/suite.go
    • test/kind/image.go
    • test/kind/kind.go
    • test/tools/audit-webhook/pkg/sink/sink.go
    • test/tools/fake-apiserver/pkg/server/server.go
    • test/tools/issuer/pkg/issuer/issuer.go
    • test/util/tls.go
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +134 to 142
con, err := net.DialTimeout("tcp", host, timeout)
if err != nil {
return false, nil
} else {
con.Close()
defer func() {
_ = con.Close()
}()
return true, nil
}

Choose a reason for hiding this comment

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

Network connection not properly closed on error

The connection to the URL is not properly closed if there's an error. Add a defer to close the connection after checking for errors to prevent resource leaks.

Code suggestion
Check the AI-generated fix before applying

 @@ -134,11 +134,11 @@
  +		con, err := net.DialTimeout("tcp", host, timeout)
  +		if err != nil {
  +			return false, nil
  +		} else {
  +			defer func() {
  +					_ = con.Close()
  +			}()
  +			return true, nil
  +		}

@@ -134,11 +134,12 @@

  • con, err := net.DialTimeout("tcp", host, timeout)
    
  • if err != nil {
    
  • 	return false, nil
    
  • }
    
  • defer func() {
    
  • 	_ = con.Close()
    
  • }()
    
  • return true, nil
    

</div>
</details>
</div>



<small><i>Code Review Run <a href=https://github.com/platform9/pf9-oidc-proxy/pull/14#issuecomment-3200886537>#894caf</a></i></small>
</div>

---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them

Copy link
Collaborator

@indradhanush indradhanush left a comment

Choose a reason for hiding this comment

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

Left a bunch of comments about not ignoring the error. I'm surprised the linter didn't catch this already. Can you check how to enforce this check with golangci-lint 2.x?

Not blocking, because lint fixes are still good to have!

cols, _, _ := term.GetSize(0)
cmd.SetUsageFunc(func(cmd *cobra.Command) error {
fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine())
_, _ = fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't ignore the error being returned. You can ignore n.

So something like this:

Suggested change
_, _ = fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine())
if _, err := fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine()); err != nil {
return err
}


cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 9 to 11
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/client-go/transport"

genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of removing this, why not remove genericapirequest? Then you won't have to make code changes related to this import. There's no conflict with request at the moment, so we can directly import it as is.

}
defer file.Close()
defer func() {
_ = file.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't ignore the error. Log it.

}
defer watcher.Close()
defer func() {
_ = watcher.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

} else {
con.Close()
defer func() {
_ = con.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't ignore the error.

@hsri-pf9 hsri-pf9 force-pushed the private/harsh/lint-fix branch from a34776e to 3bf4de7 Compare August 21, 2025 07:01
@hsri-pf9 hsri-pf9 requested a review from indradhanush August 21, 2025 07:03
@hsri-pf9
Copy link
Collaborator Author

I will resolve the comments in this PR

@bito-code-review
Copy link

bito-code-review bot commented Aug 21, 2025

Code Review Agent Run #9e5c68

Actionable Suggestions - 0
Additional Suggestions - 6
  • test/kind/kind.go - 2
    • Redundant timeout in context and polling function · Line 221-225
      The timeout context is created with a 10-minute timeout, but then the same timeout duration is passed to `PollUntilContextTimeout`. This creates redundant timeout mechanisms that could lead to unexpected behavior.
      Code suggestion
       @@ -221,7 +221,7 @@
      -	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
      +	ctx, cancel := context.WithCancel(context.Background())
        	defer cancel()
       
      -	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
      +	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
    • Redundant timeout in context and polling function · Line 265-268
      The code creates a timeout context but then passes the same timeout duration to `PollUntilContextTimeout`. This is redundant as the context already has the timeout, leading to duplicate timeout mechanisms.
      Code suggestion
       @@ -265,7 +265,7 @@
        	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
        	defer cancel()
       
      -	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
      +	return wait.PollUntilContextTimeout(ctx, 5*time.Second, 0, true, func(ctx context.Context) (bool, error) {
  • pkg/proxy/handlers.go - 1
    • Redundant nil initialization after variable declaration · Line 96-97
      The type change from `user.Info` to `authuser.Info` is correct, but the variable is initialized to `nil` immediately after declaration, making the type change redundant. Consider removing the explicit initialization to `nil` as it's the default value for interface types.
      Code suggestion
       @@ -96,2 +96,1 @@
      +		var targetForContext authuser.Info
      -		var targetForContext authuser.Info
      -		targetForContext = nil
  • test/e2e/suite/cases/impersonation/impersonation.go - 1
    • Redundant named imports with same pattern · Line 9-10
      Changing dot imports to named imports creates semantic duplication with the `ginkgo.It` and `gomega.Expect` calls. The code now uses explicit package names but still uses the same pattern as dot imports.
      Code suggestion
       @@ -9,2 +9,2 @@
      -	ginkgo "github.com/onsi/ginkgo"
      -	gomega "github.com/onsi/gomega"
      +	. "github.com/onsi/ginkgo"
      +	. "github.com/onsi/gomega"
  • pkg/proxy/namespace_round_tripper.go - 1
    • Unnecessary complexity in file close handling · Line 51-53
      The `file.Close()` error is being silently ignored in the defer function. While ignoring the error is acceptable for file closing, using `defer file.Close()` directly would be more idiomatic in Go.
      Code suggestion
       @@ -51,3 +51,1 @@
      -	defer func() {
      -		_ = file.Close()
      -	}()
      +	defer file.Close()
  • test/e2e/framework/helper/poll.go - 1
    • Redundant timeout handling in polling function · Line 22-25
      The `context.WithTimeout` creates a context with timeout, but then the same timeout is passed to `PollUntilContextTimeout`. This creates redundant timeout handling that could lead to unexpected behavior.
      Code suggestion
       @@ -22,5 +22,5 @@
        	ctx, cancel := context.WithTimeout(context.Background(), timeout)
        	defer cancel()
       
      -	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
      +	err := wait.PollUntilContextTimeout(ctx, 2*time.Second, 0, true, func(ctx context.Context) (bool, error) {
Review Details
  • Files reviewed - 29 · Commit Range: 207ba4e..3bf4de7
    • Makefile
    • cmd/app/options/options.go
    • pkg/proxy/context/context.go
    • pkg/proxy/handlers.go
    • pkg/proxy/namespace_round_tripper.go
    • pkg/proxy/proxy.go
    • pkg/proxy/proxy_test.go
    • pkg/proxy/subjectaccessreview/subjectaccessreview_test.go
    • pkg/util/port.go
    • test/e2e/framework/framework.go
    • test/e2e/framework/helper/poll.go
    • test/e2e/framework/helper/requester.go
    • test/e2e/framework/helper/secrets.go
    • test/e2e/framework/util.go
    • test/e2e/suite/cases/audit/audit.go
    • test/e2e/suite/cases/headers/headers.go
    • test/e2e/suite/cases/impersonation/impersonation.go
    • test/e2e/suite/cases/passthrough/passthrough.go
    • test/e2e/suite/cases/probe/probe.go
    • test/e2e/suite/cases/rbac/rbac.go
    • test/e2e/suite/cases/token/token.go
    • test/e2e/suite/cases/upgrade/upgrade.go
    • test/e2e/suite/suite.go
    • test/kind/image.go
    • test/kind/kind.go
    • test/tools/audit-webhook/pkg/sink/sink.go
    • test/tools/fake-apiserver/pkg/server/server.go
    • test/tools/issuer/pkg/issuer/issuer.go
    • test/util/tls.go
  • Files skipped - 1
    • .github/workflows/lint.yml - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Golangci-lint (Linter) - ✖︎ Failed

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Default Agent You can customize the agent settings here or contact your Bito workspace admin at mithil@platform9.com.

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Collaborator

@indradhanush indradhanush left a comment

Choose a reason for hiding this comment

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

Lint is still failing. The lint failures looked very suspicious to me so I looked deeper. You'll need to:

  • Run go mod tidy
  • Run the lint again locally to see the failures which will be the correct ones this time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants