Skip to content
Open
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
24 changes: 2 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [ push, pull_request ]

env:
GO_VERSION: "1.21"
GO_VERSION: "1.25"

permissions:
contents: read
Expand All @@ -25,31 +25,11 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v9
with:
version: v1.54
# '-v' flag is required to show the output of golangci-lint.
args: -v

unit-test:
name: Unit test coverage
runs-on: ubuntu-latest
needs: [ lint ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Unit test
run: make coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ./coverage.xml
name: codecov-gtctl
verbose: true
e2e:
name: End to End tests
runs-on: ubuntu-latest
Expand Down
110 changes: 19 additions & 91 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,95 +1,23 @@
version: "2"

# Options for analysis running.
run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 10m

# The default concurrency value is the number of available CPU.
concurrency: 4

# Which dirs to skip: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default value is empty list,
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-dirs:
- bin
- docs
- examples
- hack

# output configuration options.
output:
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.xml,json:stdout,colored-line-number"
#
# Default: colored-line-number
format: colored-line-number

# Print lines of code with issue.
# Default: true
print-issued-lines: true

# Print linter name in the end of issue text.
# Default: true
print-linter-lines: true
# Timeout for total work, e.g. 30s, 5m, 5m30s.
# If the value is lower or equal to 0, the timeout is disabled.
# Default: 0 (disabled)
timeout: 5m

linters:
# Disable all linters.
disable-all: true

# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
# Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases.
- errcheck

# Linter for Go source code that specializes in simplifying code.
- gosimple

# Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
- govet

# Detects when assignments to existing variables are not used.
- ineffassign

# It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
# The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.
- staticcheck

# Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
- goimports

# Checks whether HTTP response body is closed successfully.
- bodyclose

# Provides diagnostics that check for bugs, performance and style issues.
# Extensible without recompilation through dynamic rules.
# Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion.
- gocritic

# Gofmt checks whether code was gofmt-ed. By default, this tool runs with -s option to check for code simplification.
- gofmt

# Finds repeated strings that could be replaced by a constant.
- goconst

# Finds commonly misspelled English words in comments.
- misspell

# Finds naked returns in functions greater than a specified function length.
- nakedret

linters-settings:
goimports:
# A comma-separated list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: ""
local-prefixes: github.com/GreptimeTeam/gtctl
linters-settings:
min-occurrences: 3
# Default set of linters.
# The value can be:
# - `standard`: https://golangci-lint.run/docs/linters/#enabled-by-default
# - `all`: enables all linters by default.
# - `none`: disables all linters by default.
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
# Default: standard
default: standard

formatters:
# Enable specific formatter.
# Default: [] (uses standard Go formatting)
enable: []
4 changes: 1 addition & 3 deletions cmd/gtctl/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type clusterCreateCliOptions struct {
Config string
GreptimeBinVersion string
EnableCache bool
UseMemoryMeta bool

// Common options.
Timeout int
Expand Down Expand Up @@ -110,7 +109,6 @@ func NewCreateClusterCommand(l logger.Logger) *cobra.Command {
cmd.Flags().StringVar(&options.GreptimeDBClusterValuesFile, "greptimedb-cluster-values-file", "", "The values file for greptimedb cluster.")
cmd.Flags().StringVar(&options.EtcdClusterValuesFile, "etcd-cluster-values-file", "", "The values file for etcd cluster.")
cmd.Flags().StringVar(&options.GreptimeDBOperatorValuesFile, "greptimedb-operator-values-file", "", "The values file for greptimedb operator.")
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.")

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

var opts []baremetal.Option
opts = append(opts, baremetal.WithEnableCache(options.EnableCache), baremetal.WithMetastore(options.UseMemoryMeta))
opts = append(opts, baremetal.WithEnableCache(options.EnableCache))
if len(options.GreptimeBinVersion) > 0 {
opts = append(opts, baremetal.WithGreptimeVersion(options.GreptimeBinVersion))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/GreptimeTeam/gtctl

go 1.18
go 1.25

require (
github.com/GreptimeTeam/greptimedb-operator v0.1.0-alpha.9
Expand Down
8 changes: 4 additions & 4 deletions pkg/artifacts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (m *manager) downloadFromHTTP(ctx context.Context, httpURL string, dest str
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("download failed, status code: %d", resp.StatusCode)
}
defer resp.Body.Close()
defer fileutils.MustClose(resp.Body)

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

data, err := io.ReadAll(rsp.Body)
if err != nil {
Expand Down Expand Up @@ -431,7 +431,7 @@ func (m *manager) installBinaries(downloadFile, installDir string) error {
if err != nil {
return err
}
defer os.RemoveAll(tempDir)
defer fileutils.RemoveAll(tempDir)

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

data, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions pkg/artifacts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (
"sigs.k8s.io/kind/pkg/log"

"github.com/GreptimeTeam/gtctl/pkg/logger"
"github.com/GreptimeTeam/gtctl/pkg/utils/file"
)

func TestDownloadCharts(t *testing.T) {
tempDir, err := os.MkdirTemp("/tmp", "gtctl-ut-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
defer file.RemoveAll(tempDir)

m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
if err != nil {
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestDownloadChartsFromCNRegion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
defer file.RemoveAll(tempDir)

m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
if err != nil {
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestDownloadBinariesFromCNRegion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
defer file.RemoveAll(tempDir)

m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
if err != nil {
Expand Down Expand Up @@ -171,7 +172,7 @@ func TestDownloadBinaries(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
defer file.RemoveAll(tempDir)

m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
if err != nil {
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestArtifactsCache(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)
defer file.RemoveAll(tempDir)

m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
if err != nil {
Expand Down
13 changes: 3 additions & 10 deletions pkg/cluster/baremetal/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Cluster struct {
config *config.BareMetalClusterConfig
createNoDirs bool
enableCache bool
useMemoryMeta bool

am artifacts.Manager
mm metadata.Manager
Expand All @@ -55,9 +54,9 @@ type ClusterComponents struct {
}

func NewClusterComponents(config *config.BareMetalClusterComponentsConfig, workingDirs components.WorkingDirs,
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) *ClusterComponents {
wg *sync.WaitGroup, logger logger.Logger) *ClusterComponents {
return &ClusterComponents{
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger, useMemoryMeta),
MetaSrv: components.NewMetaSrv(config.MetaSrv, workingDirs, wg, logger),
Datanode: components.NewDataNode(config.Datanode, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
Frontend: components.NewFrontend(config.Frontend, config.MetaSrv.ServerAddr, workingDirs, wg, logger),
Etcd: components.NewEtcd(workingDirs, wg, logger),
Expand Down Expand Up @@ -85,12 +84,6 @@ func WithEnableCache(enableCache bool) Option {
}
}

func WithMetastore(useMemoryMeta bool) Option {
return func(c *Cluster) {
c.useMemoryMeta = useMemoryMeta
}
}

func WithCreateNoDirs() Option {
return func(c *Cluster) {
c.createNoDirs = true
Expand Down Expand Up @@ -143,7 +136,7 @@ func NewCluster(l logger.Logger, clusterName string, opts ...Option) (cluster.Op
DataDir: csd.DataDir,
LogsDir: csd.LogsDir,
PidsDir: csd.PidsDir,
}, &c.wg, c.logger, c.useMemoryMeta)
}, &c.wg, c.logger)

return c, nil
}
2 changes: 1 addition & 1 deletion pkg/cluster/baremetal/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *Cluster) Create(ctx context.Context, options *opt.CreateOptions) error
return nil
}

if !c.useMemoryMeta {
if c.config.Etcd != nil {
if err := withSpinner("Etcd Cluster", c.createEtcdCluster); err != nil {
return err
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/components/metasrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net"
"net/http"
"path"
"strconv"
"sync"
"time"

Expand All @@ -37,19 +36,17 @@ type metaSrv struct {
workingDirs WorkingDirs
wg *sync.WaitGroup
logger logger.Logger
useMemoryMeta bool

allocatedDirs
}

func NewMetaSrv(config *config.MetaSrv, workingDirs WorkingDirs,
wg *sync.WaitGroup, logger logger.Logger, useMemoryMeta bool) ClusterComponent {
wg *sync.WaitGroup, logger logger.Logger) ClusterComponent {
return &metaSrv{
config: config,
workingDirs: workingDirs,
wg: wg,
logger: logger,
useMemoryMeta: useMemoryMeta,
}
}

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

if m.useMemoryMeta {
useMemoryMeta := strconv.FormatBool(m.useMemoryMeta)
args = GenerateAddrArg("--use-memory-store", useMemoryMeta, nodeID, args)
}

if len(m.config.Config) > 0 {
args = append(args, fmt.Sprintf("-c=%s", m.config.Config))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type BareMetalClusterMetadata struct {
// Each field of BareMetalClusterConfig can also have its own exported method `Validate`.
type BareMetalClusterConfig struct {
Cluster *BareMetalClusterComponentsConfig `yaml:"cluster" validate:"required"`
Etcd *Etcd `yaml:"etcd" validate:"required"`
Etcd *Etcd `yaml:"etcd"`
}

type BareMetalClusterComponentsConfig struct {
Expand Down
Loading