Skip to content

Commit 172f08b

Browse files
1. remove not worked metasrv option: --use-memory-store
2. fix golangci-lint 3. upgrade go version 4. use bare metal in e2e test
1 parent 88d4486 commit 172f08b

File tree

16 files changed

+69
-207
lines changed

16 files changed

+69
-207
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on: [ push, pull_request ]
44

55
env:
6-
GO_VERSION: "1.21"
6+
GO_VERSION: "1.25"
77

88
permissions:
99
contents: read
@@ -25,31 +25,11 @@ jobs:
2525
with:
2626
go-version: ${{ env.GO_VERSION }}
2727
- name: golangci-lint
28-
uses: golangci/golangci-lint-action@v3
28+
uses: golangci/golangci-lint-action@v9
2929
with:
30-
version: v1.54
3130
# '-v' flag is required to show the output of golangci-lint.
3231
args: -v
3332

34-
unit-test:
35-
name: Unit test coverage
36-
runs-on: ubuntu-latest
37-
needs: [ lint ]
38-
steps:
39-
- uses: actions/checkout@v4
40-
- uses: actions/setup-go@v5
41-
with:
42-
go-version: ${{ env.GO_VERSION }}
43-
- name: Unit test
44-
run: make coverage
45-
- name: Upload coverage to Codecov
46-
uses: codecov/codecov-action@v4
47-
with:
48-
token: ${{ secrets.CODECOV_TOKEN }}
49-
fail_ci_if_error: true
50-
files: ./coverage.xml
51-
name: codecov-gtctl
52-
verbose: true
5333
e2e:
5434
name: End to End tests
5535
runs-on: ubuntu-latest

.golangci.yaml

Lines changed: 19 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,23 @@
1+
version: "2"
2+
13
# Options for analysis running.
24
run:
3-
# Timeout for analysis, e.g. 30s, 5m.
4-
# Default: 1m
5-
timeout: 10m
6-
7-
# The default concurrency value is the number of available CPU.
8-
concurrency: 4
9-
10-
# Which dirs to skip: issues from them won't be reported.
11-
# Can use regexp here: `generated.*`, regexp is applied on full path,
12-
# including the path prefix if one is set.
13-
# Default value is empty list,
14-
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
15-
# "/" will be replaced by current OS file path separator to properly work on Windows.
16-
skip-dirs:
17-
- bin
18-
- docs
19-
- examples
20-
- hack
21-
22-
# output configuration options.
23-
output:
24-
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
25-
#
26-
# Multiple can be specified by separating them by comma, output can be provided
27-
# for each of them by separating format name and path by colon symbol.
28-
# Output path can be either `stdout`, `stderr` or path to the file to write to.
29-
# Example: "checkstyle:report.xml,json:stdout,colored-line-number"
30-
#
31-
# Default: colored-line-number
32-
format: colored-line-number
33-
34-
# Print lines of code with issue.
35-
# Default: true
36-
print-issued-lines: true
37-
38-
# Print linter name in the end of issue text.
39-
# Default: true
40-
print-linter-lines: true
5+
# Timeout for total work, e.g. 30s, 5m, 5m30s.
6+
# If the value is lower or equal to 0, the timeout is disabled.
7+
# Default: 0 (disabled)
8+
timeout: 5m
419

4210
linters:
43-
# Disable all linters.
44-
disable-all: true
45-
46-
# Enable specific linter
47-
# https://golangci-lint.run/usage/linters/#enabled-by-default
48-
enable:
49-
# Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases.
50-
- errcheck
51-
52-
# Linter for Go source code that specializes in simplifying code.
53-
- gosimple
54-
55-
# Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
56-
- govet
57-
58-
# Detects when assignments to existing variables are not used.
59-
- ineffassign
60-
61-
# It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
62-
# The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.
63-
- staticcheck
64-
65-
# Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
66-
- goimports
67-
68-
# Checks whether HTTP response body is closed successfully.
69-
- bodyclose
70-
71-
# Provides diagnostics that check for bugs, performance and style issues.
72-
# Extensible without recompilation through dynamic rules.
73-
# Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion.
74-
- gocritic
75-
76-
# Gofmt checks whether code was gofmt-ed. By default, this tool runs with -s option to check for code simplification.
77-
- gofmt
78-
79-
# Finds repeated strings that could be replaced by a constant.
80-
- goconst
81-
82-
# Finds commonly misspelled English words in comments.
83-
- misspell
84-
85-
# Finds naked returns in functions greater than a specified function length.
86-
- nakedret
87-
88-
linters-settings:
89-
goimports:
90-
# A comma-separated list of prefixes, which, if set, checks import paths
91-
# with the given prefixes are grouped after 3rd-party packages.
92-
# Default: ""
93-
local-prefixes: github.com/GreptimeTeam/gtctl
94-
linters-settings:
95-
min-occurrences: 3
11+
# Default set of linters.
12+
# The value can be:
13+
# - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default
14+
# - `all`: enables all linters by default.
15+
# - `none`: disables all linters by default.
16+
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
17+
# Default: standard
18+
default: standard
19+
20+
formatters:
21+
# Enable specific formatter.
22+
# Default: [] (uses standard Go formatting)
23+
enable: []

