From 441f9a5b739a84093f7b6540f988f9b6c416ae98 Mon Sep 17 00:00:00 2001 From: DynamicD Date: Wed, 6 Sep 2023 21:04:04 -0700 Subject: [PATCH] add label controls --- aks.tf | 6 +++--- main.tf | 25 ++++++++++++++++++------- variables.tf | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/aks.tf b/aks.tf index 99c73b8..c2b8439 100644 --- a/aks.tf +++ b/aks.tf @@ -70,8 +70,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "user" { mode = local.node_user_pool.mode name = local.node_user_pool.name node_count = local.node_user_pool.node_count - node_labels = local.node_user_pool_defaults[local.node_user_pool.priority].labels - node_taints = local.node_user_pool_defaults[local.node_user_pool.priority].taints + node_labels = local.node_user_pool_merged.node_labels + node_taints = local.node_user_pool_merged.node_taints os_disk_size_gb = local.node_user_pool.os_disk_size_gb os_disk_type = local.node_user_pool.os_disk_type priority = local.node_user_pool.priority @@ -81,4 +81,4 @@ resource "azurerm_kubernetes_cluster_node_pool" "user" { vm_size = local.node_user_pool.vm_size vnet_subnet_id = local.subnet_id # must be defined or terraform will redeploy despite documentation stating optional zones = local.zones != [] ? local.zones : null -} \ No newline at end of file +} diff --git a/main.tf b/main.tf index 4a37b95..67bb75e 100644 --- a/main.tf +++ b/main.tf @@ -20,22 +20,32 @@ locals { # details: https://docs.microsoft.com/en-us/azure/aks/spot-node-pool node_user_pool_defaults = { Regular = { - labels = {} - taints = [] + node_labels = {} + node_taints = [] } Spot = { - labels = { + node_labels = { "kubernetes.azure.com/scalesetpriority" = "spot" } - taints = [ + node_taints = [ "kubernetes.azure.com/scalesetpriority=spot:NoSchedule" ] } } - # merges the node_pool_defaults into the node_user_pool per priority - # type (see above) Allows user to override values. - node_user_pool = var.node_user_pool + # merges the node_user_pool_defaults with the node_user_pool via + # priority type (see above). Allows user to add values. + # node_user_pool = var.node_user_pool + node_user_pool_merged = { + node_labels = merge( + var.node_user_pool.node_labels, + local.node_user_pool_defaults[var.node_user_pool.priority].node_labels + ) + node_taints = concat( + var.node_user_pool.node_taints, + local.node_user_pool_defaults[var.node_user_pool.priority].node_taints + ) + } # these are unmodified, just dropped into locals for consistency acr_list = var.acr_list @@ -45,6 +55,7 @@ locals { docker_bridge_cidr = var.docker_bridge_cidr location = var.location node_default_pool = var.node_default_pool + node_user_pool = var.node_user_pool oms = var.oms resource_group_name = var.resource_group_name sku_tier = var.sku_tier diff --git a/variables.tf b/variables.tf index 39bbb1d..283a82d 100644 --- a/variables.tf +++ b/variables.tf @@ -59,6 +59,8 @@ variable "node_user_pool" { mode = optional(string, "User") name = optional(string, "user") node_count = optional(number, 2) + node_labels = optional(map(any), {}) # needs defaults as we merge it later + node_taints = optional(list(string), []) # needs defaults as we concat it later os_disk_size_gb = optional(number, 120) os_disk_type = optional(string, "Ephemeral") priority = optional(string, "Regular")