Skip to content

Commit 37c6433

Browse files
authored
Merge pull request #1823 from Sneha-at/data-cache
Fix cachesize parsing and setup logic
2 parents 60ca386 + 220118c commit 37c6433

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

cmd/gce-pd-csi-driver/main.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ func handle() {
242242

243243
if *enableNodeDataCacheFlag {
244244
if nodeName == nil || *nodeName == "" {
245-
klog.Fatalf("Data cache enabled, but --node-name not passed")
245+
klog.Errorf("Data cache enabled, but --node-name not passed")
246246
}
247247
if err := setupDataCache(ctx, *nodeName); err != nil {
248-
klog.Fatalf("DataCache setup failed: %v", err)
248+
klog.Errorf("DataCache setup failed: %v", err)
249249
}
250250
}
251251

@@ -299,24 +299,26 @@ func urlFlag(target **url.URL, name string, usage string) {
299299
}
300300

301301
func setupDataCache(ctx context.Context, nodeName string) error {
302-
cfg, err := rest.InClusterConfig()
303-
if err != nil {
304-
return err
305-
}
306-
kubeClient, err := kubernetes.NewForConfig(cfg)
307-
if err != nil {
308-
return err
309-
}
310-
node, err := kubeClient.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
311-
if err != nil {
312-
// We could retry, but this error will also crashloop the driver which may be as good a way to retry as any.
313-
return err
314-
}
315-
if val, found := node.GetLabels()[dataCacheLabel]; !found || val != dataCacheLabelValue {
316-
klog.V(2).Infof("Datacache not enabled for node %s; node label %s=%s and not %s", nodeName, dataCacheLabel, val, dataCacheLabelValue)
317-
return nil
302+
klog.V(2).Infof("Seting up data cache for node %s", nodeName)
303+
if nodeName != common.TestNode {
304+
cfg, err := rest.InClusterConfig()
305+
if err != nil {
306+
return err
307+
}
308+
kubeClient, err := kubernetes.NewForConfig(cfg)
309+
if err != nil {
310+
return err
311+
}
312+
node, err := kubeClient.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
313+
if err != nil {
314+
// We could retry, but this error will also crashloop the driver which may be as good a way to retry as any.
315+
return err
316+
}
317+
if val, found := node.GetLabels()[dataCacheLabel]; !found || val != dataCacheLabelValue {
318+
klog.V(2).Infof("Datacache not enabled for node %s; node label %s=%s and not %s", nodeName, dataCacheLabel, val, dataCacheLabelValue)
319+
return nil
320+
}
318321
}
319-
// Setup data cache only if enabled fro nodes
320322
klog.V(2).Info("Raiding local ssds to setup data cache")
321323
if err := driver.RaidLocalSsds(); err != nil {
322324
return fmt.Errorf("Failed to Raid local SSDs, unable to setup data caching, got error %v", err)

pkg/common/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ const (
4242

4343
// Keys in the publish context
4444
ContexLocalSsdCacheSize = "local-ssd-cache-size"
45+
// Node name for E2E tests
46+
TestNode = "test-node-csi-e2e"
4547
)

pkg/common/parameters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
251251
return p, d, fmt.Errorf("parameters contain invalid dataCacheSize parameter: %w", err)
252252
}
253253
d.DataCacheSize = strconv.FormatInt(paramDataCacheSize, 10)
254-
klog.V(2).Infof("====== Data cache size is %v ======", v)
254+
klog.V(2).Infof("====== Data cache size is %v GiB ======", d.DataCacheSize)
255255
case ParameterKeyDataCacheMode:
256256
if !enableDataCache {
257257
return p, d, fmt.Errorf("data caching enabled %v; parameters contains invalid option %q", enableDataCache, ParameterKeyDataCacheSize)
@@ -260,7 +260,7 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
260260
return p, d, fmt.Errorf("parameters contains invalid option: %w", err)
261261
}
262262
d.DataCacheMode = v
263-
klog.V(2).Infof("====== Data cache mode is %v ======", v)
263+
klog.V(2).Infof("====== Data cache mode is %v ======", d.DataCacheMode)
264264
case ParameterKeyResourceTags:
265265
if err := extractResourceTagsParameter(v, p.ResourceTags); err != nil {
266266
return p, d, err

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,15 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
164164
} else {
165165
fastCacheSize := req.GetPublishContext()[common.ContexLocalSsdCacheSize]
166166
chunkSize := "960" // Cannot use default chunk size(64KiB) as it errors on maxChunksAllowed. Unit - KiB
167-
klog.V(2).Infof("============================== fastCacheSize is %v ==============================", fastCacheSize)
167+
klog.V(2).Infof("============================== fastCacheSize is %v GiB ==============================", fastCacheSize)
168168
klog.V(2).Infof("============================== lvcreate fast cache layer again with the VolumeGroup %v==============================", volumeGroupName)
169169
args = []string{
170170
"--yes",
171171
"-n",
172172
cacheLvName,
173173
"-L",
174-
fastCacheSize,
174+
// ConvertGiStringToInt64 converts the input size to GiB so default to "g" for cache size - LVM g|G is GiB.
175+
fastCacheSize + "g",
175176
volumeGroupName,
176177
raidedLocalSsdPath,
177178
}

test/e2e/utils/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func GCEClientAndDriverSetup(instance *remote.InstanceInfo, computeEndpoint stri
6262
"--use-instance-api-to-list-volumes-published-nodes",
6363
"--enable-controller-data-cache",
6464
"--enable-node-data-cache",
65+
fmt.Sprintf("--node-name=%s", utilcommon.TestNode),
6566
}
6667
extra_flags = append(extra_flags, fmt.Sprintf("--compute-endpoint=%s", computeEndpoint))
6768

0 commit comments

Comments
 (0)