Skip to content

Commit 9310f46

Browse files
committed
skip cache clean up for non-data cache PVCs
1 parent d35496c commit 9310f46

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

deploy/kubernetes/base/controller/controller.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ spec:
143143
- "--endpoint=unix:/csi/csi.sock"
144144
- "--supports-dynamic-iops-provisioning=hyperdisk-balanced,hyperdisk-extreme"
145145
- "--supports-dynamic-throughput-provisioning=hyperdisk-balanced,hyperdisk-throughput,hyperdisk-ml"
146-
- --enable-controller-data-cache
146+
- --enable-data-cache
147147
env:
148148
- name: GOOGLE_APPLICATION_CREDENTIALS
149149
value: "/etc/cloud-sa/cloud-sa.json"

pkg/gce-pd-csi-driver/cache.go

+17
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ func cleanupCache(volumeId string, nodeId string) error {
217217

218218
volumeGroupName := getVolumeGroupName(nodeId)
219219
if !checkVgExists(volumeGroupName) {
220+
klog.V(4).Infof("Volume group %s not found, no cache clean up needed", volumeGroupName)
220221
// If volume group doesn't exist then there's nothing to uncache
221222
return nil
222223
}
223224
mainLvName := getLvName(mainLvSuffix, volumeId)
225+
if !checkLvExists(mainLvName) {
226+
klog.V(4).Infof("Logical volume %s not found, assuming caching wasn't setup for the PVC %s or is cleaned up", mainLvName, volumeId)
227+
// If logical volume doesn't exist then there's nothing to uncache
228+
return nil
229+
}
224230
args := []string{
225231
"-an",
226232
"/dev/" + volumeGroupName + "/" + mainLvName,
@@ -241,6 +247,17 @@ func cleanupCache(volumeId string, nodeId string) error {
241247
return nil
242248
}
243249

250+
func checkLvExists(lvName string) bool {
251+
args := []string{}
252+
info, err := common.RunCommand("" /* pipedCmd */, "" /* pipedCmdArg */, "lvscan", args...)
253+
if err != nil {
254+
klog.Errorf("Errored while checking if logical volume exists for %s %v: %s", lvName, err, info)
255+
return false
256+
}
257+
// Check if the required logical volume already exists
258+
return strings.Contains(string(info), lvName)
259+
}
260+
244261
func getVolumeGroupName(nodePath string) string {
245262
nodeSlice := strings.Split(nodePath, "/")
246263
nodeId := nodeSlice[len(nodeSlice)-1]

0 commit comments

Comments
 (0)