Skip to content

Commit 220118c

Browse files
committed
fix E2E tests when kube client not available
1 parent d018f11 commit 220118c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)

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)