From 6341bce175c4d96e27be8657be71a34590666535 Mon Sep 17 00:00:00 2001 From: Yuki Iwai Date: Wed, 2 Aug 2023 05:44:50 +0900 Subject: [PATCH] Upgrade Go version to v1.20 Signed-off-by: Yuki Iwai --- Makefile | 2 +- docs/developer-guide.md | 2 +- go.mod | 2 +- hack/verify-golangci-lint.sh | 2 +- pkg/db/v1beta1/mysql/mysql.go | 19 +------------------ pkg/db/v1beta1/mysql/mysql_test.go | 5 +---- pkg/db/v1beta1/postgres/postgres.go | 19 +------------------ pkg/db/v1beta1/postgres/postgres_test.go | 5 +---- 8 files changed, 8 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 2988ac08e59..523fe44dfe6 100755 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ fmt: lint: ifndef HAS_LINT - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3 $(info "golangci-lint has been installed") endif hack/verify-golangci-lint.sh diff --git a/docs/developer-guide.md b/docs/developer-guide.md index 88f3333f9c3..da7a010c868 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -12,7 +12,7 @@ see the following user guides: ## Requirements -- [Go](https://golang.org/) (1.19 or later) +- [Go](https://golang.org/) (1.20 or later) - [Docker](https://docs.docker.com/) (20.10 or later) - [Docker Buildx](https://docs.docker.com/build/buildx/) (0.8.0 or later) - [Java](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html) (8 or later) diff --git a/go.mod b/go.mod index d17aca07349..b36d3a7d8fa 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kubeflow/katib -go 1.19 +go 1.20 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 4a8a440aecc..5ba7a167f26 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -25,4 +25,4 @@ if [ -z "$(command -v golangci-lint)" ]; then fi echo 'Running golangci-lint' -golangci-lint run --timeout 5m --go 1.19 +golangci-lint run --timeout 5m --go 1.20 diff --git a/pkg/db/v1beta1/mysql/mysql.go b/pkg/db/v1beta1/mysql/mysql.go index 4fe863e8b47..b17aee8705f 100644 --- a/pkg/db/v1beta1/mysql/mysql.go +++ b/pkg/db/v1beta1/mysql/mysql.go @@ -17,11 +17,8 @@ limitations under the License. package mysql import ( - crand "crypto/rand" "database/sql" "fmt" - "math/big" - "math/rand" "os" "time" @@ -59,26 +56,12 @@ func getDbName() string { return fmt.Sprintf(dbNameTmpl, dbUser, dbPass, dbHost, dbPort, dbName) } -func NewWithSQLConn(db *sql.DB) (common.KatibDBInterface, error) { - d := new(dbConn) - d.db = db - seed, err := crand.Int(crand.Reader, big.NewInt(1<<63-1)) - if err != nil { - return nil, fmt.Errorf("RNG initialization failed: %v", err) - } - // We can do the following instead, but it creates a locking issue - //d.rng = rand.New(rand.NewSource(seed.Int64())) - rand.Seed(seed.Int64()) - - return d, nil -} - func NewDBInterface(connectTimeout time.Duration) (common.KatibDBInterface, error) { db, err := common.OpenSQLConn(dbDriver, getDbName(), common.ConnectInterval, connectTimeout) if err != nil { return nil, fmt.Errorf("DB open failed: %v", err) } - return NewWithSQLConn(db) + return &dbConn{db: db}, nil } func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta1.ObservationLog) error { diff --git a/pkg/db/v1beta1/mysql/mysql_test.go b/pkg/db/v1beta1/mysql/mysql_test.go index 8d95446531f..f22df6cb896 100644 --- a/pkg/db/v1beta1/mysql/mysql_test.go +++ b/pkg/db/v1beta1/mysql/mysql_test.go @@ -38,10 +38,7 @@ func TestMain(m *testing.M) { fmt.Printf("error opening db: %v\n", err) os.Exit(1) } - dbInterface, err = NewWithSQLConn(db) - if err != nil { - fmt.Printf("error NewWithSQLConn: %v\n", err) - } + dbInterface = &dbConn{db: db} mock.ExpectExec("CREATE TABLE IF NOT EXISTS observation_logs").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1)) dbInterface.DBInit() err = dbInterface.SelectOne() diff --git a/pkg/db/v1beta1/postgres/postgres.go b/pkg/db/v1beta1/postgres/postgres.go index 587f973c301..c89a9598636 100644 --- a/pkg/db/v1beta1/postgres/postgres.go +++ b/pkg/db/v1beta1/postgres/postgres.go @@ -17,11 +17,8 @@ limitations under the License. package postgres import ( - crand "crypto/rand" "database/sql" "fmt" - "math/big" - "math/rand" "os" "time" @@ -64,21 +61,7 @@ func NewDBInterface(connectTimeout time.Duration) (common.KatibDBInterface, erro if err != nil { return nil, fmt.Errorf("DB open failed: %v", err) } - return NewWithSQLConn(db) -} - -func NewWithSQLConn(db *sql.DB) (common.KatibDBInterface, error) { - d := new(dbConn) - d.db = db - seed, err := crand.Int(crand.Reader, big.NewInt(1<<63-1)) - if err != nil { - return nil, fmt.Errorf("RNG initialization failed: %v", err) - } - // We can do the following instead, but it creates a locking issue - //d.rng = rand.New(rand.NewSource(seed.Int64())) - rand.Seed(seed.Int64()) - - return d, nil + return &dbConn{db: db}, nil } func (d *dbConn) RegisterObservationLog(trialName string, observationLog *v1beta1.ObservationLog) error { diff --git a/pkg/db/v1beta1/postgres/postgres_test.go b/pkg/db/v1beta1/postgres/postgres_test.go index bf6c4191b91..e4bba33164b 100644 --- a/pkg/db/v1beta1/postgres/postgres_test.go +++ b/pkg/db/v1beta1/postgres/postgres_test.go @@ -38,10 +38,7 @@ func TestMain(m *testing.M) { fmt.Printf("error opening db: %v\n", err) os.Exit(1) } - dbInterface, err = NewWithSQLConn(db) - if err != nil { - fmt.Printf("error NewWithSQLConn: %v\n", err) - } + dbInterface = &dbConn{db: db} mock.ExpectExec("CREATE TABLE IF NOT EXISTS observation_logs").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1)) dbInterface.DBInit() mock.ExpectExec("SELECT 1").WithArgs().WillReturnResult(sqlmock.NewResult(1, 1))