From 54d9c4ea25ecb0ffb829145238680486c7e9ee92 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 9 May 2018 11:00:41 +0200 Subject: [PATCH 1/2] e2e/storage: parameterize container images The CSI integration test for hostpath was hard-coded to use the latest stable release of the sidecar and hostpath container images. This makes sense for regression testing of changes made in Kubernetes itself, but the same test is also useful for testing the "canary" images on quay.io before tagging them as a new release or for testing locally produced images. Both is now possible via command line parameters. Testing "canary" images on quay.io: go run hack/e2e.go -- --provider=local --test \ --test_args="--ginkgo.focus=CSI.plugin.test.using.CSI.driver..hostPath -csiImageVersion=canary" Testing local container images: # https://docs.docker.com/registry/deploying/ docker run -d -p 5000:5000 --restart=always --name registry registry:2 for i in driver-registrar drivers external-attacher external-provisioner; do make -C $i REGISTRY_NAME=localhost:5000 push done go run hack/e2e.go -- --provider=local --test \ --test_args="--ginkgo.focus=CSI.plugin.test.using.CSI.driver..hostPath -csiImageVersion=canary -csiImageRegistry=localhost:5000" --- test/e2e/storage/csi_objects.go | 39 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/test/e2e/storage/csi_objects.go b/test/e2e/storage/csi_objects.go index d888abdbb5c..2836f11d1c6 100644 --- a/test/e2e/storage/csi_objects.go +++ b/test/e2e/storage/csi_objects.go @@ -20,6 +20,7 @@ limitations under the License. package storage import ( + "flag" "fmt" "time" @@ -37,12 +38,30 @@ import ( . "github.com/onsi/ginkgo" ) -const ( - csiHostPathPluginImage string = "quay.io/k8scsi/hostpathplugin:v0.2.0" - csiExternalAttacherImage string = "quay.io/k8scsi/csi-attacher:v0.2.0" - csiExternalProvisionerImage string = "quay.io/k8scsi/csi-provisioner:v0.2.1" - csiDriverRegistrarImage string = "quay.io/k8scsi/driver-registrar:v0.2.0" -) +var csiImageVersions = map[string]string{ + "hostpathplugin": "v0.2.0", + "csi-attacher": "v0.2.0", + "csi-provisioner": "v0.2.1", + "driver-registrar": "v0.2.0", +} +var csiImageVersion string +var csiImageRegistry string + +func init() { + flag.StringVar(&csiImageVersion, "csiImageVersion", "", "overrides the default tag used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") + flag.StringVar(&csiImageRegistry, "csiImageRegistry", "quay.io/k8scsi", "overrides the default repository used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") +} + +func csiContainerImage(image string) string { + var fullName string + fullName += csiImageRegistry + "/" + image + ":" + if csiImageVersion != "" { + fullName += csiImageVersion + } else { + fullName += csiImageVersions[image] + } + return fullName +} // Create the driver registrar cluster role if it doesn't exist, no teardown so that tests // are parallelizable. This role will be shared with many of the CSI tests. @@ -207,7 +226,7 @@ func csiHostPathPod( Containers: []v1.Container{ { Name: "external-provisioner", - Image: csiExternalProvisionerImage, + Image: csiContainerImage("csi-provisioner"), ImagePullPolicy: v1.PullAlways, Args: []string{ "--v=5", @@ -223,7 +242,7 @@ func csiHostPathPod( }, { Name: "driver-registrar", - Image: csiDriverRegistrarImage, + Image: csiContainerImage("driver-registrar"), ImagePullPolicy: v1.PullAlways, Args: []string{ "--v=5", @@ -248,7 +267,7 @@ func csiHostPathPod( }, { Name: "external-attacher", - Image: csiExternalAttacherImage, + Image: csiContainerImage("csi-attacher"), ImagePullPolicy: v1.PullAlways, Args: []string{ "--v=5", @@ -269,7 +288,7 @@ func csiHostPathPod( }, { Name: "hostpath-driver", - Image: csiHostPathPluginImage, + Image: csiContainerImage("hostpathplugin"), ImagePullPolicy: v1.PullAlways, SecurityContext: &v1.SecurityContext{ Privileged: &priv, From cc2a5954acf570b7f919a9a7e274661cc830d3a3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 28 May 2018 11:44:20 +0200 Subject: [PATCH 2/2] e2e/storage: central argument handling Putting the command line argument handling into the central test context seems like the better solution, in particular considering that argument handling might get changed in the future to use Viper. --- test/e2e/framework/test_context.go | 16 ++++++++++++++++ test/e2e/storage/csi_objects.go | 14 +++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index c13e8e769f0..a4028e0688b 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -110,6 +110,8 @@ type TestContextType struct { FeatureGates map[string]bool // Node e2e specific test context NodeTestContextType + // Storage e2e specific test context + StorageTestContextType // Monitoring solution that is used in current cluster. ClusterMonitoringMode string // Separate Prometheus monitoring deployed in cluster @@ -157,6 +159,14 @@ type NodeTestContextType struct { SystemSpecName string } +// StorageConfig contains the shared settings for storage 2e2 tests. +type StorageTestContextType struct { + // CSIImageVersion overrides the builtin stable version numbers if set. + CSIImageVersion string + // CSIImageRegistry defines the image registry hosting the CSI container images. + CSIImageRegistry string +} + type CloudConfig struct { ApiEndpoint string ProjectID string @@ -290,6 +300,11 @@ func RegisterNodeFlags() { flag.StringVar(&TestContext.SystemSpecName, "system-spec-name", "", "The name of the system spec (e.g., gke) that's used in the node e2e test. The system specs are in test/e2e_node/system/specs/. This is used by the test framework to determine which tests to run for validating the system requirements.") } +func RegisterStorageFlags() { + flag.StringVar(&TestContext.CSIImageVersion, "csiImageVersion", "", "overrides the default tag used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") + flag.StringVar(&TestContext.CSIImageRegistry, "csiImageRegistry", "quay.io/k8scsi", "overrides the default repository used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") +} + // ViperizeFlags sets up all flag and config processing. Future configuration info should be added to viper, not to flags. func ViperizeFlags() { @@ -298,6 +313,7 @@ func ViperizeFlags() { // since go test 'flag's are sort of incompatible w/ flag, glog, etc. RegisterCommonFlags() RegisterClusterFlags() + RegisterStorageFlags() flag.Parse() // Part 2: Set Viper provided flags. diff --git a/test/e2e/storage/csi_objects.go b/test/e2e/storage/csi_objects.go index 2836f11d1c6..15fd7cf3282 100644 --- a/test/e2e/storage/csi_objects.go +++ b/test/e2e/storage/csi_objects.go @@ -20,7 +20,6 @@ limitations under the License. package storage import ( - "flag" "fmt" "time" @@ -44,19 +43,12 @@ var csiImageVersions = map[string]string{ "csi-provisioner": "v0.2.1", "driver-registrar": "v0.2.0", } -var csiImageVersion string -var csiImageRegistry string - -func init() { - flag.StringVar(&csiImageVersion, "csiImageVersion", "", "overrides the default tag used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") - flag.StringVar(&csiImageRegistry, "csiImageRegistry", "quay.io/k8scsi", "overrides the default repository used for hostpathplugin/csi-attacher/csi-provisioner/driver-registrar images") -} func csiContainerImage(image string) string { var fullName string - fullName += csiImageRegistry + "/" + image + ":" - if csiImageVersion != "" { - fullName += csiImageVersion + fullName += framework.TestContext.CSIImageRegistry + "/" + image + ":" + if framework.TestContext.CSIImageVersion != "" { + fullName += framework.TestContext.CSIImageVersion } else { fullName += csiImageVersions[image] }