From 830f413ca85331ae65efc41d87df49eaaa39bfd5 Mon Sep 17 00:00:00 2001 From: Andre Sterba <andre.sterba@stud.h-da.de> Date: Thu, 27 Jul 2023 12:06:03 +0000 Subject: [PATCH] Update mongo driver and fix deprecations See merge request danet/gosdn!495 --- Makefile | 17 ++++++++++++----- controller/nucleus/database/mongo-connection.go | 9 ++------- .../nucleus/databaseNetworkElementStore.go | 3 ++- controller/rbac/databaseUserStore.go | 2 +- controller/topology/nodes/nodeStore.go | 2 +- go.mod | 6 +++--- go.sum | 7 +++++++ 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index cae9f0788..c528eaebf 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,13 @@ BUILD_ARTIFACTS_PATH=artifacts PLUGIN_NAME= bundled_plugin.zip +# Tool Versions +GOTESTSUM_VERSION=v1.8.1 +GOLANGCI_LINT_VERSION=v1.53.3 +MOCKERY_VERSION=v2.20.0 +YGOT_GENERATOR_VERSION=v0.27.0 +YGOT_GENERATOR_GENERATOR_VERSION=v0.0.4 + all: build pre: @@ -28,11 +35,11 @@ create-clab-dir: create-gosdn-tmp-dir install-tools: @echo Install development tooling mkdir -p $(GOSDN_PRG) - export GOBIN=$(GOSDN_PRG) && go install gotest.tools/gotestsum@v1.8.1 &&\ - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 &&\ - go install github.com/vektra/mockery/v2@v2.20.0 &&\ - go install github.com/openconfig/ygot/generator@v0.27.0 &&\ - go install github.com/andresterba/go-ygot-generator-generator@v0.0.4 + export GOBIN=$(GOSDN_PRG) && go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION) &&\ + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) &&\ + go install github.com/vektra/mockery/v2@$(MOCKERY_VERSION) &&\ + go install github.com/openconfig/ygot/generator@$(YGOT_GENERATOR_VERSION) &&\ + go install github.com/andresterba/go-ygot-generator-generator@$(YGOT_GENERATOR_GENERATOR_VERSION) @echo Finished installing development tooling ci-install-tools: diff --git a/controller/nucleus/database/mongo-connection.go b/controller/nucleus/database/mongo-connection.go index 96520f53d..8e4bde620 100644 --- a/controller/nucleus/database/mongo-connection.go +++ b/controller/nucleus/database/mongo-connection.go @@ -20,16 +20,11 @@ const ( // GetMongoConnection Retrieves a client to the MongoDB. func GetMongoConnection() (*mongo.Client, context.Context, context.CancelFunc) { mongoConnection := config.DatabaseConnection - client, err := mongo.NewClient(options.Client().ApplyURI(mongoConnection)) - if err != nil { - log.Printf("Failed to create client: %v", err) - } - ctx, cancel := context.WithTimeout(context.Background(), connectTimeout*time.Second) - err = client.Connect(ctx) + client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoConnection)) if err != nil { - log.Printf("Failed to connect to cluster: %v", err) + log.Printf("Failed to create client: %v", err) } // Force a connection to verify our connection string diff --git a/controller/nucleus/databaseNetworkElementStore.go b/controller/nucleus/databaseNetworkElementStore.go index f2192be58..be64919a6 100644 --- a/controller/nucleus/databaseNetworkElementStore.go +++ b/controller/nucleus/databaseNetworkElementStore.go @@ -171,7 +171,8 @@ func (s *DatabaseNetworkElementStore) Update(networkElementToUpdate networkeleme }() // 1. Start Transaction - wcMajority := writeconcern.New(writeconcern.WMajority()) + wcMajority := writeconcern.Majority() + wcMajorityCollectionOpts := options.Collection().SetWriteConcern(wcMajority) userCollection := client.Database(database.DatabaseName).Collection(s.storeName, wcMajorityCollectionOpts) diff --git a/controller/rbac/databaseUserStore.go b/controller/rbac/databaseUserStore.go index da455a860..42451c646 100644 --- a/controller/rbac/databaseUserStore.go +++ b/controller/rbac/databaseUserStore.go @@ -189,7 +189,7 @@ func (s *DatabaseUserStore) Update(userToUpdate rbac.User) (err error) { }() // 1. Start Transaction - wcMajority := writeconcern.New(writeconcern.WMajority()) + wcMajority := writeconcern.Majority() wcMajorityCollectionOpts := options.Collection().SetWriteConcern(wcMajority) userCollection := client.Database(database.DatabaseName).Collection(s.userStoreName, wcMajorityCollectionOpts) diff --git a/controller/topology/nodes/nodeStore.go b/controller/topology/nodes/nodeStore.go index f5bb7f4c7..f6f637e94 100644 --- a/controller/topology/nodes/nodeStore.go +++ b/controller/topology/nodes/nodeStore.go @@ -181,7 +181,7 @@ func (s *DatabaseNodeStore) Update(node Node) (err error) { }() // 1. Start Transaction - wcMajority := writeconcern.New(writeconcern.WMajority()) + wcMajority := writeconcern.Majority() wcMajorityCollectionOpts := options.Collection().SetWriteConcern(wcMajority) nodeCollection := client.Database(database.DatabaseName).Collection(s.storeName, wcMajorityCollectionOpts) diff --git a/go.mod b/go.mod index 3a0804bc6..ac699a4b3 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/spf13/viper v1.15.0 github.com/stretchr/objx v0.5.0 // indirect github.com/stretchr/testify v1.8.1 - go.mongodb.org/mongo-driver v1.10.0 + go.mongodb.org/mongo-driver v1.12.0 golang.org/x/sync v0.1.0 google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 google.golang.org/grpc v1.53.0 @@ -81,8 +81,8 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect go.opencensus.io v0.24.0 // indirect diff --git a/go.sum b/go.sum index 7c2894961..5044c8e70 100644 --- a/go.sum +++ b/go.sum @@ -985,8 +985,12 @@ github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= @@ -1021,6 +1025,8 @@ go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD0 go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4= go.mongodb.org/mongo-driver v1.10.0 h1:UtV6N5k14upNp4LTduX0QCufG124fSu25Wz9tu94GLg= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= +go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE= +go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0= go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -1341,6 +1347,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 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.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -- GitLab