Skip to content

Commit 35cce11

Browse files
committed
kubernetes bootstrap through k8s-integration for both linux & windows
1 parent 1184d0d commit 35cce11

File tree

6 files changed

+57
-52
lines changed

6 files changed

+57
-52
lines changed

test/k8s-integration/cluster.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func isRegionalGKECluster(gceZone, gceRegion string) bool {
3636

3737
func clusterDownGCE(k8sDir string) error {
3838
cmd := exec.Command(filepath.Join(k8sDir, "hack", "e2e-internal", "e2e-down.sh"))
39+
cmd.Env = os.Environ()
3940
err := runCommand("Bringing Down E2E Cluster on GCE", cmd)
4041
if err != nil {
4142
return fmt.Errorf("failed to bring down kubernetes e2e cluster on gce: %v", err)
@@ -60,14 +61,15 @@ func clusterDownGKE(gceZone, gceRegion string) error {
6061

6162
func buildKubernetes(k8sDir, command string) error {
6263
cmd := exec.Command("make", "-C", k8sDir, command)
63-
err := runCommand("Building Kubernetes", cmd)
64+
cmd.Env = os.Environ()
65+
err := runCommand(fmt.Sprintf("Running command in kubernetes/kubernetes path=%s", k8sDir), cmd)
6466
if err != nil {
6567
return fmt.Errorf("failed to build Kubernetes: %v", err)
6668
}
6769
return nil
6870
}
6971

70-
func clusterUpGCE(k8sDir, gceZone string, numNodes int, imageType string) error {
72+
func clusterUpGCE(k8sDir, gceZone string, numNodes int, numWindowsNodes int, imageType string) error {
7173
kshPath := filepath.Join(k8sDir, "cluster", "kubectl.sh")
7274
_, err := os.Stat(kshPath)
7375
if err == nil {
@@ -98,6 +100,14 @@ func clusterUpGCE(k8sDir, gceZone string, numNodes int, imageType string) error
98100
return err
99101
}
100102

103+
// the chain is NUM_WINDOWS_NODES -> --num-windows-nodes -> NUM_WINDOWS_NODES
104+
// runCommand runs e2e-up.sh inheriting env vars so the `--num-windows-nodes`
105+
// flags might not be needed, added to be similar to the setup of NUM_NODES
106+
err = os.Setenv("NUM_WINDOWS_NODES", strconv.Itoa(numWindowsNodes))
107+
if err != nil {
108+
return err
109+
}
110+
101111
// The default master size with few nodes is too small; the tests must hit the API server
102112
// more than usual. The main issue seems to be memory, to reduce GC times that stall the
103113
// api server. For defaults, get-master-size in k/k/cluster/gce/config-common.sh.
@@ -113,6 +123,7 @@ func clusterUpGCE(k8sDir, gceZone string, numNodes int, imageType string) error
113123
return err
114124
}
115125
cmd := exec.Command(filepath.Join(k8sDir, "hack", "e2e-internal", "e2e-up.sh"))
126+
cmd.Env = os.Environ()
116127
err = runCommand("Starting E2E Cluster on GCE", cmd)
117128
if err != nil {
118129
return fmt.Errorf("failed to bring up kubernetes e2e cluster on gce: %v", err)
@@ -147,7 +158,7 @@ func setImageTypeEnvs(imageType string) error {
147158
return nil
148159
}
149160

150-
func clusterUpGKE(gceZone, gceRegion string, numNodes int, imageType string, useManagedDriver bool) error {
161+
func clusterUpGKE(gceZone, gceRegion string, numNodes int, numWindowsNodes int, imageType string, useManagedDriver bool) error {
151162
locationArg, locationVal, err := gkeLocationArgs(gceZone, gceRegion)
152163
if err != nil {
153164
return err
@@ -213,7 +224,7 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, imageType string, use
213224

214225
func downloadKubernetesSource(pkgDir, k8sIoDir, kubeVersion string) error {
215226
k8sDir := filepath.Join(k8sIoDir, "kubernetes")
216-
klog.Infof("Downloading Kubernetes source for %s", kubeVersion)
227+
klog.Infof("Downloading Kubernetes source v=%s to path=%s", kubeVersion, k8sIoDir)
217228

218229
if err := os.MkdirAll(k8sIoDir, 0777); err != nil {
219230
return err

test/k8s-integration/main.go

+32-27
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ var (
4545
localK8sDir = flag.String("local-k8s-dir", "", "local prebuilt kubernetes/kubernetes directory to use for cluster and test binaries")
4646
deploymentStrat = flag.String("deployment-strategy", "gce", "choose between deploying on gce or gke")
4747
gkeClusterVer = flag.String("gke-cluster-version", "", "version of Kubernetes master and node for gke")
48-
numNodes = flag.Int("num-nodes", -1, "the number of nodes in the test cluster")
48+
numNodes = flag.Int("num-nodes", 0, "the number of nodes in the test cluster")
49+
numWindowsNodes = flag.Int("num-windows-nodes", 0, "the number of Windows nodes in the test cluster")
4950
imageType = flag.String("image-type", "cos", "the image type to use for the cluster")
5051
gkeReleaseChannel = flag.String("gke-release-channel", "", "GKE release channel to be used for cluster deploy. One of 'rapid', 'stable' or 'regular'")
5152
gkeTestClusterPrefix = flag.String("gke-cluster-prefix", "pdcsi", "Prefix of GKE cluster names. A random suffix will be appended to form the full name.")
@@ -160,10 +161,6 @@ func main() {
160161
}
161162
}
162163

163-
if *platform == "windows" {
164-
ensureFlag(bringupCluster, false, "bringupCluster is set to false if it is for testing in windows cluster")
165-
}
166-
167164
if *deploymentStrat == "gke" {
168165
ensureVariable(kubeVersion, false, "Cannot set kube-version when using deployment strategy 'gke'. Use gke-cluster-version.")
169166
ensureExactlyOneVariableSet([]*string{gkeClusterVer, gkeReleaseChannel},
@@ -186,9 +183,12 @@ func main() {
186183
ensureVariable(testVersion, false, "Cannot set a test version when using a local k8s dir.")
187184
}
188185

189-
if *numNodes == -1 && *bringupCluster {
186+
if *numNodes == 0 && *bringupCluster {
190187
klog.Fatalf("num-nodes must be set to number of nodes in cluster")
191188
}
189+
if *numWindowsNodes == 0 && *bringupCluster && *platform == "windows" {
190+
klog.Fatalf("num-windows-nodes must be set if the platform is windows")
191+
}
192192

193193
err := handle()
194194
if err != nil {
@@ -225,24 +225,19 @@ func handle() error {
225225
if err != nil {
226226
return fmt.Errorf("failed to get gcloud project: %s, err: %v", oldProject, err)
227227
}
228-
// TODO: Currently for prow tests with linux cluster, here it manually sets up a project from Boskos.
229-
// For Windows, we used kubernetes_e2e.py which already set up the project and kubernetes automatically.
230-
// Will update Linux in the future to use the same way as Windows test.
231-
if *platform != "windows" {
232-
newproject, _ := testutils.SetupProwConfig(*boskosResourceType)
233-
err = setEnvProject(newproject)
228+
newproject, _ := testutils.SetupProwConfig(*boskosResourceType)
229+
err = setEnvProject(newproject)
230+
if err != nil {
231+
return fmt.Errorf("failed to set project environment to %s: %v", newproject, err)
232+
}
233+
234+
defer func() {
235+
err = setEnvProject(string(oldProject))
234236
if err != nil {
235-
return fmt.Errorf("failed to set project environment to %s: %v", newproject, err)
237+
klog.Errorf("failed to set project environment to %s: %v", oldProject, err)
236238
}
237-
238-
defer func() {
239-
err = setEnvProject(string(oldProject))
240-
if err != nil {
241-
klog.Errorf("failed to set project environment to %s: %v", oldProject, err)
242-
}
243-
}()
244-
project = newproject
245-
}
239+
}()
240+
project = newproject
246241
if *doDriverBuild {
247242
*stagingImage = fmt.Sprintf("gcr.io/%s/gcp-persistent-disk-csi-driver", strings.TrimSpace(string(project)))
248243
}
@@ -256,6 +251,7 @@ func handle() error {
256251

257252
// Build and push the driver, if required. Defer the driver image deletion.
258253
if *doDriverBuild {
254+
klog.Infof("Building GCE PD CSI Driver")
259255
err := pushImage(testParams.pkgDir, *stagingImage, testParams.stagingVersion, testParams.platform)
260256
if err != nil {
261257
return fmt.Errorf("failed pushing image: %v", err)
@@ -326,9 +322,9 @@ func handle() error {
326322
var err error = nil
327323
switch *deploymentStrat {
328324
case "gce":
329-
err = clusterUpGCE(testParams.k8sSourceDir, *gceZone, *numNodes, testParams.imageType)
325+
err = clusterUpGCE(testParams.k8sSourceDir, *gceZone, *numNodes, *numWindowsNodes, testParams.imageType)
330326
case "gke":
331-
err = clusterUpGKE(*gceZone, *gceRegion, *numNodes, testParams.imageType, testParams.useGKEManagedDriver)
327+
err = clusterUpGKE(*gceZone, *gceRegion, *numNodes, *numWindowsNodes, testParams.imageType, testParams.useGKEManagedDriver)
332328
default:
333329
err = fmt.Errorf("deployment-strategy must be set to 'gce' or 'gke', but is: %s", testParams.deploymentStrategy)
334330
}
@@ -360,6 +356,8 @@ func handle() error {
360356
// For windows cluster, when cluster is up, all Windows nodes are tainted with NoSchedule to avoid linux pods
361357
// being scheduled to Windows nodes. When running windows tests, we need to remove the taint.
362358
if testParams.platform == "windows" {
359+
klog.Infof("Removing taints from all windows nodes.")
360+
363361
nodesCmd := exec.Command("kubectl", "get", "nodes", "-l", "kubernetes.io/os=windows", "-o", "name")
364362
out, err := nodesCmd.CombinedOutput()
365363
if err != nil {
@@ -428,6 +426,7 @@ func handle() error {
428426
// unschedulable.
429427
testParams.allowedNotReadyNodes = 0
430428
if *platform == "windows" {
429+
klog.Infof("Tainting linux nodes")
431430
nodesCmd := exec.Command("kubectl", "get", "nodes", "-l", "kubernetes.io/os=linux", "-o", "name")
432431
out, err := nodesCmd.CombinedOutput()
433432
if err != nil {
@@ -664,7 +663,6 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
664663
testArgs := fmt.Sprintf("%s %s", ginkgoArgs, testConfigArg)
665664

666665
// kubetest2 flags
667-
668666
var runID string
669667
if uid, exists := os.LookupEnv("PROW_JOB_ID"); exists && uid != "" {
670668
// reuse uid for CI use cases
@@ -673,20 +671,27 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
673671
runID = string(uuid.NewUUID())
674672
}
675673

674+
// Usage: kubetest2 <deployer> [Flags] [DeployerFlags] -- [TesterArgs]
675+
// [Flags]
676676
kubeTest2Args := []string{
677677
*deploymentStrat,
678678
fmt.Sprintf("--run-id=%s", runID),
679679
"--test=ginkgo",
680680
}
681+
682+
// [DeployerFlags]
681683
kubeTest2Args = append(kubeTest2Args, testParams.cloudProviderArgs...)
682684
if kubetestDumpDir != "" {
683685
kubeTest2Args = append(kubeTest2Args, fmt.Sprintf("--artifacts=%s", kubetestDumpDir))
684686
}
687+
685688
kubeTest2Args = append(kubeTest2Args, "--")
689+
690+
// [TesterArgs]
686691
if len(*testVersion) != 0 {
687692
if *testVersion == "master" {
688-
// the kubernetes binaries should've already been built above
689-
// or by the user if --localK8sDir was set, these binaries should be copied to the
693+
// the kubernetes binaries should've already been built above because of `--kube-version`
694+
// or by the user if --local-k8s-dir was set, these binaries should be copied to the
690695
// path sent to kubetest2 through its --artifacts path
691696

692697
// pkg/_artifacts is the default value that kubetests uses for --artifacts

test/k8s-integration/utils.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"os"
76
"os/exec"
@@ -14,8 +13,9 @@ func runCommand(action string, cmd *exec.Cmd) error {
1413
cmd.Stdin = os.Stdin
1514
cmd.Stderr = os.Stderr
1615

17-
fmt.Printf("%s\n", action)
18-
fmt.Printf("%s\n", cmd.Args)
16+
klog.Infof("%s", action)
17+
klog.Infof("cmd env=%v", cmd.Env)
18+
klog.Infof("cmd args=%s", cmd.Args)
1919

2020
err := cmd.Start()
2121
if err != nil {

test/run-k8s-integration-ci.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
22

33
# Optional environment variables
44
# GCE_PD_OVERLAY_NAME: which Kustomize overlay to deploy with
55
# GCE_PD_DO_DRIVER_BUILD: if set, don't build the driver from source and just
66
# use the driver version from the overlay
77
# GCE_PD_BOSKOS_RESOURCE_TYPE: name of the boskos resource type to reserve
88

9+
set -o xtrace
910
set -o nounset
1011
set -o errexit
1112

test/run-k8s-integration.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# use the driver version from the overlay
77
# GCE_PD_BOSKOS_RESOURCE_TYPE: name of the boskos resource type to reserve
88

9+
set -o xtrace
910
set -o nounset
1011
set -o errexit
1112

test/run-windows-k8s-integration.sh

+4-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -o nounset
1111
set -o errexit
1212

1313
readonly PKGDIR=${GOPATH}/src/sigs.k8s.io/gcp-compute-persistent-disk-csi-driver
14-
readonly overlay_name="${GCE_PD_OVERLAY_NAME:-noauth}"
14+
readonly overlay_name="${GCE_PD_OVERLAY_NAME:-stable-master}"
1515
readonly do_driver_build="${GCE_PD_DO_DRIVER_BUILD:-true}"
1616
readonly deployment_strategy=${DEPLOYMENT_STRATEGY:-gce}
1717
readonly kube_version=${GCE_PD_KUBE_VERSION:-master}
@@ -22,7 +22,7 @@ readonly use_kubetest2=${USE_KUBETEST2:-true}
2222
readonly num_windows_nodes=${NUM_WINDOWS_NODES:-3}
2323

2424
# build platforms for `make quick-release`
25-
export KUBE_BUILD_PLATFORMS="linux/amd64 windows/amd64"
25+
export KUBE_BUILD_PLATFORMS=${KUBE_BUILD_PLATFORMS:-"linux/amd64 windows/amd64"}
2626

2727
make -C "${PKGDIR}" test-k8s-integration
2828

@@ -33,21 +33,8 @@ if [ "$use_kubetest2" = true ]; then
3333
go install sigs.k8s.io/kubetest2/kubetest2-tester-ginkgo@latest;
3434
fi
3535

36-
# TODO(mauriciopoppe): remove this assignment
37-
E2E_GOOGLE_APPLICATION_CREDENTIALS=sa
38-
39-
# TODO(mauriciopoppe): change run-in-prow=true
40-
41-
# TODO(mauriciopoppe): change overlay back to stable-master
42-
43-
# TODO(mauriciopoppe): remove --staging-image and this flag
44-
GCE_PD_CSI_STAGING_IMAGE=gcr.io/mauriciopoppe-gke-dev/gcp-compute-persistent-disk-csi-driver
45-
46-
# TODO(mauriciopoppe): change to --do-driver-build=${do_driver_build} \
47-
4836
base_cmd="${PKGDIR}/bin/k8s-integration-test \
49-
--staging-image="${GCE_PD_CSI_STAGING_IMAGE}" \
50-
--run-in-prow=false \
37+
--run-in-prow=true \
5138
--service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
5239
--deployment-strategy=${deployment_strategy} \
5340
--gce-zone=${gce_zone} \
@@ -57,7 +44,7 @@ base_cmd="${PKGDIR}/bin/k8s-integration-test \
5744
--num-nodes=1 \
5845
--num-windows-nodes=${num_windows_nodes} \
5946
--teardown-driver=${teardown_driver} \
60-
--do-driver-build=true \
47+
--do-driver-build=${do_driver_build} \
6148
--deploy-overlay-name=${overlay_name} \
6249
--test-version=${test_version} \
6350
--kube-version=${kube_version} \

0 commit comments

Comments
 (0)