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.
This commit is contained in:
Tim Gross 2020-10-14 10:29:33 -04:00 committed by GitHub
parent 65282a7cf1
commit 115edb53a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 6 deletions

View file

@ -36,6 +36,17 @@ func init() {
func (tc *CSIVolumesTest) BeforeAll(f *framework.F) { func (tc *CSIVolumesTest) BeforeAll(f *framework.F) {
t := f.T() 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 // Ensure cluster has leader and at least two client
// nodes in a ready state before running tests // nodes in a ready state before running tests
e2eutil.WaitForLeader(t, tc.Nomad()) e2eutil.WaitForLeader(t, tc.Nomad())

View file

@ -90,6 +90,7 @@ resource "aws_security_group" "primary" {
} }
resource "aws_security_group" "nfs" { resource "aws_security_group" "nfs" {
count = var.volumes ? 1 : 0
name = "${local.random_name}-nfs" name = "${local.random_name}-nfs"
vpc_id = data.aws_vpc.default.id vpc_id = data.aws_vpc.default.id

View file

@ -7,3 +7,4 @@ profile = "full-cluster"
nomad_enterprise = true nomad_enterprise = true
nomad_acls = true nomad_acls = true
vault = true vault = true
volumes = true

View file

@ -7,6 +7,7 @@ profile = "dev-cluster"
nomad_acls = false nomad_acls = false
nomad_enterprise = false nomad_enterprise = false
vault = true vault = true
volumes = false
# Example overrides: # Example overrides:
# nomad_local_binary = "../../pkg/linux_amd/nomad" # nomad_local_binary = "../../pkg/linux_amd/nomad"

View file

@ -91,6 +91,12 @@ variable "vault" {
default = false 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 # 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, # provide a list of builds to override the values of nomad_sha, nomad_version,

View file

@ -1,4 +1,5 @@
resource "aws_efs_file_system" "csi" { resource "aws_efs_file_system" "csi" {
count = var.volumes ? 1 : 0
creation_token = "${local.random_name}-CSI" creation_token = "${local.random_name}-CSI"
tags = { tags = {
@ -8,12 +9,14 @@ resource "aws_efs_file_system" "csi" {
} }
resource "aws_efs_mount_target" "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 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" { resource "aws_ebs_volume" "csi" {
count = var.volumes ? 1 : 0
availability_zone = var.availability_zone availability_zone = var.availability_zone
size = 40 size = 40
@ -24,11 +27,12 @@ resource "aws_ebs_volume" "csi" {
} }
data "template_file" "ebs_volume_hcl" { data "template_file" "ebs_volume_hcl" {
count = var.volumes ? 1 : 0
template = <<EOT template = <<EOT
type = "csi" type = "csi"
id = "ebs-vol0" id = "ebs-vol0"
name = "ebs-vol0" name = "ebs-vol0"
external_id = "${aws_ebs_volume.csi.id}" external_id = "${aws_ebs_volume.csi[0].id}"
access_mode = "single-node-writer" access_mode = "single-node-writer"
attachment_mode = "file-system" attachment_mode = "file-system"
plugin_id = "aws-ebs0" plugin_id = "aws-ebs0"
@ -36,11 +40,12 @@ EOT
} }
data "template_file" "efs_volume_hcl" { data "template_file" "efs_volume_hcl" {
count = var.volumes ? 1 : 0
template = <<EOT template = <<EOT
type = "csi" type = "csi"
id = "efs-vol0" id = "efs-vol0"
name = "efs-vol0" name = "efs-vol0"
external_id = "${aws_efs_file_system.csi.id}" external_id = "${aws_efs_file_system.csi[0].id}"
access_mode = "single-node-writer" access_mode = "single-node-writer"
attachment_mode = "file-system" attachment_mode = "file-system"
plugin_id = "aws-efs0" plugin_id = "aws-efs0"
@ -48,13 +53,15 @@ EOT
} }
resource "local_file" "ebs_volume_hcl" { resource "local_file" "ebs_volume_hcl" {
content = data.template_file.ebs_volume_hcl.rendered count = var.volumes ? 1 : 0
content = data.template_file.ebs_volume_hcl[0].rendered
filename = "${path.module}/../csi/input/volume-ebs.hcl" filename = "${path.module}/../csi/input/volume-ebs.hcl"
file_permission = "0664" file_permission = "0664"
} }
resource "local_file" "efs_volume_hcl" { resource "local_file" "efs_volume_hcl" {
content = data.template_file.efs_volume_hcl.rendered count = var.volumes ? 1 : 0
content = data.template_file.efs_volume_hcl[0].rendered
filename = "${path.module}/../csi/input/volume-efs.hcl" filename = "${path.module}/../csi/input/volume-efs.hcl"
file_permission = "0664" file_permission = "0664"
} }