Skip to content

Commit bc0a5d3

Browse files
Sneha-atcemakd
authored andcommitted
skip cache clean up for non-data cache PVCs
1 parent 03d4a84 commit bc0a5d3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

deploy/kubernetes/base/controller/controller.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ spec:
139139
args:
140140
- "--v=5"
141141
- "--endpoint=unix:/csi/csi.sock"
142-
- --enable-controller-data-cache
142+
- --enable-data-cache
143143
env:
144144
- name: GOOGLE_APPLICATION_CREDENTIALS
145145
value: "/etc/cloud-sa/cloud-sa.json"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,17 @@ func cleanupCache(volumeId string, nodeId string) error {
369369

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

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

0 commit comments

Comments
 (0)