From 2effbb345ad1c2771ec798e06ccde68d3253b4bc Mon Sep 17 00:00:00 2001 From: Alex Jones Date: Tue, 23 Jan 2024 07:46:01 +0000 Subject: [PATCH] chore: linting improvements and catching false positives (#882) * chore: linting improvements and catching false positives Signed-off-by: Alex Jones * chore: linting improvements and catching false positives Signed-off-by: Alex Jones * chore: linting improvements and catching false positives Signed-off-by: Alex Jones * chore: increase linter time out Signed-off-by: Alex Jones --------- Signed-off-by: Alex Jones --- .github/workflows/golangci_lint.yaml | 4 ++- cmd/cache/add.go | 3 +- cmd/generate/generate.go | 1 + pkg/analyzer/gateway.go | 5 +++- pkg/analyzer/gateway_test.go | 3 ++ pkg/integration/trivy/analyzer.go | 10 +++++-- pkg/server/integration.go | 5 +++- pkg/server/server.go | 44 ++++++++-------------------- pkg/server/server_test.go | 1 + 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/golangci_lint.yaml b/.github/workflows/golangci_lint.yaml index 8523d6a48c..4b91793193 100644 --- a/.github/workflows/golangci_lint.yaml +++ b/.github/workflows/golangci_lint.yaml @@ -2,7 +2,7 @@ name: Run golangci-lint on: pull_request: - branches: [ main ] + branches: [main] jobs: golangci-lint: @@ -16,3 +16,5 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-pr-check + golangci_lint_flags: "--timeout=120s" + level: warning diff --git a/cmd/cache/add.go b/cmd/cache/add.go index 979aa8f036..3a71192703 100644 --- a/cmd/cache/add.go +++ b/cmd/cache/add.go @@ -24,7 +24,8 @@ import ( ) var ( - region string + region string + //nolint:unused bucketName string storageAccount string containerName string diff --git a/cmd/generate/generate.go b/cmd/generate/generate.go index 087ad02fc1..2173ca10ff 100644 --- a/cmd/generate/generate.go +++ b/cmd/generate/generate.go @@ -41,6 +41,7 @@ var GenerateCmd = &cobra.Command{ } // override the default backend if a flag is provided if backend != "" { + //nolint:all backendType = backend } fmt.Println("") diff --git a/pkg/analyzer/gateway.go b/pkg/analyzer/gateway.go index a67cc4e6c6..557af26dd2 100644 --- a/pkg/analyzer/gateway.go +++ b/pkg/analyzer/gateway.go @@ -37,7 +37,10 @@ func (GatewayAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { gtwList := >wapi.GatewayList{} gc := >wapi.GatewayClass{} client := a.Client.CtrlClient - gtwapi.AddToScheme(client.Scheme()) + err := gtwapi.AddToScheme(client.Scheme()) + if err != nil { + return nil, err + } if err := client.List(a.Context, gtwList, &ctrl.ListOptions{}); err != nil { return nil, err } diff --git a/pkg/analyzer/gateway_test.go b/pkg/analyzer/gateway_test.go index 44d6893c80..920144871d 100644 --- a/pkg/analyzer/gateway_test.go +++ b/pkg/analyzer/gateway_test.go @@ -56,7 +56,9 @@ func TestGatewayAnalyzer(t *testing.T) { Gateway := BuildGateway(ClassName, AcceptedStatus) // Create a Gateway Analyzer instance with the fake client scheme := scheme.Scheme + //nolint:all gtwapi.Install(scheme) + //nolint:all apiextensionsv1.AddToScheme(scheme) objects := []runtime.Object{ &Gateway, @@ -88,6 +90,7 @@ func TestMissingClassGatewayAnalyzer(t *testing.T) { // Create a Gateway Analyzer instance with the fake client scheme := scheme.Scheme + //nolint:all gtwapi.Install(scheme) apiextensionsv1.AddToScheme(scheme) objects := []runtime.Object{ diff --git a/pkg/integration/trivy/analyzer.go b/pkg/integration/trivy/analyzer.go index d65920e81c..547575d7a3 100644 --- a/pkg/integration/trivy/analyzer.go +++ b/pkg/integration/trivy/analyzer.go @@ -33,7 +33,10 @@ func (TrivyAnalyzer) analyzeVulnerabilityReports(a common.Analyzer) ([]common.Re result := &v1alpha1.VulnerabilityReportList{} client := a.Client.CtrlClient - v1alpha1.AddToScheme(client.Scheme()) + err := v1alpha1.AddToScheme(client.Scheme()) + if err != nil { + return nil, err + } if err := client.List(a.Context, result, &ctrl.ListOptions{}); err != nil { return nil, err } @@ -85,7 +88,10 @@ func (t TrivyAnalyzer) analyzeConfigAuditReports(a common.Analyzer) ([]common.Re result := &v1alpha1.ConfigAuditReportList{} client := a.Client.CtrlClient - v1alpha1.AddToScheme(client.Scheme()) + err := v1alpha1.AddToScheme(client.Scheme()) + if err != nil { + return nil, err + } if err := client.List(a.Context, result, &ctrl.ListOptions{}); err != nil { return nil, err } diff --git a/pkg/server/integration.go b/pkg/server/integration.go index 901df9485e..9542916721 100644 --- a/pkg/server/integration.go +++ b/pkg/server/integration.go @@ -131,7 +131,10 @@ func (*handler) deactivateAllIntegrations(integrationProvider *integration.Integ } if err == nil { if namespace != "" { - integrationProvider.Deactivate(i, namespace) + err := integrationProvider.Deactivate(i, namespace) + if err != nil { + return err + } } else { fmt.Printf("Skipping deactivation of %s, not installed\n", i) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 00862c5fa0..d0099e4ef3 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -14,13 +14,10 @@ limitations under the License. package server import ( - json "encoding/json" "errors" "fmt" "net" "net/http" - "strconv" - "strings" "time" rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc" @@ -32,25 +29,26 @@ import ( ) type Config struct { - Port string - MetricsPort string - Backend string - Key string - Token string - Output string - maxConcurrency int - Handler *handler - Logger *zap.Logger - metricsServer *http.Server - listener net.Listener + Port string + MetricsPort string + Backend string + Key string + Token string + Output string + Handler *handler + Logger *zap.Logger + metricsServer *http.Server + listener net.Listener } +//nolint:unused type Health struct { Status string `json:"status"` Success int `json:"success"` Failure int `json:"failure"` } +//nolint:unused var health = Health{ Status: "ok", Success: 0, @@ -106,21 +104,3 @@ func (s *Config) ServeMetrics() error { } return nil } - -func (s *Config) healthzHandler(w http.ResponseWriter, r *http.Request) { - js, err := json.MarshalIndent(health, "", " ") - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - fmt.Fprint(w, string(js)) -} - -func getBoolParam(param string) bool { - b, err := strconv.ParseBool(strings.ToLower(param)) - if err != nil { - // Handle error if conversion fails - return false - } - return b -} diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index ef76f83d06..ce6d684796 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -16,6 +16,7 @@ func TestServerInit(t *testing.T) { color.Red("failed to create logger: %v", err) os.Exit(1) } + //nolint:all defer logger.Sync() server_config := Config{ Backend: "openai",