Skip to content

Commit e3d3ecc

Browse files
authored
Use golangci-lint 2.x (#207)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 5beb878 commit e3d3ecc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+512
-492
lines changed

.golangci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "2"
2+
linters:
3+
default: standard
4+
enable:
5+
- unparam
6+
7+
formatters:
8+
enable:
9+
- gofmt
10+
- goimports
11+
settings:
12+
gofmt:
13+
rewrite-rules:
14+
- pattern: 'interface{}'
15+
replacement: 'any'
16+
17+
issues:
18+
max-same-issues: 100
19+
20+
exclude-files:
21+
- generated.*\\.go
22+
23+
exclude-dirs:
24+
- client
25+
- vendor
26+
27+
run:
28+
timeout: 10m

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ endif
4545
### These variables should not need tweaking.
4646
###
4747

48-
SRC_PKGS := elasticsearch elasticsearchdashboard mariadb mongodb mysql oracle perconaxtradb pgbouncer postgres proxysql redis redissentinel pgpool
48+
SRC_PKGS := cassandra clickhouse db2 druid elasticsearch elasticsearchdashboard hack hazelcast ignite kafka mariadb memcached mongodb mssqlserver mysql neo4j oracle perconaxtradb pgbouncer pgpool postgres proxysql qdrant rabbitmq redis redissentinel singlestore solr zookeeper
4949
SRC_DIRS := $(SRC_PKGS)
5050

5151
DOCKER_PLATFORMS := linux/amd64 linux/arm linux/arm64
@@ -177,8 +177,6 @@ test: $(BUILD_DIRS)
177177
./hack/test.sh $(SRC_PKGS) \
178178
"
179179

180-
ADDTL_LINTERS := gofmt,goimports,unparam
181-
182180
.PHONY: lint
183181
lint: $(BUILD_DIRS)
184182
@echo "running linter"
@@ -196,7 +194,7 @@ lint: $(BUILD_DIRS)
196194
--env GO111MODULE=on \
197195
--env GOFLAGS="-mod=vendor" \
198196
$(BUILD_IMAGE) \
199-
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --exclude-files="generated.*\.go$\" --exclude-dirs-use-default
197+
golangci-lint run
200198

201199
$(BUILD_DIRS):
202200
@mkdir -p $@

cassandra/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ func (c *Client) PingCassandra() error {
9797

9898
func (c *Client) CloseCassandraClient() {
9999
if c != nil {
100-
c.Close()
100+
c.Close() // nolint:errcheck
101101
}
102102
}

cassandra/kubedb_client_builder.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
"errors"
2424
"fmt"
2525

26+
"kubedb.dev/apimachinery/apis/kubedb"
27+
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
28+
29+
"github.com/gocql/gocql"
2630
core "k8s.io/api/core/v1"
2731
kerr "k8s.io/apimachinery/pkg/api/errors"
2832
"k8s.io/apimachinery/pkg/types"
2933
"k8s.io/klog/v2"
30-
"kubedb.dev/apimachinery/apis/kubedb"
31-
32-
"github.com/gocql/gocql"
33-
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
)
3636

@@ -63,6 +63,7 @@ func (o *KubeDBClientBuilder) WithContext(ctx context.Context) *KubeDBClientBuil
6363
o.ctx = ctx
6464
return o
6565
}
66+
6667
func (o *KubeDBClientBuilder) GetCassandraClient() (*Client, error) {
6768
host := o.url
6869
cluster := gocql.NewCluster(host)

clickhouse/kubedb_client_builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
"database/sql"
2222
"fmt"
2323

24+
"kubedb.dev/apimachinery/apis/kubedb"
25+
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
26+
2427
_ "github.com/ClickHouse/clickhouse-go/v2"
2528
core "k8s.io/api/core/v1"
2629
"k8s.io/klog/v2"
27-
"kubedb.dev/apimachinery/apis/kubedb"
28-
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
)
3132

@@ -81,7 +82,7 @@ func (o *KubeDBClientBuilder) GetClickHouseClient() (*Client, error) {
8182
}
8283
// ping to database to check the connection
8384
if err := db.PingContext(o.ctx); err != nil {
84-
closeErr := db.Close()
85+
closeErr := db.Close() // nolint:errcheck
8586
if closeErr != nil {
8687
klog.Errorf("Failed to close client. error: %v", closeErr)
8788
}

db2/kubedb_client_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"net/http"
88
"time"
99

10+
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
11+
1012
"github.com/go-resty/resty/v2"
1113
"github.com/pkg/errors"
1214
core "k8s.io/api/core/v1"
1315
"k8s.io/apimachinery/pkg/types"
1416
"k8s.io/klog/v2"
15-
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
1617
"sigs.k8s.io/controller-runtime/pkg/client"
1718
)
1819

druid/client.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
)
4646

