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

chore: linting improvements and catching false positives #882

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/golangci_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run golangci-lint

on:
pull_request:
branches: [ main ]
branches: [main]

jobs:
golangci-lint:
Expand All @@ -16,3 +16,5 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-check
golangci_lint_flags: "--timeout=120s"
level: warning
3 changes: 2 additions & 1 deletion cmd/cache/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
)

var (
region string
region string
//nolint:unused
bucketName string
storageAccount string
containerName string
Expand Down
1 change: 1 addition & 0 deletions cmd/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down
5 changes: 4 additions & 1 deletion pkg/analyzer/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ func (GatewayAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) {
gtwList := &gtwapi.GatewayList{}
gc := &gtwapi.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
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
10 changes: 8 additions & 2 deletions pkg/integration/trivy/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/server/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
44 changes: 12 additions & 32 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading