Skip to content

Commit

Permalink
fix: improve code quality and context handling
Browse files Browse the repository at this point in the history
* fix: remove duplicate error check in elasticsearch client
* fix: use context.Background() instead of context.TODO()
* fix: add missing imports and remove unused ones
* fix: add contextcheck linter exceptions where needed
* chore: update .gitignore to exclude VERSION file
* chore: expand GOSOURCE_PATHS in Makefile to include cmd/...
* style: fix imports ordering in elasticsearch.go
  • Loading branch information
elliotxx committed Nov 22, 2024
1 parent 0345ed2 commit ac773b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ issues:
text: "use of `fmt.Println`"
linters:
- forbidigo
# Allow fmt.Println in version commands
- path: cmd/(cert-generator|karpor)/.*
text: "use of `fmt.Println`"
linters:
- forbidigo
exclude-dirs:
- "pkg/kubernetes/generated" # Generated code
- "pkg/kubernetes/openapi" # Generated OpenAPI code
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include go.mk

# Override the variables in the go.mk
APPROOT=karpor
GOSOURCE_PATHS = ./pkg/...
GOSOURCE_PATHS = ./pkg/... ./cmd/...
LICENSE_CHECKER ?= license-eye
LICENSE_CHECKER_VERSION ?= main

Expand Down
2 changes: 2 additions & 0 deletions cmd/karpor/app/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func run(ctx context.Context, options *syncerOptions) error {
}

// TODO: add startup parameters to change the type of storage
//nolint:contextcheck
es, err := elasticsearch.NewStorage(esclient.Config{
Addresses: options.ElasticSearchAddresses,
})
Expand All @@ -80,6 +81,7 @@ func run(ctx context.Context, options *syncerOptions) error {
return err
}

//nolint:contextcheck
if err = syncer.NewSyncReconciler(es).SetupWithManager(mgr); err != nil {
log.Error(err, "unable to create resource syncer")
return err
Expand Down
3 changes: 0 additions & 3 deletions pkg/infra/persistence/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func NewClient(config elasticsearch.Config) (*Client, error) {
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
typed, err := elasticsearch.NewTypedClient(config)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/infra/search/storage/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func NewStorage(cfg esv8.Config) (*Storage, error) {
return nil, err
}

if err = cl.CreateIndex(context.TODO(), defaultResourceIndexName, strings.NewReader(defaultResourceMapping)); err != nil {
if err = cl.CreateIndex(context.Background(), defaultResourceIndexName, strings.NewReader(defaultResourceMapping)); err != nil {
return nil, err
}

if err = cl.CreateIndex(context.TODO(), defaultResourceGroupRuleIndexName, strings.NewReader(defaultResourceGroupRuleMapping)); err != nil {
if err = cl.CreateIndex(context.Background(), defaultResourceGroupRuleIndexName, strings.NewReader(defaultResourceGroupRuleMapping)); err != nil {
return nil, err
}

Expand Down
1 change: 0 additions & 1 deletion ui/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import (
// Embedded contains embedded UI resources
//
//go:embed build/*
//nolint:typecheck
var Embedded embed.FS

0 comments on commit ac773b1

Please sign in to comment.