Skip to content

Commit

Permalink
Merge pull request #825 from andyzhangx/fix-2022-test-failure
Browse files Browse the repository at this point in the history
test: fix windows 2022 test failure
  • Loading branch information
andyzhangx authored Aug 16, 2024
2 parents 68fed09 + 8c49d79 commit bd4f8a1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
2 changes: 1 addition & 1 deletion deploy/example/windows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
"kubernetes.io/os": windows
containers:
- name: busybox
image: e2eteam/busybox:1.29
image: mcr.microsoft.com/windows/servercore:ltsc2022
command:
- "powershell.exe"
- "-Command"
Expand Down
2 changes: 1 addition & 1 deletion deploy/example/windows/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
"kubernetes.io/os": windows
containers:
- name: busybox-smb
image: e2eteam/busybox:1.29
image: mcr.microsoft.com/windows/servercore:ltsc2022
command:
- "powershell.exe"
- "-Command"
Expand Down
37 changes: 24 additions & 13 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
}

podCheckCmd := []string{"cat", "/mnt/test-1/data"}
Expand Down Expand Up @@ -123,7 +124,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
Expand All @@ -148,7 +150,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
{
Cmd: convertToPowershellCommandIfNecessary("while true; do echo $(date -u) >> /mnt/test-1/data; sleep 100; done"),
Expand All @@ -161,7 +164,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedCollocatedPodTest{
Expand Down Expand Up @@ -190,7 +194,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedReadOnlyVolumeTest{
Expand All @@ -217,7 +222,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
}

podCheckCmd := []string{"cat", "/mnt/test-1/data"}
Expand Down Expand Up @@ -286,9 +292,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {

pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: volumes,
IsWindows: isWindowsCluster,
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: volumes,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedPodWithMultiplePVsTest{
Expand All @@ -312,7 +319,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedVolumeSubpathTester{
Expand Down Expand Up @@ -381,7 +389,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
Expand Down Expand Up @@ -414,7 +423,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
Expand Down Expand Up @@ -447,7 +457,8 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
},
},
},
IsWindows: isWindowsCluster,
IsWindows: isWindowsCluster,
WinServerVer: winServerVer,
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
kubeconfigEnvVar = "KUBECONFIG"
reportDirEnv = "ARTIFACTS"
testWindowsEnvVar = "TEST_WINDOWS"
testWinServerVerEnvVar = "WINDOWS_SERVER_VERSION"
defaultReportDir = "test/e2e"
testSmbSourceEnvVar = "TEST_SMB_SOURCE"
testSmbSecretNameEnvVar = "TEST_SMB_SECRET_NAME"
Expand All @@ -52,6 +53,7 @@ const (
var (
smbDriver *smb.Driver
isWindowsCluster = os.Getenv(testWindowsEnvVar) != ""
winServerVer = os.Getenv(testWinServerVerEnvVar)
defaultStorageClassParameters = map[string]string{
"source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource),
"csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName),
Expand Down Expand Up @@ -117,6 +119,7 @@ var _ = ginkgo.BeforeSuite(func() {
framework.AfterReadingAllFlags(&framework.TestContext)

kubeconfig := os.Getenv(kubeconfigEnvVar)
log.Println(testWinServerVerEnvVar, os.Getenv(testWinServerVerEnvVar), fmt.Sprintf("%v", winServerVer))

// Install SMB provisioner on cluster
installSMBProvisioner := testCmd{
Expand Down
17 changes: 9 additions & 8 deletions test/e2e/testsuites/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (
)

type PodDetails struct {
Cmd string
Volumes []VolumeDetails
IsWindows bool
Cmd string
Volumes []VolumeDetails
IsWindows bool
WinServerVer string
}

type VolumeDetails struct {
Expand Down Expand Up @@ -86,7 +87,7 @@ type DataSource struct {

//nolint:dupl
func (pod *PodDetails) SetupWithDynamicVolumes(ctx context.Context, client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, storageClassParameters map[string]string) (*TestPod, []func(ctx context.Context)) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer)
cleanupFuncs := make([]func(ctx context.Context), 0)
for n, v := range pod.Volumes {
tpvc, funcs := v.SetupDynamicPersistentVolumeClaim(ctx, client, namespace, csiDriver, storageClassParameters)
Expand All @@ -104,7 +105,7 @@ func (pod *PodDetails) SetupWithDynamicVolumes(ctx context.Context, client clien
//
//nolint:dupl
func (pod *PodDetails) SetupWithDynamicMultipleVolumes(ctx context.Context, client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, storageClassParameters map[string]string) (*TestPod, []func(ctx context.Context)) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer)
cleanupFuncs := make([]func(ctx context.Context), 0)
for n, v := range pod.Volumes {
tpvc, funcs := v.SetupDynamicPersistentVolumeClaim(ctx, client, namespace, csiDriver, storageClassParameters)
Expand All @@ -119,7 +120,7 @@ func (pod *PodDetails) SetupWithDynamicMultipleVolumes(ctx context.Context, clie
}

func (pod *PodDetails) SetupWithPreProvisionedVolumes(ctx context.Context, client clientset.Interface, namespace *v1.Namespace, csiDriver driver.PreProvisionedVolumeTestDriver) (*TestPod, []func(ctx context.Context)) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer)
cleanupFuncs := make([]func(ctx context.Context), 0)
for n, v := range pod.Volumes {
tpvc, funcs := v.SetupPreProvisionedPersistentVolumeClaim(ctx, client, namespace, csiDriver)
Expand Down Expand Up @@ -149,14 +150,14 @@ func (pod *PodDetails) SetupDeployment(ctx context.Context, client clientset.Int
tpvc.ValidateProvisionedPersistentVolume(ctx)
cleanupFuncs = append(cleanupFuncs, tpvc.Cleanup)
ginkgo.By("setting up the Deployment")
tDeployment := NewTestDeployment(client, namespace, pod.Cmd, tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", volume.VolumeMount.NameGenerate, 1), fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, 1), volume.VolumeMount.ReadOnly, pod.IsWindows)
tDeployment := NewTestDeployment(client, namespace, pod.Cmd, tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", volume.VolumeMount.NameGenerate, 1), fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, 1), volume.VolumeMount.ReadOnly, pod.IsWindows, pod.WinServerVer)

cleanupFuncs = append(cleanupFuncs, tDeployment.Cleanup)
return tDeployment, cleanupFuncs
}

func (pod *PodDetails) SetupWithDynamicVolumesWithSubpath(ctx context.Context, client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, storageClassParameters map[string]string) (*TestPod, []func(ctx context.Context)) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer)
cleanupFuncs := make([]func(ctx context.Context), 0)
for n, v := range pod.Volumes {
tpvc, funcs := v.SetupDynamicPersistentVolumeClaim(ctx, client, namespace, csiDriver, storageClassParameters)
Expand Down
16 changes: 12 additions & 4 deletions test/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ type TestDeployment struct {
podName string
}

func NewTestDeployment(c clientset.Interface, ns *v1.Namespace, command string, pvc *v1.PersistentVolumeClaim, volumeName, mountPath string, readOnly, isWindows bool) *TestDeployment {
func NewTestDeployment(c clientset.Interface, ns *v1.Namespace, command string, pvc *v1.PersistentVolumeClaim, volumeName, mountPath string, readOnly, isWindows bool, winServerVer string) *TestDeployment {
generateName := "smb-volume-tester-"
selectorValue := fmt.Sprintf("%s%d", generateName, rand.Int())
replicas := int32(1)
Expand Down Expand Up @@ -400,7 +400,7 @@ func NewTestDeployment(c clientset.Interface, ns *v1.Namespace, command string,
Value: "win1809",
},
}
testDeployment.deployment.Spec.Template.Spec.Containers[0].Image = "e2eteam/busybox:1.29"
testDeployment.deployment.Spec.Template.Spec.Containers[0].Image = "mcr.microsoft.com/windows/servercore:" + getWinImageTag(winServerVer)
testDeployment.deployment.Spec.Template.Spec.Containers[0].Command = []string{"powershell.exe"}
testDeployment.deployment.Spec.Template.Spec.Containers[0].Args = []string{"-Command", command}
}
Expand Down Expand Up @@ -502,7 +502,7 @@ type TestPod struct {
namespace *v1.Namespace
}

func NewTestPod(c clientset.Interface, ns *v1.Namespace, command string, isWindows bool) *TestPod {
func NewTestPod(c clientset.Interface, ns *v1.Namespace, command string, isWindows bool, winServerVer string) *TestPod {
testPod := &TestPod{
client: c,
namespace: ns,
Expand Down Expand Up @@ -537,14 +537,22 @@ func NewTestPod(c clientset.Interface, ns *v1.Namespace, command string, isWindo
Value: "win1809",
},
}
testPod.pod.Spec.Containers[0].Image = "e2eteam/busybox:1.29"
testPod.pod.Spec.Containers[0].Image = "mcr.microsoft.com/windows/servercore:" + getWinImageTag(winServerVer)
testPod.pod.Spec.Containers[0].Command = []string{"powershell.exe"}
testPod.pod.Spec.Containers[0].Args = []string{"-Command", command}
}

return testPod
}

func getWinImageTag(winServerVer string) string {
testWinImageTag := "ltsc2019"
if winServerVer == "windows-2022" {
testWinImageTag = "ltsc2022"
}
return testWinImageTag
}

func (t *TestPod) Create(ctx context.Context) {
var err error

Expand Down

0 comments on commit bd4f8a1

Please sign in to comment.