Skip to content

Commit

Permalink
Upgrade Go version to v1.20 (#2190)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <[email protected]>
  • Loading branch information
tenzen-y authored Aug 3, 2023
1 parent c731fd2 commit 74cf5b8
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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/kubeflow/katib

go 1.19
go 1.20

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 1 addition & 18 deletions pkg/db/v1beta1/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ limitations under the License.
package mysql

import (
crand "crypto/rand"
"database/sql"
"fmt"
"math/big"
"math/rand"
"os"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions pkg/db/v1beta1/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 1 addition & 18 deletions pkg/db/v1beta1/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ limitations under the License.
package postgres

import (
crand "crypto/rand"
"database/sql"
"fmt"
"math/big"
"math/rand"
"os"
"time"

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions pkg/db/v1beta1/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 74cf5b8

Please sign in to comment.