Skip to content

Commit 78c4de2

Browse files
committed
Swap
1 parent e529166 commit 78c4de2

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ No resources.
203203
| <a name="input_cert_manager_namespace"></a> [cert\_manager\_namespace](#input\_cert\_manager\_namespace) | The name of the namespace in which cert-manager is or will be installed. | `string` | `"cert-manager"` | no |
204204
| <a name="input_database_config"></a> [database\_config](#input\_database\_config) | Azure Database for PostgreSQL configuration | <pre>object({<br/> sku_name = optional(string, "GP_Standard_D2s_v3")<br/> postgres_version = optional(string, "15")<br/> password = string<br/> username = optional(string, "materialize")<br/> db_name = optional(string, "materialize")<br/> })</pre> | n/a | yes |
205205
| <a name="input_disk_setup_image"></a> [disk\_setup\_image](#input\_disk\_setup\_image) | Docker image for the disk setup script | `string` | `"materialize/ephemeral-storage-setup-image:v0.3.4"` | no |
206-
| <a name="input_disk_support_config"></a> [disk\_support\_config](#input\_disk\_support\_config) | Advanced configuration for disk support (only used when enable\_disk\_support = true) | <pre>object({<br/> install_openebs = optional(bool, true)<br/> run_disk_setup_script = optional(bool, true)<br/> create_storage_class = optional(bool, true)<br/> openebs_version = optional(string, "4.2.0")<br/> openebs_namespace = optional(string, "openebs")<br/> storage_class_name = optional(string, "openebs-lvm-instance-store-ext4")<br/> })</pre> | `{}` | no |
206+
| <a name="input_disk_support_config"></a> [disk\_support\_config](#input\_disk\_support\_config) | Advanced configuration for disk support (only used when enable\_disk\_support = true) | <pre>object({<br/> install_openebs = optional(bool, true)<br/> run_disk_setup_script = optional(bool, true)<br/> create_storage_class = optional(bool, true)<br/> openebs_version = optional(string, "4.3.3")<br/> openebs_namespace = optional(string, "openebs")<br/> storage_class_name = optional(string, "openebs-lvm-instance-store-ext4")<br/> })</pre> | `{}` | no |
207207
| <a name="input_enable_disk_support"></a> [enable\_disk\_support](#input\_enable\_disk\_support) | Enable disk support for Materialize using OpenEBS and local SSDs. When enabled, this configures OpenEBS, runs the disk setup script, and creates appropriate storage classes. | `bool` | `true` | no |
208208
| <a name="input_helm_chart"></a> [helm\_chart](#input\_helm\_chart) | Chart name from repository or local path to chart. For local charts, set the path to the chart directory. | `string` | `"materialize-operator"` | no |
209209
| <a name="input_helm_values"></a> [helm\_values](#input\_helm\_values) | Additional Helm values to merge with defaults | `any` | `{}` | no |
@@ -218,6 +218,7 @@ No resources.
218218
| <a name="input_orchestratord_version"></a> [orchestratord\_version](#input\_orchestratord\_version) | Version of the Materialize orchestrator to install | `string` | `null` | no |
219219
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix to be used for resource names | `string` | `"materialize"` | no |
220220
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of an existing resource group to use | `string` | n/a | yes |
221+
| <a name="input_swap_enabled"></a> [swap\_enabled](#input\_swap\_enabled) | Enable swap for Materialize. When enabled, this configures swap on a new nodepool, and adds it to the clusterd node selectors. | `bool` | `false` | no |
221222
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all resources | `map(string)` | `{}` | no |
222223
| <a name="input_use_local_chart"></a> [use\_local\_chart](#input\_use\_local\_chart) | Whether to use a local chart instead of one from a repository | `bool` | `false` | no |
223224
| <a name="input_use_self_signed_cluster_issuer"></a> [use\_self\_signed\_cluster\_issuer](#input\_use\_self\_signed\_cluster\_issuer) | Whether to install and use a self-signed ClusterIssuer for TLS. To work around limitations in Terraform, this will be treated as `false` if no materialize instances are defined. | `bool` | `true` | no |

examples/simple/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ module "materialize" {
9191

9292
materialize_instances = var.materialize_instances
9393

94+
swap_enabled = var.swap_enabled
95+
9496
database_config = {
9597
sku_name = "GP_Standard_D2s_v3"
9698
version = "15"
@@ -188,6 +190,12 @@ variable "use_self_signed_cluster_issuer" {
188190
default = true
189191
}
190192

193+
variable "swap_enabled" {
194+
description = "Enable swap for Materialize. When enabled, this configures swap on a new nodepool, and adds it to the clusterd node selectors."
195+
type = bool
196+
default = false
197+
}
198+
191199
# Output the Materialize instance details
192200
output "aks_cluster" {
193201
description = "AKS cluster details"

main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ module "aks" {
5959
openebs_version = local.disk_config.openebs_version
6060
disk_setup_image = var.disk_setup_image
6161

62+
# Swap configuration
63+
swap_enabled = var.swap_enabled
64+
6265
tags = local.common_labels
6366
}
6467

@@ -123,7 +126,7 @@ locals {
123126
region = var.location
124127
}
125128
clusters = {
126-
swap_enabled = false
129+
swap_enabled = var.swap_enabled
127130
}
128131
}
129132
observability = {

modules/aks/main.tf

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
locals {
2-
nodepool_name = substr(replace(var.prefix, "-", ""), 0, 12)
2+
nodepool_name = substr(replace(var.prefix, "-", ""), 0, 12)
3+
swap_nodepool_name = substr(replace("${var.prefix}-swap", "-", ""), 0, 12)
4+
disk_setup_name = "disk-setup-scratchfs"
35
}
46

57
resource "azurerm_user_assigned_identity" "aks_identity" {
@@ -84,12 +86,46 @@ resource "azurerm_kubernetes_cluster_node_pool" "materialize" {
8486
"materialize.cloud/disk-config-required" = var.enable_disk_setup ? "true" : "false"
8587
}
8688

89+
upgrade_settings {
90+
max_surge = "10%"
91+
drain_timeout_in_minutes = 0
92+
node_soak_duration_in_minutes = 0
93+
}
94+
8795
# Taints can not be removed: https://github.com/Azure/AKS/issues/2934
8896
# node_taints = var.enable_disk_setup ? ["materialize.cloud/disk-unconfigured=true:NoSchedule"] : []
8997

9098
tags = var.tags
9199
}
92100

101+
resource "azurerm_kubernetes_cluster_node_pool" "swap" {
102+
count = var.swap_enabled ? 1 : 0
103+
name = local.swap_nodepool_name
104+
temporary_name_for_rotation = "${local.swap_nodepool_name}2"
105+
kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id
106+
vm_size = var.vm_size
107+
auto_scaling_enabled = true
108+
min_count = var.min_nodes
109+
max_count = var.max_nodes
110+
vnet_subnet_id = var.subnet_id
111+
os_disk_size_gb = var.disk_size_gb
112+
113+
node_labels = {
114+
"materialize.cloud/scratch-fs" = "true"
115+
"materialize.cloud/swap" = "true"
116+
"workload" = "materialize-instance"
117+
"materialize.cloud/disk-config-required" = "true"
118+
}
119+
120+
upgrade_settings {
121+
max_surge = "10%"
122+
drain_timeout_in_minutes = 0
123+
node_soak_duration_in_minutes = 0
124+
}
125+
126+
tags = var.tags
127+
}
128+
93129
resource "kubernetes_namespace" "openebs" {
94130
count = var.install_openebs ? 1 : 0
95131

@@ -182,7 +218,7 @@ resource "kubernetes_namespace" "disk_setup" {
182218
count = var.enable_disk_setup ? 1 : 0
183219

184220
metadata {
185-
name = "disk-setup"
221+
name = local.disk_setup_name
186222
labels = {
187223
"app.kubernetes.io/managed-by" = "terraform"
188224
"app.kubernetes.io/part-of" = "materialize"
@@ -198,26 +234,26 @@ resource "kubernetes_daemonset" "disk_setup" {
198234
count = var.enable_disk_setup ? 1 : 0
199235

200236
metadata {
201-
name = "disk-setup"
237+
name = local.disk_setup_name
202238
namespace = kubernetes_namespace.disk_setup[0].metadata[0].name
203239
labels = {
204240
"app.kubernetes.io/managed-by" = "terraform"
205241
"app.kubernetes.io/part-of" = "materialize"
206-
"app" = "disk-setup"
242+
"app" = local.disk_setup_name
207243
}
208244
}
209245

210246
spec {
211247
selector {
212248
match_labels = {
213-
app = "disk-setup"
249+
app = local.disk_setup_name
214250
}
215251
}
216252

217253
template {
218254
metadata {
219255
labels = {
220-
app = "disk-setup"
256+
app = local.disk_setup_name
221257
}
222258
}
223259

@@ -236,7 +272,7 @@ resource "kubernetes_daemonset" "disk_setup" {
236272
required_during_scheduling_ignored_during_execution {
237273
node_selector_term {
238274
match_expressions {
239-
key = "materialize.cloud/disk"
275+
key = "materialize.cloud/scratch-fs"
240276
operator = "In"
241277
values = ["true"]
242278
}
@@ -346,15 +382,15 @@ resource "kubernetes_daemonset" "disk_setup" {
346382
resource "kubernetes_service_account" "disk_setup" {
347383
count = var.enable_disk_setup ? 1 : 0
348384
metadata {
349-
name = "disk-setup"
385+
name = local.disk_setup_name
350386
namespace = kubernetes_namespace.disk_setup[0].metadata[0].name
351387
}
352388
}
353389

354390
resource "kubernetes_cluster_role" "disk_setup" {
355391
count = var.enable_disk_setup ? 1 : 0
356392
metadata {
357-
name = "disk-setup"
393+
name = local.disk_setup_name
358394
}
359395
rule {
360396
api_groups = [""]
@@ -366,7 +402,7 @@ resource "kubernetes_cluster_role" "disk_setup" {
366402
resource "kubernetes_cluster_role_binding" "disk_setup" {
367403
count = var.enable_disk_setup ? 1 : 0
368404
metadata {
369-
name = "disk-setup"
405+
name = local.disk_setup_name
370406
}
371407
role_ref {
372408
api_group = "rbac.authorization.k8s.io"

modules/aks/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ variable "disk_setup_image" {
9090
type = string
9191
default = "materialize/ephemeral-storage-setup-image:v0.1.2"
9292
}
93+
94+
variable "swap_enabled" {
95+
description = "Enable swap for Materialize. When enabled, this configures swap on a new nodepool."
96+
type = bool
97+
default = false
98+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ variable "enable_disk_support" {
185185
default = true
186186
}
187187

188+
variable "swap_enabled" {
189+
description = "Enable swap for Materialize. When enabled, this configures swap on a new nodepool, and adds it to the clusterd node selectors."
190+
type = bool
191+
default = false
192+
}
193+
188194
variable "disk_support_config" {
189195
description = "Advanced configuration for disk support (only used when enable_disk_support = true)"
190196
type = object({

0 commit comments

Comments
 (0)