Skip to content

Commit

Permalink
add dynamic block for containers (resize, snapshot) in the right place
Browse files Browse the repository at this point in the history
fix toleration var defaults
  • Loading branch information
DrFaust92 committed Jul 30, 2020
1 parent af79992 commit fe05183
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 58 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ module "ebs_csi_driver_controller" {
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| csi\_controller\_replica\_count | Number of EBS CSI driver controller pods | `number` | `2` | no |
| csi\_controller\_tolerations | CSI driver controller tolerations | `list(map(string))` | <pre>[<br> {}<br>]</pre> | no |
| csi\_controller\_tolerations | CSI driver controller tolerations | `list(map(string))` | `[]` | no |
| ebs\_csi\_controller\_role\_name | The name of the EBS CSI driver IAM role | `string` | `"ebs-csi-driver-controller"` | no |
| ebs\_csi\_controller\_role\_policy\_name\_prefix | The prefix of the EBS CSI driver IAM policy | `string` | `"ebs-csi-driver-policy"` | no |
| enable\_volume\_resizing | Whether to enable volume resizing | `bool` | `false` | no |
| enable\_volume\_snapshot | Whether to enable volume snapshotting | `bool` | `false` | no |
| namespace | The K8s namespace for all EBS CSI driver resources | `string` | `"kube-system"` | no |
| node\_tolerations | CSI driver node tolerations | `list(map(string))` | <pre>[<br> {}<br>]</pre> | no |
| node\_tolerations | CSI driver node tolerations | `list(map(string))` | `[]` | no |
| oidc\_url | EKS OIDC provider URL, to allow pod to assume role using IRSA | `string` | n/a | yes |
| tags | A map of tags to add to all resources | `map(string)` | `{}` | no |

Expand Down
48 changes: 48 additions & 0 deletions controller.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,54 @@ resource "kubernetes_deployment" "ebs_csi_controller" {
}
}

dynamic "container" {
for_each = local.resizer_container

content {
name = lookup(container.value, "name", null)
image = lookup(container.value, "image", null)

args = [
"--csi-address=$(ADDRESS)",
"--v=5"
]

env {
name = "ADDRESS"
value = "/var/lib/csi/sockets/pluginproxy/csi.sock"
}

volume_mount {
mount_path = "/var/lib/csi/sockets/pluginproxy/"
name = "socket-dir"
}
}
}

dynamic "container" {
for_each = local.snapshot_container

content {
name = lookup(container.value, "name", null)
image = lookup(container.value, "image", null)

args = [
"--csi-address=$(ADDRESS)",
"--leader-election=true"
]

env {
name = "ADDRESS"
value = "/var/lib/csi/sockets/pluginproxy/csi.sock"
}

volume_mount {
mount_path = "/var/lib/csi/sockets/pluginproxy/"
name = "socket-dir"
}
}
}

volume {
name = "socket-dir"
empty_dir {}
Expand Down
11 changes: 6 additions & 5 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
locals {
csi_volume_tags = join(",", [for key, value in var.tags : "${key}=${value}"])
controller_name = "ebs-csi-controller"
daemonset_name = "ebs-csi-node"
resizer_container = var.enable_volume_resizing ? [{}] : [{
csi_volume_tags = join(",", [for key, value in var.tags : "${key}=${value}"])

resizer_container = var.enable_volume_resizing ? [{
name = "csi-resizer",
image = "quay.io/k8scsi/csi-resizer:v0.3.0"
}]
}] : []

snapshot_container = var.enable_volume_snapshot ? [{}] : [{
snapshot_container = var.enable_volume_snapshot ? [{
name = "csi-snapshotter",
image = "quay.io/k8scsi/csi-snapshotter:2.1.1"
}]
}] : []
}
50 changes: 1 addition & 49 deletions node.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resource "kubernetes_daemonset" "node" {
}

container {
name = "ebs-plugin"
name = "ebs-plugin"
image = "amazon/aws-ebs-csi-driver:v0.5.0"
args = [
"node",
Expand Down Expand Up @@ -161,54 +161,6 @@ resource "kubernetes_daemonset" "node" {
}
}

dynamic "container" {
for_each = local.resizer_container

content {
name = lookup(container.value, "name", null)
image = lookup(container.value, "image", null)

args = [
"--csi-address=$(ADDRESS)",
"--v=5"
]

env {
name = "ADDRESS"
value = "/var/lib/csi/sockets/pluginproxy/csi.sock"
}

volume_mount {
mount_path = "/var/lib/csi/sockets/pluginproxy/"
name = "socket-dir"
}
}
}

dynamic "container" {
for_each = local.snapshot_container

content {
name = lookup(container.value, "name", null)
image = lookup(container.value, "image", null)

args = [
"--csi-address=$(ADDRESS)",
"--leader-election=true"
]

env {
name = "ADDRESS"
value = "/var/lib/csi/sockets/pluginproxy/csi.sock"
}

volume_mount {
mount_path = "/var/lib/csi/sockets/pluginproxy/"
name = "socket-dir"
}
}
}

volume {
name = "kubelet-dir"

Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ variable "oidc_url" {
variable "node_tolerations" {
description = "CSI driver node tolerations"
type = list(map(string))
default = [{}]
default = []
}

variable "csi_controller_tolerations" {
description = "CSI driver controller tolerations"
type = list(map(string))
default = [{}]
default = []
}

variable "csi_controller_replica_count" {
Expand Down

0 comments on commit fe05183

Please sign in to comment.