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

Upgrade Go version to v1.20 #2190

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
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
}
Comment on lines -62 to -74
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to replace the rand.Seed() function with another way since the rand.Seed() function is deprecated, as shown below.

Deprecated: Programs that call Seed and then expect a specific sequence of results from the global random source (using functions such as Int) can be broken when a dependency changes how much it consumes from the global random source. To avoid such breakages, programs that need a specific result sequence should use NewRand(NewSource(seed)) to obtain a random generator that other packages cannot access.

https://pkg.go.dev/math/rand#Seed

However, I don't think we need to set the global random seed to the same value every run since we don't use random values anywhere, as I can see. So, I removed this.

@andreyvelich @johnugeorge WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why did we set these values.
@gaocegege @johnugeorge Do you have any context ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreyvelich As I can see, I can not find any context for this random number by git blame.
It seems that this was copied from https://github.com/mlkube/katib/blob/0bed55aae3cfddf255e6d297e31d1fedbe5dca4a/db/interface.go#L65-L67 to here.


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