Skip to content

Commit 1c51cca

Browse files
authored
Merge pull request #529 from jingxu97/June/windowstest
Add e2e CI tests for Windows
2 parents cca3c14 + 33654c9 commit 1c51cca

File tree

11 files changed

+122
-48
lines changed

11 files changed

+122
-48
lines changed

Dockerfile.Windows

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
ARG BASE_IMAGE
22
ARG BASE_IMAGE_TAG
3+
FROM --platform=$BUILDPLATFORM golang:1.13.3 AS builder
4+
5+
ARG TARGETPLATFORM
6+
ARG BUILDPLATFORM
7+
ARG STAGINGVERSION
8+
WORKDIR /code
9+
ADD . /code/
10+
RUN cd /code/ && GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d '/') GCE_PD_CSI_STAGING_VERSION=${STAGINGVERSION} make gce-pd-driver-windows
311

412
FROM mcr.microsoft.com/windows/${BASE_IMAGE}:${BASE_IMAGE_TAG}
513
LABEL description="PD CSI driver"
6-
COPY bin/gce-pd-csi-driver.exe /gce-pd-csi-driver.exe
14+
COPY --from=builder /code/bin/gce-pd-csi-driver.exe /gce-pd-csi-driver.exe
715

816
USER ContainerAdministrator
917
ENTRYPOINT ["/gce-pd-csi-driver.exe"]

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ ifndef GCE_PD_CSI_STAGING_IMAGE
4545
endif
4646
@sh init-buildx.sh; \
4747
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \
48-
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=ltsc2019 --push .
48+
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=ltsc2019 --build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
4949

5050
build-and-push-windows-container-1909:
5151
ifndef GCE_PD_CSI_STAGING_IMAGE
5252
$(error "Must set environment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
5353
endif
5454
@sh init-buildx.sh; \
5555
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \
56-
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=1909 --push .
56+
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=1909 --build-arg STAGINGVERSION=$(STAGINGVERSION) --push .
5757

5858
push-container: build-container
5959
gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION)

deploy/kubernetes/base/controller/cluster_setup.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,3 @@ roleRef:
272272
kind: Role
273273
name: csi-gce-pd-leaderelection-role
274274
apiGroup: rbac.authorization.k8s.io
275-

deploy/kubernetes/images/alpha/image.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ metadata:
44
name: imagetag-gcepd-driver-alpha-win
55
imageTag:
66
name: gke.gcr.io/gcp-compute-persistent-disk-csi-driver-win
7-
newName: gcr.io/jing-k8s-dev/gce-pd-windows-2019
8-
newTag: "0.2.0"
7+
newName: gcr.io/gke-release-staging/gcp-compute-persistent-disk-csi-driver-amd64-windows-1909
8+
newTag: "cca3c14"
99
---
1010

1111
apiVersion: builtin

deploy/kubernetes/overlays/alpha/kustomization.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
3-
namespace:
4-
gce-pd-csi-driver
3+
namespace: gce-pd-csi-driver
54
resources:
65
- ../../base/
76
transformers:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: storage.k8s.io/v1
2+
kind: StorageClass
3+
metadata:
4+
name: csi-gcepd
5+
provisioner: pd.csi.storage.gke.io
6+
parameters:
7+
type: pd-standard
8+
csi.storage.k8s.io/fstype: ntfs
9+
volumeBindingMode: WaitForFirstConsumer

test/k8s-integration/config/test-config-template.in

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ SnapshotClass:
77
DriverInfo:
88
Name: csi-gcepd
99
SupportedFsType:
10-
ext2:
11-
ext3:
12-
ext4:
13-
xfs:
14-
# The following FS types supported by GCE PD but
15-
# currently we do not test the CSI Driver on Windows
16-
# ntfs: NTFS only available on Windows
10+
{{range .SupportedFsType}} {{ . }}:
11+
{{end}}
1712
Capabilities:
1813
{{range .Capabilities}} {{ . }}: true
1914
{{end}}

test/k8s-integration/driver-config.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type driverConfig struct {
1212
StorageClassFile string
1313
SnapshotClassFile string
1414
Capabilities []string
15+
SupportedFsType []string
1516
}
1617

