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: update ci and add some test for bare-metal #123

Merged
merged 8 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
41 changes: 37 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on: [push, pull_request]

jobs:
typos-check:
name: Spell Check with Typos
name: spell-typos-check
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v3
- name: Check spelling with custom config file
uses: crate-ci/[email protected]
build:
linter:
name: linter
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -27,10 +28,42 @@ jobs:
with:
version: v1.50.0
args: --timeout 10m0s
unit-test:
name: coverage-test
runs-on: ubuntu-latest
needs: [ linter ]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.18.4"

- name: unit test
- name: Unit test
run: |
make test
make coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ./coverage.xml
name: codecov-gtctl
verbose: true
e2e-test:
name: e2e-test
runs-on: ubuntu-latest
needs: [ linter ]
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.18.4"

- name: e2e test of basic cluster
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/license-checker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: License checker
name: License

on:
push:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pr-title-checker.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: PR Title Checker
name: Title

on: [pull_request]

jobs:
check:
name: pr-title-check
runs-on: ubuntu-latest
steps:
- uses: thehanimo/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
name: Build binary
name: build-binary
strategy:
matrix:
# The file format is gtctl-<os>-<arch>
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
path: bin/${{ matrix.file }}.sha256sum

release:
name: Release artifacts
name: release-artifacts
needs: [ build ]
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ testbin/*
.vscode

.gtctl
coverage.xml
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ e2e: gtctl setup-e2e ## Run e2e.
test: ## Run unit test.
go test -timeout 1m -v ./pkg/...

.PHONY: coverage
coverage: ## Run unit test with coverage.
go test ./pkg/... -race -coverprofile=coverage.xml -covermode=atomic

.PHONY: fix-license-header
fix-license-header: license-eye ## Fix license header.
license-eye -c .licenserc.yaml header fix
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gtctl

[![codecov](https://codecov.io/github/GreptimeTeam/gtctl/branch/main/graph/badge.svg?token=287NUSEH5D)](https://codecov.io/github/GreptimeTeam/gtctl)

## Overview

`gtctl`(`g-t-control`) is a command-line tool for managing the [GreptimeDB](https://github.com/GrepTimeTeam/greptimedb) cluster. `gtctl` is the **All-in-One** binary that integrates multiple operations of the GreptimeDB cluster.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/briandowns/spinner v1.19.0
github.com/fatih/color v1.13.0
github.com/go-pg/pg/v10 v10.11.1
github.com/go-playground/validator/v10 v10.14.1
github.com/go-sql-driver/mysql v1.6.0
github.com/google/go-cmp v0.5.9
Expand Down Expand Up @@ -62,7 +63,6 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-pg/pg/v10 v10.11.1 // indirect
github.com/go-pg/zerochecker v0.2.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,6 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -853,16 +851,12 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -875,8 +869,6 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
21 changes: 21 additions & 0 deletions pkg/deployer/baremetal/test_data/invalid_artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cluster:
name: mycluster # name of the cluster
artifact:
version: v0.2.0-nightly-20230403
frontend:
replicas: 1
datanode:
replicas: 3
rpcAddr: 0.0.0.0:14100
mysqlAddr: 0.0.0.0:14200
httpAddr: 0.0.0.0:14300
meta:
storeAddr: 127.0.0.1:2379
serverAddr: 0.0.0.0:3002
httpAddr: 0.0.0.0:14001

etcd:
artifact: # invalid artifact
version:
local:

19 changes: 19 additions & 0 deletions pkg/deployer/baremetal/test_data/invalid_hostname_port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cluster:
name: mycluster # name of the cluster
artifact:
version: v0.2.0-nightly-20230403
frontend:
replicas: 1
datanode:
replicas: 3
rpcAddr: 0.0.0.0:14100
mysqlAddr: 0.0.0.0:14200
httpAddr: 0.0.0.0:1438000 # invalid port
meta:
storeAddr: 127.0.0.1:2379
serverAddr: 6870.0.0.0:3243002 # invalid hostname and port
httpAddr: 0.0.0.0:14001

etcd:
artifact:
version: v3.5.7
19 changes: 19 additions & 0 deletions pkg/deployer/baremetal/test_data/invalid_replicas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cluster:
name: mycluster # name of the cluster
artifact:
version: v0.2.0-nightly-20230403
frontend:
replicas: 0 # invalid replicas
datanode:
replicas: -3 # invalid replicas
rpcAddr: 0.0.0.0:14100
mysqlAddr: 0.0.0.0:14200
httpAddr: 0.0.0.0:14300
meta:
storeAddr: 127.0.0.1:2379
serverAddr: 0.0.0.0:3002
httpAddr: 0.0.0.0:14001

etcd:
artifact:
version: v3.5.7
19 changes: 19 additions & 0 deletions pkg/deployer/baremetal/test_data/valid_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cluster:
name: mycluster # name of the cluster
artifact:
version: v0.2.0-nightly-20230403
frontend:
replicas: 1
datanode:
replicas: 3
rpcAddr: 0.0.0.0:14100
mysqlAddr: 0.0.0.0:14200
httpAddr: 0.0.0.0:14300
meta:
storeAddr: 127.0.0.1:2379
serverAddr: 0.0.0.0:3002
httpAddr: 0.0.0.0:14001

etcd:
artifact:
version: v3.5.7
93 changes: 93 additions & 0 deletions pkg/deployer/baremetal/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package baremetal

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"

"github.com/GreptimeTeam/gtctl/pkg/deployer/baremetal/config"
)

func TestValidateConfig(t *testing.T) {
testCases := []struct {
name string
expect bool
errKey []string
}{
{
name: "valid_config",
expect: true,
},
{
name: "invalid_hostname_port",
expect: false,
errKey: []string{
"Config.Cluster.MetaSrv.ServerAddr",
"Config.Cluster.Datanode.HTTPAddr",
},
},
{
name: "invalid_replicas",
expect: false,
errKey: []string{
"Config.Cluster.Frontend.Replicas",
"Config.Cluster.Datanode.Replicas",
},
},
{
name: "invalid_artifact",
expect: false,
errKey: []string{
"Config.Etcd.Artifact.Artifact",
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
var actual config.Config
if err := loadConfig(fmt.Sprintf("test_data/%s.yaml", tc.name), &actual); err != nil {
t.Errorf("error while loading %s file: %v", tc.name, err)
}

err := ValidateConfig(&actual)
if tc.expect {
assert.NoError(t, err)
} else {
assert.Error(t, err)
for _, key := range tc.errKey {
assert.Contains(t, err.Error(), key)
}
}
})
}
}

func loadConfig(path string, ret *config.Config) error {
configs, err := os.ReadFile(path)
if err != nil {
return err
}

if err = yaml.Unmarshal(configs, ret); err != nil {
return err
}
return nil
}
Loading