Skip to content

Commit

Permalink
Merge pull request #103 from dasmeta/DMVP-4602-efs
Browse files Browse the repository at this point in the history
feat(DMVP-4602): Added feature to have multiple storage classes
  • Loading branch information
viktoryathegreat authored Jul 31, 2024
2 parents 3ef6f85 + d311976 commit a1e727d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ worker_groups = {
| <a name="input_create_cert_manager"></a> [create\_cert\_manager](#input\_create\_cert\_manager) | If enabled it always gets deployed to the cert-manager namespace. | `bool` | `false` | no |
| <a name="input_ebs_csi_version"></a> [ebs\_csi\_version](#input\_ebs\_csi\_version) | EBS CSI driver addon version | `string` | `"v1.15.0-eksbuild.1"` | no |
| <a name="input_efs_id"></a> [efs\_id](#input\_efs\_id) | EFS filesystem id in AWS | `string` | `null` | no |
| <a name="input_efs_storage_classes"></a> [efs\_storage\_classes](#input\_efs\_storage\_classes) | Additional storage class configurations: by default, 2 storage classes are created - efs-sc and efs-sc-root which has 0 uid. One can add another storage classes besides these 2. | <pre>list(object({<br> name : string<br> provisioning_mode : optional(string, "efs-ap")<br> file_system_id : string<br> directory_perms : optional(string, "755")<br> base_path : optional(string, "/")<br> uid : optional(number)<br> }))</pre> | `[]` | no |
| <a name="input_enable_api_gw_controller"></a> [enable\_api\_gw\_controller](#input\_enable\_api\_gw\_controller) | Weather enable API-GW controller or not | `bool` | `false` | no |
| <a name="input_enable_ebs_driver"></a> [enable\_ebs\_driver](#input\_enable\_ebs\_driver) | Weather enable EBS-CSI driver or not | `bool` | `true` | no |
| <a name="input_enable_efs_driver"></a> [enable\_efs\_driver](#input\_enable\_efs\_driver) | Weather install EFS driver or not in EKS | `bool` | `false` | no |
Expand Down
2 changes: 1 addition & 1 deletion examples/spot-instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.41 |

## Modules

Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ module "efs-csi-driver" {
cluster_name = var.cluster_name
efs_id = var.efs_id
cluster_oidc_arn = module.eks-cluster[0].oidc_provider_arn
storage_classes = var.efs_storage_classes
}

resource "helm_release" "cert-manager" {
Expand Down
3 changes: 2 additions & 1 deletion modules/efs-csi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ No modules.
| [aws_iam_role.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [helm_release.efs-driver](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubernetes_service_account.servciceaccount](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service_account) | resource |
| [kubernetes_storage_class.efs-storage-class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
| [kubernetes_storage_class.efs_storage_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/storage_class) | resource |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

## Inputs
Expand All @@ -57,6 +57,7 @@ No modules.
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Parent cluster name | `string` | n/a | yes |
| <a name="input_cluster_oidc_arn"></a> [cluster\_oidc\_arn](#input\_cluster\_oidc\_arn) | oidc arn of cluster | `string` | n/a | yes |
| <a name="input_efs_id"></a> [efs\_id](#input\_efs\_id) | Id of EFS filesystem in AWS (Required) | `string` | n/a | yes |
| <a name="input_storage_classes"></a> [storage\_classes](#input\_storage\_classes) | Additional storage class configurations: by default, 2 storage classes are created - efs-sc and efs-sc-root which has 0 uid. One can add another storage classes besides these 2. | <pre>list(object({<br> name : string<br> provisioning_mode : optional(string, "efs-ap")<br> file_system_id : string<br> directory_perms : optional(string, "755")<br> base_path : optional(string, "/")<br> uid : optional(number)<br> }))</pre> | `[]` | no |

## Outputs

Expand Down
47 changes: 39 additions & 8 deletions modules/efs-csi/storageClass.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
resource "kubernetes_storage_class" "efs-storage-class" {
locals {
default_storage_classes = [
{
name : "efs-sc"
provisioning_mode : "efs-ap"
file_system_id : var.efs_id
directory_perms : "755"
base_path : "/eks"
uid : null
},
{
name : "efs-sc-root"
provisioning_mode : "efs-ap"
file_system_id : var.efs_id
directory_perms : "755"
base_path : "/eks-root"
uid : 0
}
]

combined_storage_classes = concat(local.default_storage_classes, var.storage_classes)
}


resource "kubernetes_storage_class" "efs_storage_class" {
for_each = { for sc in local.combined_storage_classes : sc.name => sc }

metadata {
name = "efs-sc"
name = each.value.name
}

storage_provisioner = "efs.csi.aws.com"
parameters = {
provisioningMode : "efs-ap"
fileSystemId : var.efs_id
directoryPerms : "755"
basePath : "/eks"
}

parameters = merge(
{
provisioningMode = each.value.provisioning_mode
fileSystemId = each.value.file_system_id
directoryPerms = each.value.directory_perms
basePath = each.value.base_path
},
each.value.uid != null ? { "uid" : each.value.uid } : {}
)
}
13 changes: 13 additions & 0 deletions modules/efs-csi/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ variable "cluster_name" {
description = "Parent cluster name"
type = string
}

variable "storage_classes" {
description = "Additional storage class configurations: by default, 2 storage classes are created - efs-sc and efs-sc-root which has 0 uid. One can add another storage classes besides these 2."
type = list(object({
name : string
provisioning_mode : optional(string, "efs-ap")
file_system_id : string
directory_perms : optional(string, "755")
base_path : optional(string, "/")
uid : optional(number)
}))
default = []
}
2 changes: 1 addition & 1 deletion tests/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ No requirements.

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion tests/eks-nginx-ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ No requirements.

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.67.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |

## Modules

Expand Down
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ variable "enable_efs_driver" {
description = "Weather install EFS driver or not in EKS"
}

variable "efs_storage_classes" {
description = "Additional storage class configurations: by default, 2 storage classes are created - efs-sc and efs-sc-root which has 0 uid. One can add another storage classes besides these 2."
type = list(object({
name : string
provisioning_mode : optional(string, "efs-ap")
file_system_id : string
directory_perms : optional(string, "755")
base_path : optional(string, "/")
uid : optional(number)
}))
default = []
}

variable "efs_id" {
description = "EFS filesystem id in AWS"
type = string
Expand Down

0 comments on commit a1e727d

Please sign in to comment.