1718
const (
@@ -22,7 +23,7 @@ const (
2223

2324
// generateDriverConfigFile loads a testdriver config template and creates a file
2425
// with the test-specific configuration
25-
func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat string) (string, error) {
26+
func generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassFile, deploymentStrat string) (string, error) {
2627
// Load template
2728
t, err := template.ParseFiles(filepath.Join(pkgDir, testConfigDir, configTemplateFile))
2829
if err != nil {
@@ -50,6 +51,17 @@ func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deplo
5051
"multipods",
5152
"topology",
5253
}
54+
var fsTypes []string
55+
if platform == "windows" {
56+
fsTypes = []string{"ntfs"}
57+
} else {
58+
fsTypes = []string{
59+
"ext2",
60+
"ext3",
61+
"ext4",
62+
"xfs",
63+
}
64+
}
5365

5466
/* Unsupported Capabilities:
5567
pvcDataSource
@@ -83,6 +95,7 @@ func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deplo
8395
params := driverConfig{
8496
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
8597
SnapshotClassFile: absSnapshotClassFilePath,
98+
SupportedFsType: fsTypes,
8699
Capabilities: caps,
87100
}
88101

test/k8s-integration/driver.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func deleteDriver(goPath, pkgDir, deployOverlayName string) error {
8787
return nil
8888
}
8989

90-
func pushImage(pkgDir, stagingImage, stagingVersion string) error {
90+
func pushImage(pkgDir, stagingImage, stagingVersion, platform string) error {
9191
err := os.Setenv("GCE_PD_CSI_STAGING_VERSION", stagingVersion)
9292
if err != nil {
9393
return err
@@ -96,9 +96,16 @@ func pushImage(pkgDir, stagingImage, stagingVersion string) error {
9696
if err != nil {
9797
return err
9898
}
99-
cmd := exec.Command("make", "-C", pkgDir, "push-container",
100-
fmt.Sprintf("GCE_PD_CSI_STAGING_VERSION=%s", stagingVersion),
101-
fmt.Sprintf("GCE_PD_CSI_STAGING_IMAGE=%s", stagingImage))
99+
var cmd *exec.Cmd
100+
if platform != "windows" {
101+
cmd = exec.Command("make", "-C", pkgDir, "push-container",
102+
fmt.Sprintf("GCE_PD_CSI_STAGING_VERSION=%s", stagingVersion),
103+
fmt.Sprintf("GCE_PD_CSI_STAGING_IMAGE=%s", stagingImage))
104+
} else {
105+
cmd = exec.Command("make", "-C", pkgDir, "build-and-push-windows-container-1909",
106+
fmt.Sprintf("GCE_PD_CSI_STAGING_VERSION=%s", stagingVersion),
107+
fmt.Sprintf("GCE_PD_CSI_STAGING_IMAGE=%s", stagingImage))
108+
}
102109
err = runCommand("Pushing GCP Container", cmd)
103110
if err != nil {
104111
return fmt.Errorf("failed to run make command: err: %v", err)

test/k8s-integration/main.go

+41-28
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"os/exec"
2222
"path/filepath"
23+
"strings"
2324
"syscall"
2425

2526
"k8s.io/apimachinery/pkg/util/uuid"
@@ -33,6 +34,7 @@ var (
3334
teardownCluster = flag.Bool("teardown-cluster", true, "teardown the cluster after the e2e test")
3435
teardownDriver = flag.Bool("teardown-driver", true, "teardown the driver after the e2e test")
3536
bringupCluster = flag.Bool("bringup-cluster", true, "build kubernetes and bringup a cluster")
37+
platform = flag.String("platform", "linux", "platform that the tests will be run, either linux or windows")
3638
gceZone = flag.String("gce-zone", "", "zone that the gce k8s cluster is created/found in")
3739
gceRegion = flag.String("gce-region", "", "region that gke regional cluster should be created in")
3840
kubeVersion = flag.String("kube-version", "", "version of Kubernetes to download and use for the cluster")
@@ -95,7 +97,6 @@ func main() {
9597
}
9698

9799
ensureVariable(testFocus, true, "test-focus is a required flag")
98-
ensureVariable(imageType, true, "image type is a required flag. Available options include 'cos' and 'ubuntu'")
99100

100101
if len(*gceRegion) != 0 {
101102
ensureVariable(gceZone, false, "gce-zone and gce-region cannot both be set")
@@ -111,6 +112,12 @@ func main() {
111112

112113
if !*bringupCluster {
113114
ensureVariable(kubeFeatureGates, false, "kube-feature-gates set but not bringing up new cluster")
115+
} else {
116+
ensureVariable(imageType, true, "image type is a required flag. Available options include 'cos' and 'ubuntu'")
117+
}
118+
119+
if *platform == "windows" {
120+
ensureFlag(bringupCluster, false, "bringupCluster is set to false if it is for testing in windows cluster")
114121
}
115122

116123
if *deploymentStrat == "gke" {
@@ -132,7 +139,7 @@ func main() {
132139
ensureVariable(testVersion, false, "Cannot set a test version when using a local k8s dir.")
133140
}
134141

135-
if *numNodes == -1 {
142+
if *numNodes == -1 && *bringupCluster {
136143
klog.Fatalf("num-nodes must be set to number of nodes in cluster")
137144
}
138145

@@ -157,28 +164,32 @@ func handle() error {
157164

158165
// If running in Prow, then acquire and set up a project through Boskos
159166
if *inProw {
160-
project, _ := testutils.SetupProwConfig(*boskosResourceType)
161-
162167
oldProject, err := exec.Command("gcloud", "config", "get-value", "project").CombinedOutput()
168+
project := strings.TrimSpace(string(oldProject))
163169
if err != nil {
164170
return fmt.Errorf("failed to get gcloud project: %s, err: %v", oldProject, err)
165171
}
166-
167-
err = setEnvProject(project)
168-
if err != nil {
169-
return fmt.Errorf("failed to set project environment to %s: %v", project, err)
170-
}
171-
defer func() {
172-
err = setEnvProject(string(oldProject))
172+
// TODO: Currently for prow tests with linux cluster, here it manually sets up a project from Boskos.
173+
// For Windows, we used kubernetes_e2e.py which already set up the project and kubernetes automatically.
174+
// Will update Linux in the future to use the same way as Windows test.
175+
if *platform != "windows" {
176+
newproject, _ := testutils.SetupProwConfig(*boskosResourceType)
177+
err = setEnvProject(newproject)
173178
if err != nil {
174-
klog.Errorf("failed to set project environment to %s: %v", oldProject, err)
179+
return fmt.Errorf("failed to set project environment to %s: %v", newproject, err)
175180
}
176-
}()
177181

182+
defer func() {
183+
err = setEnvProject(string(oldProject))
184+
if err != nil {
185+
klog.Errorf("failed to set project environment to %s: %v", oldProject, err)
186+
}
187+
}()
188+
project = newproject
189+
}
178190
if *doDriverBuild {
179-
*stagingImage = fmt.Sprintf("gcr.io/%s/gcp-persistent-disk-csi-driver", project)
191+
*stagingImage = fmt.Sprintf("gcr.io/%s/gcp-persistent-disk-csi-driver", strings.TrimSpace(string(project)))
180192
}
181-
182193
if _, ok := os.LookupEnv("USER"); !ok {
183194
err = os.Setenv("USER", "prow")
184195
if err != nil {
@@ -189,7 +200,7 @@ func handle() error {
189200

190201
// Build and push the driver, if required. Defer the driver image deletion.
191202
if *doDriverBuild {
192-
err := pushImage(pkgDir, *stagingImage, stagingVersion)
203+
err := pushImage(pkgDir, *stagingImage, stagingVersion, *platform)
193204
if err != nil {
194205
return fmt.Errorf("failed pushing image: %v", err)
195206
}
@@ -319,7 +330,7 @@ func handle() error {
319330
var testSkip string
320331
switch *deploymentStrat {
321332
case "gce":
322-
testSkip = generateGCETestSkip(clusterVersion)
333+
testSkip = generateGCETestSkip(clusterVersion, *platform)
323334
case "gke":
324335
testSkip = generateGKETestSkip(clusterVersion, *useGKEManagedDriver)
325336
default:
@@ -328,7 +339,7 @@ func handle() error {
328339

329340
// Run the tests using the testDir kubernetes
330341
if len(*storageClassFile) != 0 {
331-
err = runCSITests(pkgDir, testDir, *testFocus, testSkip, *storageClassFile, *snapshotClassFile, cloudProviderArgs, *deploymentStrat)
342+
err = runCSITests(*platform, pkgDir, testDir, *testFocus, testSkip, *storageClassFile, *snapshotClassFile, cloudProviderArgs, *deploymentStrat)
332343
} else if *migrationTest {
333344
err = runMigrationTests(pkgDir, testDir, *testFocus, testSkip, cloudProviderArgs)
334345
} else {
@@ -342,7 +353,7 @@ func handle() error {
342353
return nil
343354
}
344355

345-
func generateGCETestSkip(clusterVersion string) string {
356+
func generateGCETestSkip(clusterVersion, platform string) string {
346357
skipString := "\\[Disruptive\\]|\\[Serial\\]"
347358
v := apimachineryversion.MustParseSemantic(clusterVersion)
348359

@@ -352,10 +363,12 @@ func generateGCETestSkip(clusterVersion string) string {
352363
if v.LessThan(apimachineryversion.MustParseSemantic("1.16.0")) {
353364
skipString = skipString + "|volumeMode\\sshould\\snot\\smount\\s/\\smap\\sunused\\svolumes\\sin\\sa\\spod"
354365
}
355-
356366
if v.LessThan(apimachineryversion.MustParseSemantic("1.17.0")) {
357367
skipString = skipString + "|VolumeSnapshotDataSource"
358368
}
369+
if platform == "windows" {
370+
skipString = skipString + "|\\[LinuxOnly\\]"
371+
}
359372
return skipString
360373
}
361374

@@ -375,7 +388,6 @@ func generateGKETestSkip(clusterVersion string, use_gke_managed_driver bool) str
375388
(!use_gke_managed_driver && (*curVer).lessThan(mustParseVersion("1.17.0"))) {
376389
skipString = skipString + "|VolumeSnapshotDataSource"
377390
}
378-
379391
return skipString
380392
}
381393

@@ -396,8 +408,8 @@ func runMigrationTests(pkgDir, testDir, testFocus, testSkip string, cloudProvide
396408
return runTestsWithConfig(testDir, testFocus, testSkip, "--storage.migratedPlugins=kubernetes.io/gce-pd", cloudProviderArgs)
397409
}
398410

399-
func runCSITests(pkgDir, testDir, testFocus, testSkip, storageClassFile, snapshotClassFile string, cloudProviderArgs []string, deploymentStrat string) error {
400-
testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat)
411+
func runCSITests(platform, pkgDir, testDir, testFocus, testSkip, storageClassFile, snapshotClassFile string, cloudProviderArgs []string, deploymentStrat string) error {
412+
testDriverConfigFile, err := generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassFile, deploymentStrat)
401413
if err != nil {
402414
return err
403415
}
@@ -419,10 +431,12 @@ func runTestsWithConfig(testDir, testFocus, testSkip, testConfigArg string, clou
419431
if ok {
420432
reportArg = fmt.Sprintf("-report-dir=%s", artifactsDir)
421433
}
422-
423-
testArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s %s %s",
424-
testFocus,
425-
testSkip,
434+
ginkgoArgs := fmt.Sprintf("--ginkgo.focus=%s --ginkgo.skip=%s", testFocus, testSkip)
435+
if *platform == "windows" {
436+
ginkgoArgs = ginkgoArgs + fmt.Sprintf(" --node-os-distro=%s", *platform)
437+
}
438+
testArgs := fmt.Sprintf("%s %s %s",
439+
ginkgoArgs,
426440
testConfigArg,
427441
reportArg)
428442

@@ -432,7 +446,6 @@ func runTestsWithConfig(testDir, testFocus, testSkip, testConfigArg string, clou
432446
"--check-version-skew=false",
433447
fmt.Sprintf("--test_args=%s", testArgs),
434448
}
435-
436449
kubeTestArgs = append(kubeTestArgs, cloudProviderArgs...)
437450

438451
err = runCommand("Running Tests", exec.Command("kubetest", kubeTestArgs...))

test/run-windows-k8s-integration.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Optional environment variables
4+
# GCE_PD_OVERLAY_NAME: which Kustomize overlay to deploy with
5+
# GCE_PD_DO_DRIVER_BUILD: if set, don't build the driver from source and just
6+
# use the driver version from the overlay
7+
# GCE_PD_BOSKOS_RESOURCE_TYPE: name of the boskos resource type to reserve
8+
9+
set -o nounset
10+
set -o errexit
11+
12+
readonly GCE_PD_DO_DRIVER_BUILD=false
13+
readonly PKGDIR=${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
14+
readonly LOCAL_K8S_DIR=${GOPATH}/src/k8s.io/kubernetes
15+
readonly overlay_name="${GCE_PD_OVERLAY_NAME:-alpha}"
16+
readonly do_driver_build="${GCE_PD_DO_DRIVER_BUILD:-true}"
17+
readonly deployment_strategy=${DEPLOYMENT_STRATEGY:-gce}
18+
readonly test_version=${TEST_VERSION:-master}
19+
readonly gce_zone=${GCE_CLUSTER_ZONE:-us-central1-b}
20+
readonly teardown_driver=${GCE_CLUSTER_ZONE:-true}
21+
22+
make -C ${PKGDIR} test-k8s-integration
23+
24+
base_cmd="${PKGDIR}/bin/k8s-integration-test \
25+
--platform=windows --local-k8s-dir=${LOCAL_K8S_DIR} --bringup-cluster=false --teardown-cluster=false --teardown-driver=${teardown_driver}\
26+
--run-in-prow=true --deploy-overlay-name=${overlay_name} --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
27+
--do-driver-build=${do_driver_build} --gce-zone=${gce_zone}\
28+
--storageclass-file=sc-windows.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --test-focus="External.Storage" \
29+
--deployment-strategy=${deployment_strategy}"
30+
31+
eval $base_cmd

0 commit comments

Comments
 (0)