Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 506dd87

Browse files
committed
Fix excessive io around volume cleanup, move cleanup logic to startup rather than run each volume deprovision
Signed-off-by: Cameron McAvoy <[email protected]>
1 parent a5b4907 commit 506dd87

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.4.1] - 2024-08-19
10+
### Fixed
11+
- Fixed volume cleanup to only run at startup, reducing io when many mounts are used
12+
913
## [0.4.0] - 2024-08-07
1014
### Fixed
1115
- Fixed locking behavior with volumes, terminating pods could fail to be cleaned up due to a race in the locks.

Diff for: pkg/ccm/cleanup.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import (
1111
"k8s.io/mount-utils"
1212
)
1313

14-
func doCleanup(configMap, volumeID, targetPath string) {
14+
func doCleanup() {
1515
start := time.Now()
1616
if err := cleanupDataDir(); err != nil {
17-
logger.Error(err, fmt.Sprintf("failed to cleanup on node unpublish volume for volume id %q and target path %q", volumeID, targetPath))
18-
unpublishErr.WithLabelValues(configMap, "failed to clean up volume data").Inc()
17+
logger.Error(err, "failed to cleanup")
1918
}
2019
if err := cleanupMetadataDir(); err != nil {
21-
logger.Error(err, fmt.Sprintf("failed to cleanup metadata on node unpublish volume for volume id %q and target path %q", volumeID, targetPath))
22-
unpublishErr.WithLabelValues(configMap, "failed to clean up volume metadata").Inc()
20+
logger.Error(err, "failed to cleanup metadata")
2321
}
2422
cleanupTime.WithLabelValues().Observe(time.Since(start).Seconds())
2523
}
@@ -32,6 +30,10 @@ func cleanupDataDir() error {
3230
dataDir := path.Join(storageDir, "data")
3331
dirEntries, err := os.ReadDir(dataDir)
3432
if err != nil {
33+
if os.IsNotExist(err) {
34+
logger.Info("[cleanup] no data dir, skipping cleanup")
35+
return nil
36+
}
3537
return fmt.Errorf("failed to list dir entries for %q: %w", dataDir, err)
3638
}
3739

Diff for: pkg/ccm/driver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"sync"
1212

1313
"github.com/container-storage-interface/spec/lib/go/csi"
14-
1514
"google.golang.org/grpc"
1615

1716
"k8s.io/client-go/kubernetes"
@@ -100,6 +99,8 @@ func (d *driver) Run() error {
10099
return resp, err
101100
}
102101

102+
doCleanup()
103+
103104
d.srv = grpc.NewServer(grpc.UnaryInterceptor(errHandler))
104105
csi.RegisterIdentityServer(d.srv, d)
105106
csi.RegisterNodeServer(d.srv, d)

Diff for: pkg/ccm/node.go

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ func (d *driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
152152
unpublishErr.WithLabelValues(configMap, "volume was already unmounted").Inc()
153153
}
154154
logger.V(2).Info(fmt.Sprintf("node unpublish volume succeeded for volume id %q target path %q", req.VolumeId, req.TargetPath))
155-
doCleanup(configMap, req.VolumeId, req.TargetPath)
156155
unpublish.WithLabelValues(configMap).Inc()
157156
unpublishTime.WithLabelValues(configMap).Observe(time.Since(start).Seconds())
158157
return &csi.NodeUnpublishVolumeResponse{}, nil

0 commit comments

Comments
 (0)