From 5b52bc6225d5759757a54d3f4fa3004ead45e6eb Mon Sep 17 00:00:00 2001 From: Lionel Jouin Date: Mon, 26 Jun 2023 16:13:04 +0200 Subject: [PATCH] Update to go 1.20 Signed-off-by: Lionel Jouin --- .golangci.yml | 14 ++-- go.mod | 12 +-- go.sum | 20 ++--- .../common/resetmechanism/gen.go | 25 ------ .../resetmechanism/mechanism_map.gen.go | 77 ------------------- .../common/resetmechanism/server.go | 6 +- .../common/token/multitoken/common.go | 5 +- pkg/sriov/pcifunction/function.go | 9 ++- pkg/sriov/pcifunction/physical_function.go | 5 +- pkg/sriov/pcifunction/tools.go | 5 +- pkg/tools/cgroup/cgroup.go | 5 +- pkg/tools/cgroup/cgroup_test.go | 5 +- pkg/tools/cgroup/file_api.go | 3 +- pkg/tools/yamlhelper/yaml_helper.go | 6 +- 14 files changed, 45 insertions(+), 152 deletions(-) delete mode 100644 pkg/networkservice/common/resetmechanism/gen.go delete mode 100644 pkg/networkservice/common/resetmechanism/mechanism_map.gen.go diff --git a/.golangci.yml b/.golangci.yml index 8d8e7b20..8d9897df 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,7 +4,7 @@ run: timeout: 2m issues-exit-code: 1 tests: true - go: "1.17" + go: "1.20" linters-settings: goheader: template-path: ".ci/license/template.txt" @@ -42,13 +42,11 @@ linters-settings: min-len: 2 min-occurrences: 2 depguard: - list-type: blacklist - include-go-root: false - packages: - - errors - packages-with-error-message: - # specify an error message to output when a blacklisted package is used - - errors: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" + rules: + main: + deny: + - pkg: "errors" + desc: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports" misspell: locale: US unparam: diff --git a/go.mod b/go.mod index 31ffc7d5..44b0aec2 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ module github.com/networkservicemesh/sdk-sriov -go 1.18 +go 1.20 require ( + github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 github.com/ghodss/yaml v1.0.0 github.com/golang/protobuf v1.5.2 github.com/google/uuid v1.2.0 @@ -12,7 +13,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.0 go.uber.org/goleak v1.1.12 - golang.org/x/sys v0.5.0 + golang.org/x/sys v0.9.0 google.golang.org/grpc v1.49.0 ) @@ -23,7 +24,6 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/edwarnicke/exechelper v1.0.2 // indirect - github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 // indirect github.com/edwarnicke/grpcfd v1.1.2 // indirect github.com/edwarnicke/serialize v1.0.7 // indirect github.com/go-logr/logr v1.2.3 // indirect @@ -57,9 +57,9 @@ require ( go.opentelemetry.io/otel/sdk/metric v0.31.0 // indirect go.opentelemetry.io/otel/trace v1.9.0 // indirect go.opentelemetry.io/proto/otlp v0.19.0 // indirect - golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/crypto v0.10.0 // indirect + golang.org/x/net v0.11.0 // indirect + golang.org/x/text v0.10.0 // indirect google.golang.org/genproto v0.0.0-20220908141613-51c1cc9bc6d0 // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect diff --git a/go.sum b/go.sum index b02c835f..4ffc122c 100644 --- a/go.sum +++ b/go.sum @@ -281,8 +281,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -315,7 +315,7 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -343,8 +343,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -391,8 +391,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -400,8 +400,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -447,7 +447,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/networkservice/common/resetmechanism/gen.go b/pkg/networkservice/common/resetmechanism/gen.go deleted file mode 100644 index 27ee95ec..00000000 --- a/pkg/networkservice/common/resetmechanism/gen.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// 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 resetmechanism - -import ( - "sync" -) - -//go:generate go-syncmap -output mechanism_map.gen.go -type mechanismMap - -type mechanismMap sync.Map diff --git a/pkg/networkservice/common/resetmechanism/mechanism_map.gen.go b/pkg/networkservice/common/resetmechanism/mechanism_map.gen.go deleted file mode 100644 index a18df77e..00000000 --- a/pkg/networkservice/common/resetmechanism/mechanism_map.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output mechanism_map.gen.go -type mechanismMap -output mechanism_map.gen.go -type mechanismMap"; DO NOT EDIT. -// Install -output mechanism_map.gen.go -type mechanismMap by "go get -u github.com/searKing/golang/tools/-output mechanism_map.gen.go -type mechanismMap" - -package resetmechanism - -import ( - "sync" // Used by sync.Map. - - "github.com/networkservicemesh/api/pkg/api/networkservice" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert mechanismMap literal (type mechanismMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(mechanismMap{}) -} - -var _nil_mechanismMap_networkservice_Mechanism_value = func() (val *networkservice.Mechanism) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *mechanismMap) Load(key string) (*networkservice.Mechanism, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, ok - } - return value.(*networkservice.Mechanism), ok -} - -// Store sets the value for a key. -func (m *mechanismMap) Store(key string, value *networkservice.Mechanism) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *mechanismMap) LoadOrStore(key string, value *networkservice.Mechanism) (*networkservice.Mechanism, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, loaded - } - return actual.(*networkservice.Mechanism), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *mechanismMap) LoadAndDelete(key string) (value *networkservice.Mechanism, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, loaded - } - return actual.(*networkservice.Mechanism), loaded -} - -// Delete deletes the value for a key. -func (m *mechanismMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *mechanismMap) Range(f func(key string, value *networkservice.Mechanism) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*networkservice.Mechanism)) - }) -} diff --git a/pkg/networkservice/common/resetmechanism/server.go b/pkg/networkservice/common/resetmechanism/server.go index fbfd618c..78e74893 100644 --- a/pkg/networkservice/common/resetmechanism/server.go +++ b/pkg/networkservice/common/resetmechanism/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. +// Copyright (c) 2023 Doc.ai and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -20,6 +20,7 @@ package resetmechanism import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" @@ -29,13 +30,14 @@ import ( type resetMechanismServer struct { wrappedServer networkservice.NetworkServiceServer - mechanisms mechanismMap + mechanisms *genericsync.Map[string, *networkservice.Mechanism] } // NewServer returns a new reset mechanism server chain element func NewServer(wrappedServer networkservice.NetworkServiceServer) networkservice.NetworkServiceServer { return &resetMechanismServer{ wrappedServer: wrappedServer, + mechanisms: &genericsync.Map[string, *networkservice.Mechanism]{}, } } diff --git a/pkg/networkservice/common/token/multitoken/common.go b/pkg/networkservice/common/token/multitoken/common.go index c1e6147c..7c210ebf 100644 --- a/pkg/networkservice/common/token/multitoken/common.go +++ b/pkg/networkservice/common/token/multitoken/common.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Nordix Foundation. +// Copyright (c) 2021-2023 Nordix Foundation. // // SPDX-License-Identifier: Apache-2.0 // @@ -58,9 +58,8 @@ func (c *tokenElement) assign(tokenName string, conn *networkservice.Connection) c.connectionsByTokens[tokenID] = conn.GetId() c.tokensByConnections[conn.GetId()] = tokenID break - } else { - tokenID = "" } + tokenID = "" } return } diff --git a/pkg/sriov/pcifunction/function.go b/pkg/sriov/pcifunction/function.go index 61222063..607e20c8 100644 --- a/pkg/sriov/pcifunction/function.go +++ b/pkg/sriov/pcifunction/function.go @@ -19,7 +19,8 @@ package pcifunction import ( - "io/ioutil" + "os" + "path" "path/filepath" "strconv" @@ -49,7 +50,7 @@ func (f *Function) GetPCIAddress() string { // GetNetInterfaceName returns f net interface name func (f *Function) GetNetInterfaceName() (string, error) { - fInfos, err := ioutil.ReadDir(f.withDevicePath(netInterfacesPath)) + fInfos, err := os.ReadDir(f.withDevicePath(netInterfacesPath)) if err != nil { return "", errors.Wrapf(err, "failed to read net directory for the device: %v", f.address) } @@ -104,7 +105,7 @@ func (f *Function) BindDriver(driver string) error { return nil case boundDriver != "": unbindPath := f.withDevicePath(boundDriverPath, unbindDriverPath) - if err := ioutil.WriteFile(unbindPath, []byte(f.address), 0); err != nil { + if err := os.WriteFile(unbindPath, []byte(f.address), 0); err != nil { return errors.Wrapf(err, "failed to unbind driver from the device: %v", f.address) } } @@ -112,7 +113,7 @@ func (f *Function) BindDriver(driver string) error { // For some reasons write to the driver/bind file fails but binds the driver to the PCI function // so we ignore error and simply compare the bound driver with the given one bindPath := filepath.Join(f.pciDriversPath, driver, bindDriverPath) - err := ioutil.WriteFile(bindPath, []byte(f.address), 0) + err := os.WriteFile(bindPath, []byte(f.address), 0) if boundDriver, _ := f.GetBoundDriver(); boundDriver != driver { return errors.Wrapf(err, "failed to bind the driver to the device: %v %v", f.address, driver) } diff --git a/pkg/sriov/pcifunction/physical_function.go b/pkg/sriov/pcifunction/physical_function.go index abb31c5a..916b44f4 100644 --- a/pkg/sriov/pcifunction/physical_function.go +++ b/pkg/sriov/pcifunction/physical_function.go @@ -20,7 +20,6 @@ package pcifunction import ( - "io/ioutil" "os" "path/filepath" "regexp" @@ -104,12 +103,12 @@ func (pf *PhysicalFunction) createVirtualFunctions() error { return nil } - vfsCount, err := ioutil.ReadFile(pf.withDevicePath(totalVFFile)) + vfsCount, err := os.ReadFile(pf.withDevicePath(totalVFFile)) if err != nil { return errors.Wrapf(err, "failed to get available VFs number for the PCI device: %v", pf.address) } - err = ioutil.WriteFile(pf.withDevicePath(configuredVFFile), vfsCount, 0) + err = os.WriteFile(pf.withDevicePath(configuredVFFile), vfsCount, 0) if err != nil { return errors.Wrapf(err, "failed to create VFs for the PCI device: %v", pf.address) } diff --git a/pkg/sriov/pcifunction/tools.go b/pkg/sriov/pcifunction/tools.go index ab7c7678..9ef16c79 100644 --- a/pkg/sriov/pcifunction/tools.go +++ b/pkg/sriov/pcifunction/tools.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. +// Copyright (c) 2023 Doc.ai and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -17,7 +17,6 @@ package pcifunction import ( - "io/ioutil" "os" "path/filepath" "strconv" @@ -32,7 +31,7 @@ func isFileExists(path string) bool { } func readUintFromFile(path string) (uint, error) { - data, err := ioutil.ReadFile(filepath.Clean(path)) + data, err := os.ReadFile(filepath.Clean(path)) if err != nil { return 0, errors.Wrapf(err, "unable to locate file: %v", path) } diff --git a/pkg/tools/cgroup/cgroup.go b/pkg/tools/cgroup/cgroup.go index cf93618e..d9b5b081 100644 --- a/pkg/tools/cgroup/cgroup.go +++ b/pkg/tools/cgroup/cgroup.go @@ -23,7 +23,6 @@ package cgroup import ( "bufio" - "io/ioutil" "os" "path/filepath" "reflect" @@ -63,7 +62,7 @@ func (c *Cgroup) Allow(major, minor uint32) error { dev := newDevice(major, minor, 'r', 'w', 'm') filePath := filepath.Join(c.Path, deviceAllowFileName) - if err := ioutil.WriteFile(filePath, []byte(dev.String()), 0); err != nil { + if err := os.WriteFile(filePath, []byte(dev.String()), 0); err != nil { return errors.Wrapf(err, "failed to write to a %s", filePath) } @@ -75,7 +74,7 @@ func (c *Cgroup) Deny(major, minor uint32) error { dev := newDevice(major, minor, 'r', 'w') filePath := filepath.Join(c.Path, deviceAllowFileName) - if err := ioutil.WriteFile(filePath, []byte(dev.String()), 0); err != nil { + if err := os.WriteFile(filePath, []byte(dev.String()), 0); err != nil { return errors.Wrapf(err, "failed to write to a %s", filePath) } diff --git a/pkg/tools/cgroup/cgroup_test.go b/pkg/tools/cgroup/cgroup_test.go index e8cd6abe..c344df9b 100644 --- a/pkg/tools/cgroup/cgroup_test.go +++ b/pkg/tools/cgroup/cgroup_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Doc.ai and/or its affiliates. +// Copyright (c) 2021-2023 Doc.ai and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -20,7 +20,6 @@ package cgroup_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -116,7 +115,7 @@ func TestCgroup_IsWiderThan(t *testing.T) { for i := range samples { sample := samples[i] t.Run(sample.name, func(t *testing.T) { - err := ioutil.WriteFile(filepath.Join(tmpDir, deviceListFileName), []byte(sample.device), 0) + err := os.WriteFile(filepath.Join(tmpDir, deviceListFileName), []byte(sample.device), 0) require.NoError(t, err) isWider, err := cg.IsWiderThan(1, 2) diff --git a/pkg/tools/cgroup/file_api.go b/pkg/tools/cgroup/file_api.go index 405a548a..512b596b 100644 --- a/pkg/tools/cgroup/file_api.go +++ b/pkg/tools/cgroup/file_api.go @@ -24,7 +24,6 @@ package cgroup import ( "bufio" "context" - "io/ioutil" "os" "github.com/pkg/errors" @@ -82,7 +81,7 @@ type supplierFunc func(s string) error func outputFileAPI(filePath string) (supplier supplierFunc) { supplier = func(data string) error { - if err := ioutil.WriteFile(filePath, []byte(data), createPerm); err != nil { + if err := os.WriteFile(filePath, []byte(data), createPerm); err != nil { return errors.Wrapf(err, "failed to write to a %s", filePath) } return nil diff --git a/pkg/tools/yamlhelper/yaml_helper.go b/pkg/tools/yamlhelper/yaml_helper.go index 7611d9bc..a7808ccb 100644 --- a/pkg/tools/yamlhelper/yaml_helper.go +++ b/pkg/tools/yamlhelper/yaml_helper.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. +// Copyright (c) 2023 Doc.ai and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -18,7 +18,7 @@ package yamlhelper import ( - "io/ioutil" + "os" "path" "github.com/ghodss/yaml" @@ -27,7 +27,7 @@ import ( // UnmarshalFile unmarshal YAML file into the object func UnmarshalFile(fileName string, o interface{}) error { - bytes, err := ioutil.ReadFile(path.Clean(fileName)) + bytes, err := os.ReadFile(path.Clean(fileName)) if err != nil { return errors.Wrapf(err, "error reading file: %v", fileName) }