Skip to content

Commit 3ba2694

Browse files
authored
Merge pull request #64 from inteon/replace_deprecated
Replace deprecated functions and add missing error checks
2 parents 29e7318 + ffb1d38 commit 3ba2694

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

driver/controllerserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ limitations under the License.
1717
package driver
1818

1919
import (
20+
"context"
21+
2022
"github.com/container-storage-interface/spec/lib/go/csi"
21-
"golang.org/x/net/context"
2223
"google.golang.org/grpc/codes"
2324
"google.golang.org/grpc/status"
2425
)

driver/identityserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ limitations under the License.
1717
package driver
1818

1919
import (
20+
"context"
21+
2022
"github.com/container-storage-interface/spec/lib/go/csi"
21-
"golang.org/x/net/context"
2223
"google.golang.org/grpc/codes"
2324
"google.golang.org/grpc/status"
2425
)

driver/nodeserver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,18 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
111111
}
112112

113113
log.Info("Ensuring data directory for volume is mounted into pod...")
114-
notMnt, err := mount.IsNotMountPoint(ns.mounter, req.GetTargetPath())
114+
isMnt, err := ns.mounter.IsMountPoint(req.GetTargetPath())
115115
switch {
116116
case os.IsNotExist(err):
117117
if err := os.MkdirAll(req.GetTargetPath(), 0440); err != nil {
118118
return nil, err
119119
}
120-
notMnt = true
120+
isMnt = false
121121
case err != nil:
122122
return nil, err
123123
}
124124

125-
if !notMnt {
125+
if isMnt {
126126
// Nothing more to do if the targetPath is already a bind mount
127127
log.Info("Volume already mounted to pod, nothing to do")
128128
success = true
@@ -158,11 +158,12 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, request *csi.Node
158158
ns.manager.UnmanageVolume(request.GetVolumeId())
159159
log.Info("Stopped management of volume")
160160

161-
notMnt, err := mount.IsNotMountPoint(ns.mounter, request.GetTargetPath())
161+
isMnt, err := ns.mounter.IsMountPoint(request.GetTargetPath())
162162
if err != nil {
163163
return nil, err
164164
}
165-
if !notMnt {
165+
166+
if isMnt {
166167
if err := ns.mounter.Unmount(request.GetTargetPath()); err != nil {
167168
return nil, err
168169
}

driver/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package driver
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"net"
2223
"os"
@@ -25,12 +26,10 @@ import (
2526
"github.com/container-storage-interface/spec/lib/go/csi"
2627
"github.com/go-logr/logr"
2728
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
28-
"golang.org/x/net/context"
2929
"google.golang.org/grpc"
3030
)
3131

3232
type GRPCServer struct {
33-
log logr.Logger
3433
server *grpc.Server
3534
lis net.Listener
3635
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/go-logr/logr v1.3.0
99
github.com/kubernetes-csi/csi-lib-utils v0.15.0
1010
github.com/stretchr/testify v1.8.4
11-
golang.org/x/net v0.19.0
1211
google.golang.org/grpc v1.59.0
1312
k8s.io/apimachinery v0.28.4
1413
k8s.io/client-go v0.28.4
@@ -58,6 +57,7 @@ require (
5857
go.uber.org/zap v1.26.0 // indirect
5958
golang.org/x/crypto v0.16.0 // indirect
6059
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
60+
golang.org/x/net v0.19.0 // indirect
6161
golang.org/x/oauth2 v0.15.0 // indirect
6262
golang.org/x/sys v0.15.0 // indirect
6363
golang.org/x/term v0.15.0 // indirect

manager/manager.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func NewManager(opts Options) (*Manager, error) {
169169
// Fetch the lister before calling Start() to ensure this informer is
170170
// registered with the factory
171171
lister := informerFactory.Certmanager().V1().CertificateRequests().Lister()
172-
informerFactory.Certmanager().V1().CertificateRequests().Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
172+
if _, err := informerFactory.Certmanager().V1().CertificateRequests().Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
173173
DeleteFunc: func(obj interface{}) {
174174
requestToPrivateKeyLock.Lock()
175175
defer requestToPrivateKeyLock.Unlock()
@@ -190,7 +190,9 @@ func NewManager(opts Options) (*Manager, error) {
190190

191191
delete(requestToPrivateKeyMap, req.UID)
192192
},
193-
})
193+
}); err != nil {
194+
return nil, fmt.Errorf("failed to add event handler to CertificateRequest informer: %w", err)
195+
}
194196

195197
// create a stop channel that manages all sub goroutines
196198
stopCh := make(chan struct{})
@@ -720,7 +722,7 @@ func (m *Manager) submitRequest(ctx context.Context, meta metadata.Metadata, csr
720722
// This ensures callers that read from the lister/cache do not enter a confused state
721723
// where the CertificateRequest does not exist after calling submitRequest due to
722724
// cache timing issues.
723-
wait.PollUntilContextCancel(ctx, time.Millisecond*50, true, func(ctx context.Context) (bool, error) {
725+
if err := wait.PollUntilContextCancel(ctx, time.Millisecond*50, true, func(ctx context.Context) (bool, error) {
724726
_, err := m.lister.CertificateRequests(csrBundle.Namespace).Get(req.Name)
725727
if apierrors.IsNotFound(err) {
726728
return false, nil
@@ -729,7 +731,9 @@ func (m *Manager) submitRequest(ctx context.Context, meta metadata.Metadata, csr
729731
return false, err
730732
}
731733
return true, nil
732-
})
734+
}); err != nil {
735+
return nil, fmt.Errorf("waiting for CertificateRequest to be observed by lister: %w", err)
736+
}
733737

734738
return req, nil
735739
}

storage/filesystem.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"encoding/json"
2121
"errors"
2222
"fmt"
23+
"io"
2324
"io/fs"
24-
"io/ioutil"
2525
"os"
2626
"path/filepath"
2727
"strconv"
@@ -74,7 +74,7 @@ func NewFilesystem(log logr.Logger, baseDir string) (*Filesystem, error) {
7474
fs: os.DirFS("/").(fs.StatFS),
7575
}
7676

77-
notMnt, err := mount.IsNotMountPoint(mount.New(""), f.tempfsPath())
77+
isMnt, err := mount.New("").IsMountPoint(f.tempfsPath())
7878
if err != nil {
7979
if !os.IsNotExist(err) {
8080
return nil, err
@@ -84,7 +84,7 @@ func NewFilesystem(log logr.Logger, baseDir string) (*Filesystem, error) {
8484
}
8585
}
8686

87-
if notMnt {
87+
if !isMnt {
8888
if err := mount.New("").Mount("tmpfs", f.tempfsPath(), "tmpfs", []string{}); err != nil {
8989
return nil, fmt.Errorf("mounting tmpfs: %w", err)
9090
}
@@ -290,7 +290,7 @@ func (f *Filesystem) ReadFile(volumeID, name string) ([]byte, error) {
290290
}
291291
defer file.Close()
292292

293-
return ioutil.ReadAll(file)
293+
return io.ReadAll(file)
294294
}
295295

296296
// metadataPathForVolumeID returns the metadata.json path for the volume with

0 commit comments

Comments
 (0)