chore: linting improvements and catching false positives (#882)

* chore: linting improvements and catching false positives

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: linting improvements and catching false positives

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: linting improvements and catching false positives

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: increase linter time out

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

---------

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Alex Jones 2024-01-23 07:46:01 +00:00 committed by GitHub
parent 335616c20f
commit 2effbb345a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 38 additions and 38 deletions

View File

@ -2,7 +2,7 @@ name: Run golangci-lint
on: on:
pull_request: pull_request:
branches: [ main ] branches: [main]
jobs: jobs:
golangci-lint: golangci-lint:
@ -16,3 +16,5 @@ jobs:
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check reporter: github-pr-check
golangci_lint_flags: "--timeout=120s"
level: warning

3
cmd/cache/add.go vendored
View File

@ -24,7 +24,8 @@ import (
) )
var ( var (
region string region string
//nolint:unused
bucketName string bucketName string
storageAccount string storageAccount string
containerName string containerName string

View File

@ -41,6 +41,7 @@ var GenerateCmd = &cobra.Command{
} }
// override the default backend if a flag is provided // override the default backend if a flag is provided
if backend != "" { if backend != "" {
//nolint:all
backendType = backend backendType = backend
} }
fmt.Println("") fmt.Println("")

View File

@ -37,7 +37,10 @@ func (GatewayAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
gtwList := &gtwapi.GatewayList{} gtwList := &gtwapi.GatewayList{}
gc := &gtwapi.GatewayClass{} gc := &gtwapi.GatewayClass{}
client := a.Client.CtrlClient 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 { if err := client.List(a.Context, gtwList, &ctrl.ListOptions{}); err != nil {
return nil, err return nil, err
} }

View File

@ -56,7 +56,9 @@ func TestGatewayAnalyzer(t *testing.T) {
Gateway := BuildGateway(ClassName, AcceptedStatus) Gateway := BuildGateway(ClassName, AcceptedStatus)
// Create a Gateway Analyzer instance with the fake client // Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme scheme := scheme.Scheme
//nolint:all
gtwapi.Install(scheme) gtwapi.Install(scheme)
//nolint:all
apiextensionsv1.AddToScheme(scheme) apiextensionsv1.AddToScheme(scheme)
objects := []runtime.Object{ objects := []runtime.Object{
&Gateway, &Gateway,
@ -88,6 +90,7 @@ func TestMissingClassGatewayAnalyzer(t *testing.T) {
// Create a Gateway Analyzer instance with the fake client // Create a Gateway Analyzer instance with the fake client
scheme := scheme.Scheme scheme := scheme.Scheme
//nolint:all
gtwapi.Install(scheme) gtwapi.Install(scheme)
apiextensionsv1.AddToScheme(scheme) apiextensionsv1.AddToScheme(scheme)
objects := []runtime.Object{ objects := []runtime.Object{

View File

@ -33,7 +33,10 @@ func (TrivyAnalyzer) analyzeVulnerabilityReports(a common.Analyzer) ([]common.Re
result := &v1alpha1.VulnerabilityReportList{} result := &v1alpha1.VulnerabilityReportList{}
client := a.Client.CtrlClient 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 { if err := client.List(a.Context, result, &ctrl.ListOptions{}); err != nil {
return nil, err return nil, err
} }
@ -85,7 +88,10 @@ func (t TrivyAnalyzer) analyzeConfigAuditReports(a common.Analyzer) ([]common.Re
result := &v1alpha1.ConfigAuditReportList{} result := &v1alpha1.ConfigAuditReportList{}
client := a.Client.CtrlClient 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 { if err := client.List(a.Context, result, &ctrl.ListOptions{}); err != nil {
return nil, err return nil, err
} }

View File

@ -131,7 +131,10 @@ func (*handler) deactivateAllIntegrations(integrationProvider *integration.Integ
} }
if err == nil { if err == nil {
if namespace != "" { if namespace != "" {
integrationProvider.Deactivate(i, namespace) err := integrationProvider.Deactivate(i, namespace)
if err != nil {
return err
}
} else { } else {
fmt.Printf("Skipping deactivation of %s, not installed\n", i) fmt.Printf("Skipping deactivation of %s, not installed\n", i)
} }

View File

@ -14,13 +14,10 @@ limitations under the License.
package server package server
import ( import (
json "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
"strconv"
"strings"
"time" "time"
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc" rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
@ -32,25 +29,26 @@ import (
) )
type Config struct { type Config struct {
Port string Port string
MetricsPort string MetricsPort string
Backend string Backend string
Key string Key string
Token string Token string
Output string Output string
maxConcurrency int Handler *handler
Handler *handler Logger *zap.Logger
Logger *zap.Logger metricsServer *http.Server
metricsServer *http.Server listener net.Listener
listener net.Listener
} }
//nolint:unused
type Health struct { type Health struct {
Status string `json:"status"` Status string `json:"status"`
Success int `json:"success"` Success int `json:"success"`
Failure int `json:"failure"` Failure int `json:"failure"`
} }
//nolint:unused
var health = Health{ var health = Health{
Status: "ok", Status: "ok",
Success: 0, Success: 0,
@ -106,21 +104,3 @@ func (s *Config) ServeMetrics() error {
} }
return nil 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
}

View File

@ -16,6 +16,7 @@ func TestServerInit(t *testing.T) {
color.Red("failed to create logger: %v", err) color.Red("failed to create logger: %v", err)
os.Exit(1) os.Exit(1)
} }
//nolint:all
defer logger.Sync() defer logger.Sync()
server_config := Config{ server_config := Config{
Backend: "openai", Backend: "openai",