Sitelet https://github.com/kubernetes/kops/commit/badb2ab280b5366dd4af64d2c3e1f166e59e6886
Skip to content

Commit badb2ab

Browse files
authored
Merge pull request #18102 from rifelpet/gcp-pd-e2e
Replace cwd with go:embed for storage.testdriver manifests
2 parents e5dd358 + 6815cb4 commit badb2ab

2 files changed

Lines changed: 65 additions & 12 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2026 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package csimanifests
18+
19+
import "embed"
20+
21+
//go:embed aws-ebs/* gcp-pd/*
22+
var FS embed.FS

‎tests/e2e/pkg/tester/tester.go‎

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"os/exec"
24+
"path/filepath"
2425
"strconv"
2526
"strings"
2627

@@ -29,6 +30,7 @@ import (
2930
"k8s.io/klog/v2"
3031
unversioned "k8s.io/kops/pkg/apis/kops"
3132
api "k8s.io/kops/pkg/apis/kops/v1alpha2"
33+
csimanifests "k8s.io/kops/tests/e2e/csi-manifests"
3234
"k8s.io/kops/tests/e2e/pkg/kops"
3335
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
3436
"sigs.k8s.io/kubetest2/pkg/artifacts"
@@ -421,31 +423,60 @@ func (t *Tester) addCSIDriverFlags() error {
421423
return err
422424
}
423425

424-
var driverFlags string
426+
var provider, migratedPlugin string
425427
if cluster.Spec.CloudConfig != nil {
426-
cwd, err := os.Getwd()
427-
if err != nil {
428-
return err
429-
}
430-
431428
switch {
432429
case cluster.Spec.CloudConfig.AWSEBSCSIDriver != nil &&
433430
cluster.Spec.CloudConfig.AWSEBSCSIDriver.Enabled != nil &&
434431
*cluster.Spec.CloudConfig.AWSEBSCSIDriver.Enabled:
435-
driverFlags = fmt.Sprintf(" --storage.testdriver=%s/tests/e2e/csi-manifests/aws-ebs/driver.yaml --storage.migratedPlugins=kubernetes.io/aws-ebs", cwd)
432+
provider = "aws-ebs"
433+
migratedPlugin = "kubernetes.io/aws-ebs"
436434
case cluster.Spec.CloudConfig.GCPPDCSIDriver != nil &&
437435
cluster.Spec.CloudConfig.GCPPDCSIDriver.Enabled != nil &&
438436
*cluster.Spec.CloudConfig.GCPPDCSIDriver.Enabled:
439-
driverFlags = fmt.Sprintf(" --storage.testdriver=%s/tests/e2e/csi-manifests/gcp-pd/driver.yaml --storage.migratedPlugins=kubernetes.io/gce-pd", cwd)
437+
provider = "gcp-pd"
438+
migratedPlugin = "kubernetes.io/gce-pd"
440439
}
441440
}
442441

443-
if driverFlags != "" {
444-
klog.Infof("Setting %v", driverFlags)
445-
t.TestArgs += driverFlags
446-
} else {
442+
if provider == "" {
447443
klog.Info("CSI driver not enabled. Skipping tests")
444+
return nil
445+
}
446+
447+
tmpDir, err := os.MkdirTemp("", "csi-manifests-*")
448+
if err != nil {
449+
return fmt.Errorf("creating temp dir for CSI manifests: %w", err)
448450
}
451+
452+
scData, err := csimanifests.FS.ReadFile(provider + "/sc.yaml")
453+
if err != nil {
454+
return fmt.Errorf("reading embedded %s/sc.yaml: %w", provider, err)
455+
}
456+
scPath := filepath.Join(tmpDir, "sc.yaml")
457+
if err := os.WriteFile(scPath, scData, 0644); err != nil {
458+
return fmt.Errorf("writing sc.yaml: %w", err)
459+
}
460+
461+
driverData, err := csimanifests.FS.ReadFile(provider + "/driver.yaml")
462+
if err != nil {
463+
return fmt.Errorf("reading embedded %s/driver.yaml: %w", provider, err)
464+
}
465+
// Rewrite the FromFile path to point to the temp dir copy of sc.yaml
466+
driverContent := strings.Replace(
467+
string(driverData),
468+
"tests/e2e/csi-manifests/"+provider+"/sc.yaml",
469+
scPath,
470+
1,
471+
)
472+
driverPath := filepath.Join(tmpDir, "driver.yaml")
473+
if err := os.WriteFile(driverPath, []byte(driverContent), 0644); err != nil {
474+
return fmt.Errorf("writing driver.yaml: %w", err)
475+
}
476+
477+
driverFlags := fmt.Sprintf(" --storage.testdriver=%s --storage.migratedPlugins=%s", driverPath, migratedPlugin)
478+
klog.Infof("Setting %v", driverFlags)
479+
t.TestArgs += driverFlags
449480
return nil
450481
}
451482

0 commit comments

Comments
 (0)