From 115edb53a09e5774af8c91a2c515817065ed67b3 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 14 Oct 2020 10:29:33 -0400 Subject: [PATCH] e2e: add flag to opt-in to creating EBS/EFS volumes (#9082) For everyday developer use, we don't need volumes for testing CSI. Providing a flag to opt-in speeds up deploying dev clusters and slightly reduces infra costs. Skip CSI test if missing volume specs. --- e2e/csi/csi.go | 11 +++++++++++ e2e/terraform/network.tf | 1 + e2e/terraform/terraform.tfvars | 1 + e2e/terraform/terraform.tfvars.dev | 1 + e2e/terraform/variables.tf | 6 ++++++ e2e/terraform/volumes.tf | 19 +++++++++++++------ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/e2e/csi/csi.go b/e2e/csi/csi.go index dce49a767..4e986dea8 100644 --- a/e2e/csi/csi.go +++ b/e2e/csi/csi.go @@ -36,6 +36,17 @@ func init() { func (tc *CSIVolumesTest) BeforeAll(f *framework.F) { t := f.T() + + _, err := os.Stat("csi/input/volume-ebs.hcl") + if err != nil { + t.Skip("skipping CSI test because EBS volume spec file missing:", err) + } + + _, err = os.Stat("csi/input/volume-efs.hcl") + if err != nil { + t.Skip("skipping CSI test because EFS volume spec file missing:", err) + } + // Ensure cluster has leader and at least two client // nodes in a ready state before running tests e2eutil.WaitForLeader(t, tc.Nomad()) diff --git a/e2e/terraform/network.tf b/e2e/terraform/network.tf index 23241c729..6b72bdd22 100644 --- a/e2e/terraform/network.tf +++ b/e2e/terraform/network.tf @@ -90,6 +90,7 @@ resource "aws_security_group" "primary" { } resource "aws_security_group" "nfs" { + count = var.volumes ? 1 : 0 name = "${local.random_name}-nfs" vpc_id = data.aws_vpc.default.id diff --git a/e2e/terraform/terraform.tfvars b/e2e/terraform/terraform.tfvars index 5107285f5..df9dc9c11 100644 --- a/e2e/terraform/terraform.tfvars +++ b/e2e/terraform/terraform.tfvars @@ -7,3 +7,4 @@ profile = "full-cluster" nomad_enterprise = true nomad_acls = true vault = true +volumes = true diff --git a/e2e/terraform/terraform.tfvars.dev b/e2e/terraform/terraform.tfvars.dev index dad134ccc..3b65e4a70 100644 --- a/e2e/terraform/terraform.tfvars.dev +++ b/e2e/terraform/terraform.tfvars.dev @@ -7,6 +7,7 @@ profile = "dev-cluster" nomad_acls = false nomad_enterprise = false vault = true +volumes = false # Example overrides: # nomad_local_binary = "../../pkg/linux_amd/nomad" diff --git a/e2e/terraform/variables.tf b/e2e/terraform/variables.tf index 9c7bf217c..79a648b43 100644 --- a/e2e/terraform/variables.tf +++ b/e2e/terraform/variables.tf @@ -91,6 +91,12 @@ variable "vault" { default = false } +variable "volumes" { + type = bool + description = "Include external EBS and EFS volumes (for CSI)" + default = false +} + # ---------------------------------------- # If you want to deploy multiple versions you can use these variables to # provide a list of builds to override the values of nomad_sha, nomad_version, diff --git a/e2e/terraform/volumes.tf b/e2e/terraform/volumes.tf index 966d041e5..cd4bc9221 100644 --- a/e2e/terraform/volumes.tf +++ b/e2e/terraform/volumes.tf @@ -1,4 +1,5 @@ resource "aws_efs_file_system" "csi" { + count = var.volumes ? 1 : 0 creation_token = "${local.random_name}-CSI" tags = { @@ -8,12 +9,14 @@ resource "aws_efs_file_system" "csi" { } resource "aws_efs_mount_target" "csi" { - file_system_id = aws_efs_file_system.csi.id + count = var.volumes ? 1 : 0 + file_system_id = aws_efs_file_system.csi[0].id subnet_id = data.aws_subnet.default.id - security_groups = [aws_security_group.nfs.id] + security_groups = [aws_security_group.nfs[0].id] } resource "aws_ebs_volume" "csi" { + count = var.volumes ? 1 : 0 availability_zone = var.availability_zone size = 40 @@ -24,11 +27,12 @@ resource "aws_ebs_volume" "csi" { } data "template_file" "ebs_volume_hcl" { + count = var.volumes ? 1 : 0 template = <