Skip to content

Commit 81510ca

Browse files
committed
skip cache clean up for non-data cache PVCs
1 parent 4ef1224 commit 81510ca

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
@@ -370,11 +370,17 @@ func cleanupCache(volumeId string, nodeId string) error {
370370

371371
volumeGroupName := getVolumeGroupName(nodeId)
372372
if !checkVgExists(volumeGroupName) {
373+
klog.V(4).Infof("Volume group %s not found, no cache clean up needed", volumeGroupName)
373374
// If volume group doesn't exist then there's nothing to uncache
374375
return nil
375376
}
376377
reduceVolumeGroup(volumeGroupName, true)
377378
mainLvName := getLvName(mainLvSuffix, volumeId)
379+
if !checkLvExists(mainLvName) {
380+
klog.V(4).Infof("Logical volume %s not found, assuming caching wasn't setup for the PVC %s or is cleaned up", mainLvName, volumeId)
381+
// If logical volume doesn't exist then there's nothing to uncache
382+
return nil
383+
}
378384
args := []string{
379385
"-an",
380386
"/dev/" + volumeGroupName + "/" + mainLvName,
@@ -395,6 +401,17 @@ func cleanupCache(volumeId string, nodeId string) error {
395401
return nil
396402
}
397403

404+
func checkLvExists(lvName string) bool {
405+
args := []string{}
406+
info, err := common.RunCommand("" /* pipedCmd */, "" /* pipedCmdArg */, "lvscan", args...)
407+
if err != nil {
408+
klog.Errorf("Errored while checking if logical volume exists for %s %v: %s", lvName, err, info)
409+
return false
410+
}
411+
// Check if the required logical volume already exists
412+
return strings.Contains(string(info), lvName)
413+
}
414+
398415
func getVolumeGroupName(nodePath string) string {
399416
nodeSlice := strings.Split(nodePath, "/")
400417
nodeId := nodeSlice[len(nodeSlice)-1]

0 commit comments

Comments
 (0)