cmd/gtctl/cluster_create.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ type clusterCreateCliOptions struct {
6262
Config string
6363
GreptimeBinVersion string
6464
EnableCache bool
65-
UseMemoryMeta bool
6665

6766
// Common options.
6867
Timeout int
@@ -110,7 +109,6 @@ func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
110109
cmd.Flags().StringVar(&options.GreptimeDBClusterValuesFile, "greptimedb-cluster-values-file", "", "The values file for greptimedb cluster.")
111110
cmd.Flags().StringVar(&options.EtcdClusterValuesFile, "etcd-cluster-values-file", "", "The values file for etcd cluster.")
112111
cmd.Flags().StringVar(&options.GreptimeDBOperatorValuesFile, "greptimedb-operator-values-file", "", "The values file for greptimedb operator.")
113-
cmd.Flags().BoolVar(&options.UseMemoryMeta, "use-memory-meta", false, "Bootstrap the whole cluster without installing etcd for testing purposes through using the memory storage of metasrv in bare-metal mode.")
114112

115113
return cmd
116114
}
@@ -184,7 +182,7 @@ func NewCluster(args []string, options *clusterCreateCliOptions, l logger.Logger
184182
l.V(0).Infof("Creating GreptimeDB cluster '%s' on bare-metal", logger.Bold(clusterName))
185183

186184
var opts []baremetal.Option
187-
opts = append(opts, baremetal.WithEnableCache(options.EnableCache), baremetal.WithMetastore(options.UseMemoryMeta))
185+
opts = append(opts, baremetal.WithEnableCache(options.EnableCache))
188186
if len(options.GreptimeBinVersion) > 0 {
189187
opts = append(opts, baremetal.WithGreptimeVersion(options.GreptimeBinVersion))
190188
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/GreptimeTeam/gtctl
22

3-
go 1.18
3+
go 1.25
44

55
require (
66
github.com/GreptimeTeam/greptimedb-operator v0.1.0-alpha.9

pkg/artifacts/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (m *manager) downloadFromHTTP(ctx context.Context, httpURL string, dest str
246246
if resp.StatusCode != http.StatusOK {
247247
return fmt.Errorf("download failed, status code: %d", resp.StatusCode)
248248
}
249-
defer resp.Body.Close()
249+
defer fileutils.MustClose(resp.Body)
250250

251251
data, err := io.ReadAll(resp.Body)
252252
if err != nil {
@@ -306,7 +306,7 @@ func (m *manager) chartIndexFile(ctx context.Context, indexURL string) (*repo.In
306306
if err != nil {
307307
return nil, err
308308
}
309-
defer rsp.Body.Close()
309+
defer fileutils.MustClose(rsp.Body)
310310

311311
data, err := io.ReadAll(rsp.Body)
312312
if err != nil {
@@ -431,7 +431,7 @@ func (m *manager) installBinaries(downloadFile, installDir string) error {
431431
if err != nil {
432432
return err
433433
}
434-
defer os.RemoveAll(tempDir)
434+
defer fileutils.RemoveAll(tempDir)
435435

436436
if err := fileutils.Uncompress(downloadFile, tempDir); err != nil {
437437
return err
@@ -525,7 +525,7 @@ func (m *manager) getVersionInfoFromS3(typ ArtifactType, name string, nightly bo
525525
if resp.StatusCode != http.StatusOK {
526526
return "", fmt.Errorf("get latest info from '%s' failed, status code: %d", latestVersionInfoURL, resp.StatusCode)
527527
}
528-
defer resp.Body.Close()
528+
defer fileutils.MustClose(resp.Body)
529529

530530
data, err := io.ReadAll(resp.Body)
531531
if err != nil {

pkg/artifacts/manager_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626
"sigs.k8s.io/kind/pkg/log"
2727

2828
"github.com/GreptimeTeam/gtctl/pkg/logger"
29+
"github.com/GreptimeTeam/gtctl/pkg/utils/file"
2930
)
3031

3132
func TestDownloadCharts(t *testing.T) {
3233
tempDir, err := os.MkdirTemp("/tmp", "gtctl-ut-")
3334
if err != nil {
3435
t.Fatal(err)
3536
}
36-
defer os.RemoveAll(tempDir)
37+
defer file.RemoveAll(tempDir)
3738

3839
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
3940
if err != nil {
@@ -79,7 +80,7 @@ func TestDownloadChartsFromCNRegion(t *testing.T) {
7980
if err != nil {
8081
t.Fatal(err)
8182
}
82-
defer os.RemoveAll(tempDir)
83+
defer file.RemoveAll(tempDir)
8384

8485
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
8586
if err != nil {
@@ -125,7 +126,7 @@ func TestDownloadBinariesFromCNRegion(t *testing.T) {
125126
if err != nil {
126127
t.Fatal(err)
127128
}
128-
defer os.RemoveAll(tempDir)
129+
defer file.RemoveAll(tempDir)
129130

130131
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
131132
if err != nil {
@@ -171,7 +172,7 @@ func TestDownloadBinaries(t *testing.T) {
171172
if err != nil {
172173
t.Fatal(err)
173174
}
174-
defer os.RemoveAll(tempDir)
175+
defer file.RemoveAll(tempDir)
175176

176177
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
177178
if err != nil {
@@ -218,7 +219,7 @@ func TestArtifactsCache(t *testing.T) {
218219
if err != nil {
219220
t.Fatal(err)
220221
}
221-
defer os.RemoveAll(tempDir)
222+
defer file.RemoveAll(tempDir)
222223

223224
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
224225
if err != nil {

pkg/cluster/baremetal/cluster.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type Cluster struct {
3434
config *config.BareMetalClusterConfig
3535
createNoDirs bool
3636
enableCache bool
37-
useMemoryMeta bool
3837

3938
am artifacts.Manager
4039
mm metadata.Manager
@@ -55,9 +54,9 @@ type ClusterComponents struct {
5554
}
5655

5756
func NewClusterComponents(config *config.BareMetalClusterComponentsConfig, workingDirs components.WorkingDirs,
58-
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) *ClusterComponents {
57+
wg *sync.WaitGroup, logger logger.Logger) *ClusterComponents {
5958
return &ClusterComponents{
60-
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger, useMemoryMeta),
59+
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger),
6160
Datanode: components.NewDataNode(config.Datanode, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
6261
Frontend: components.NewFrontend(config.Frontend, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
6362
Etcd: components.NewEtcd(workingDirs, wg, logger),
@@ -85,12 +84,6 @@ func WithEnableCache(enableCache bool) Option {
8584
}
8685
}
8786

88-
func WithMetastore(useMemoryMeta bool) Option {
89-
return func(c *Cluster) {
90-
c.useMemoryMeta = useMemoryMeta
91-
}
92-
}
93-
9487
func WithCreateNoDirs() Option {
9588
return func(c *Cluster) {
9689
c.createNoDirs = true
@@ -143,7 +136,7 @@ func NewCluster(l logger.Logger, clusterName string, opts ...Option) (cluster.Op
143136
DataDir: csd.DataDir,
144137
LogsDir: csd.LogsDir,
145138
PidsDir: csd.PidsDir,
146-
}, &c.wg, c.logger, c.useMemoryMeta)
139+
}, &c.wg, c.logger)
147140

148141
return c, nil
149142
}

pkg/cluster/baremetal/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
5252
return nil
5353
}
5454

55-
if !c.useMemoryMeta {
55+
if c.config.Etcd != nil {
5656
if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
5757
return err
5858
}

pkg/components/metasrv.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net"
2323
"net/http"
2424
"path"
25-
"strconv"
2625
"sync"
2726
"time"
2827

@@ -37,19 +36,17 @@ type metaSrv struct {
3736
workingDirs WorkingDirs
3837
wg *sync.WaitGroup
3938
logger logger.Logger
40-
useMemoryMeta bool
4139

4240
allocatedDirs
4341
}
4442

4543
func NewMetaSrv(config *config.MetaSrv, workingDirs WorkingDirs,
46-
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) ClusterComponent {
44+
wg *sync.WaitGroup, logger logger.Logger) ClusterComponent {
4745
return &metaSrv{
4846
config: config,
4947
workingDirs: workingDirs,
5048
wg: wg,
5149
logger: logger,
52-
useMemoryMeta: useMemoryMeta,
5350
}
5451
}
5552

@@ -128,11 +125,6 @@ func (m *metaSrv) BuildArgs(params ...interface{}) []string {
128125
args = GenerateAddrArg("--http-addr", m.config.HTTPAddr, nodeID, args)
129126
args = GenerateAddrArg("--bind-addr", bindAddr, nodeID, args)
130127

131-
if m.useMemoryMeta {
132-
useMemoryMeta := strconv.FormatBool(m.useMemoryMeta)
133-
args = GenerateAddrArg("--use-memory-store", useMemoryMeta, nodeID, args)
134-
}
135-
136128
if len(m.config.Config) > 0 {
137129
args = append(args, fmt.Sprintf("-c=%s", m.config.Config))
138130
}

pkg/config/baremetal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type BareMetalClusterMetadata struct {
3838
// Each field of BareMetalClusterConfig can also have its own exported method `Validate`.
3939
type BareMetalClusterConfig struct {
4040
Cluster *BareMetalClusterComponentsConfig `yaml:"cluster" validate:"required"`
41-
Etcd *Etcd `yaml:"etcd" validate:"required"`
41+
Etcd *Etcd `yaml:"etcd"`
4242
}
4343

4444
type BareMetalClusterComponentsConfig struct {

0 commit comments

Comments
 (0)