4747
func (c *Client) CloseDruidClient() {
48-
err := c.Close()
48+
err := c.Close() // nolint:errcheck
4949
if err != nil {
5050
klog.Error(err, "Failed to close druid middleManagers client")
5151
return
@@ -103,7 +103,7 @@ func (c *Client) CheckNodeDiscoveryStatus() (bool, error) {
103103
func (c *Client) CheckDataSourceExistence() (bool, error) {
104104
path := "druid/v2/sql"
105105

106-
data := map[string]interface{}{
106+
data := map[string]any{
107107
"query": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'druid' AND TABLE_NAME = 'kubedb-datasource'",
108108
}
109109

@@ -113,7 +113,7 @@ func (c *Client) CheckDataSourceExistence() (bool, error) {
113113
}
114114
rawMessage := json.RawMessage(jsonData)
115115

116-
var result []map[string]interface{}
116+
var result []map[string]any
117117
_, err = c.ExecuteRequest(http.MethodPost, path, rawMessage, &result)
118118
if err != nil {
119119
klog.Error("Failed to execute request", err)
@@ -192,7 +192,7 @@ func (c *Client) GetData() (string, error) {
192192

193193
func (c *Client) runSelectQuery() (string, error) {
194194
path := "druid/v2/sql"
195-
data := map[string]interface{}{
195+
data := map[string]any{
196196
"query": "SELECT * FROM \"kubedb-datasource\"",
197197
}
198198

@@ -202,7 +202,7 @@ func (c *Client) runSelectQuery() (string, error) {
202202
}
203203
rawMessage := json.RawMessage(jsonData)
204204

205-
var result []map[string]interface{}
205+
var result []map[string]any
206206
_, err = c.ExecuteRequest(http.MethodPost, path, rawMessage, &result)
207207
if err != nil {
208208
klog.Error("Failed to execute POST query request", err)
@@ -214,7 +214,7 @@ func (c *Client) runSelectQuery() (string, error) {
214214
}
215215

216216
func (c *Client) updateCoordinatorsWaitBeforeDeletingConfig(value int32) error {
217-
data := map[string]interface{}{
217+
data := map[string]any{
218218
"millisToWaitBeforeDeleting": value,
219219
}
220220
if err := c.updateCoordinatorDynamicConfig(data); err != nil {
@@ -224,7 +224,7 @@ func (c *Client) updateCoordinatorsWaitBeforeDeletingConfig(value int32) error {
224224
return nil
225225
}
226226

227-
func (c *Client) updateCoordinatorDynamicConfig(data map[string]interface{}) error {
227+
func (c *Client) updateCoordinatorDynamicConfig(data map[string]any) error {
228228
path := "druid/coordinator/v1/config"
229229

230230
jsonData, err := json.Marshal(data)
@@ -274,7 +274,7 @@ func (c *Client) submitTask(taskType DruidTaskType, dataSource string, data stri
274274
rawMessage := json.RawMessage(task)
275275
path := "druid/indexer/v1/task"
276276

277-
var result map[string]interface{}
277+
var result map[string]any
278278
_, err := c.ExecuteRequest(http.MethodPost, path, rawMessage, &result)
279279
if err != nil {
280280
klog.Error("Failed to execute POST ingestion or kill task request", err)
@@ -339,15 +339,15 @@ func GetKillTaskDefinition() string {
339339
func (c *Client) CheckTaskStatus(taskID string) (bool, error) {
340340
path := fmt.Sprintf("druid/indexer/v1/task/%s/status", taskID)
341341

342-
var result map[string]interface{}
342+
var result map[string]any
343343
_, err := c.ExecuteRequest(http.MethodGet, path, nil, &result)
344344
if err != nil {
345345
klog.Error("Failed to execute GET task status request", err)
346346
return false, err
347347
}
348348

349349
statusRes := result["status"]
350-
statusMap := statusRes.(map[string]interface{})
350+
statusMap := statusRes.(map[string]any)
351351
status := statusMap["status"].(string)
352352

353353
return status == "SUCCESS", nil
@@ -375,7 +375,7 @@ func (c *Client) checkDBReadAccess(oldData string) error {
375375
func (c *Client) UpdateDruidPassword(password string) error {
376376
path := "druid-ext/basic-security/authentication/db/basic/users/admin/credentials"
377377

378-
data := map[string]interface{}{
378+
data := map[string]any{
379379
"password": password,
380380
}
381381
jsonData, err := json.Marshal(data)

druid/kubedb_client_builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ import (
2424
"fmt"
2525
"net/http"
2626

27+
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
28+
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
29+
apiutils "kubedb.dev/apimachinery/pkg/utils"
30+
2731
druidgo "github.com/grafadruid/go-druid"
2832
_ "github.com/lib/pq"
2933
core "k8s.io/api/core/v1"
3034
kerr "k8s.io/apimachinery/pkg/api/errors"
3135
"k8s.io/apimachinery/pkg/types"
3236
"k8s.io/klog/v2"
33-
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
34-
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
35-
apiutils "kubedb.dev/apimachinery/pkg/utils"
3637
"sigs.k8s.io/controller-runtime/pkg/client"
3738
)
3839

elasticsearch/api.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
174174
return nil, -1, errors.Wrap(err, "failed to parse version")
175175
}
176176

177-
switch {
178-
case esVersion.Spec.AuthPlugin == catalog.ElasticsearchAuthPluginXpack ||
179-
esVersion.Spec.AuthPlugin == catalog.ElasticsearchAuthPluginSearchGuard ||
180-
esVersion.Spec.AuthPlugin == catalog.ElasticsearchAuthPluginOpenDistro:
177+
switch esVersion.Spec.AuthPlugin {
178+
case catalog.ElasticsearchAuthPluginXpack, catalog.ElasticsearchAuthPluginSearchGuard, catalog.ElasticsearchAuthPluginOpenDistro:
181179
switch {
182180
case version.Major() == 6:
183181
client, err := esv6.NewClient(esv6.Config{
@@ -208,7 +206,7 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
208206
if err != nil {
209207
return nil, -1, errors.Wrap(err, "failed to perform health check")
210208
}
211-
defer res.Body.Close()
209+
defer res.Body.Close() // nolint:errcheck
212210

213211
if res.IsError() {
214212
return &ESClientV6{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
@@ -244,7 +242,7 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
244242
if err != nil {
245243
return nil, -1, errors.Wrap(err, "failed to perform health check")
246244
}
247-
defer res.Body.Close()
245+
defer res.Body.Close() // nolint:errcheck
248246

249247
if res.IsError() {
250248
return &ESClientV7{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
@@ -280,7 +278,7 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
280278
if err != nil {
281279
return nil, -1, errors.Wrap(err, "failed to perform health check")
282280
}
283-
defer res.Body.Close()
281+
defer res.Body.Close() // nolint:errcheck
284282

285283
if res.IsError() {
286284
return &ESClientV8{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
@@ -316,15 +314,15 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
316314
if err != nil {
317315
return nil, -1, errors.Wrap(err, "failed to perform health check")
318316
}
319-
defer res.Body.Close()
317+
defer res.Body.Close() // nolint:errcheck
320318

321319
if res.IsError() {
322320
return &ESClientV9{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
323321
}
324322
return &ESClientV9{client: client}, res.StatusCode, nil
325323
}
326324

327-
case esVersion.Spec.AuthPlugin == catalog.ElasticsearchAuthPluginOpenSearch:
325+
case catalog.ElasticsearchAuthPluginOpenSearch:
328326
switch {
329327
case version.Major() == 1:
330328
client, err := opensearchv1.NewClient(opensearchv1.Config{
@@ -355,7 +353,7 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
355353
if err != nil {
356354
return nil, -1, errors.Wrap(err, "failed to perform health check")
357355
}
358-
defer res.Body.Close()
356+
defer res.Body.Close() // nolint:errcheck
359357

360358
if res.IsError() {
361359
return &OSClientV1{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
@@ -390,10 +388,10 @@ func GetElasticClient(kc kubernetes.Interface, dc cs.Interface, db *dbapi.Elasti
390388
if err != nil {
391389
return nil, -1, errors.Wrap(err, "Failed to perform health check")
392390
}
393-
defer res.Body.Close()
391+
defer res.Body.Close() // nolint:errcheck
394392

395393
if res.IsError() {
396-
return &OSClientV2{client: client}, res.StatusCode, fmt.Errorf("Health check failed with status code: %d", res.StatusCode)
394+
return &OSClientV2{client: client}, res.StatusCode, fmt.Errorf("health check failed with status code: %d", res.StatusCode)
397395
}
398396
return &OSClientV2{client: client}, res.StatusCode, nil
399397
}
@@ -453,28 +451,28 @@ type WriteRequestIndexBody struct {
453451
}
454452

455453
type ESClient interface {
456-
ClusterHealthInfo() (map[string]interface{}, error)
454+
ClusterHealthInfo() (map[string]any, error)
457455
ClusterStatus() (string, error)
458456
CountData(index string) (int, error)
459457
CreateDBUserRole(ctx context.Context) error
460458
CreateIndex(index string) error
461459
DeleteIndex(index string) error
462-
GetIndicesInfo() ([]interface{}, error)
460+
GetIndicesInfo() ([]any, error)
463461
GetClusterWriteStatus(ctx context.Context, db *dbapi.Elasticsearch) error
464462
GetClusterReadStatus(ctx context.Context, db *dbapi.Elasticsearch) error
465463
GetTotalDiskUsage(ctx context.Context) (string, error)
466464
GetDBUserRole(ctx context.Context) (error, bool)
467465
IndexExistsOrNot(index string) error
468-
NodesStats() (map[string]interface{}, error)
466+
NodesStats() (map[string]any, error)
469467
ShardStats() ([]ShardInfo, error)
470-
PutData(index, id string, data map[string]interface{}) error
468+
PutData(index, id string, data map[string]any) error
471469
SyncCredentialFromSecret(secret *core.Secret) error
472470
DisableShardAllocation() error
473471
ReEnableShardAllocation() error
474472
CheckVersion() (string, error)
475473
GetClusterStatus() (string, error)
476474
CountIndex() (int, error)
477-
GetData(_index, _type, _id string) (map[string]interface{}, error)
475+
GetData(_index, _type, _id string) (map[string]any, error)
478476
CountNodes() (int64, error)
479477
AddVotingConfigExclusions(nodes []string) error
480478
DeleteVotingConfigExclusions() error

0 commit comments

Comments
 (0)