diff --git a/k8s-readonly.tf b/k8s-readonly.tf index da0a238..3ee7dfc 100644 --- a/k8s-readonly.tf +++ b/k8s-readonly.tf @@ -348,3 +348,33 @@ data "aws_lb" "k8s_hms_ro_lb" { count = var.hms_instance_type == "k8s" && var.enable_vpc_endpoint_services ? 1 : 0 name = split("-", split(".", kubernetes_service.hms_readonly[0].status.0.load_balancer.0.ingress.0.hostname).0).0 } + +resource "kubernetes_pod_disruption_budget" "hms_readonly" { + count = var.hms_instance_type == "k8s" && var.hms_ro_k8s_pdb_settings.enabled ? 1 : 0 + + metadata { + name = "${local.hms_alias}-readonly" + } + + spec { + selector { + match_labels = { + name = "${local.hms_alias}-readonly" + } + } + + dynamic "max_unavailable" { + for_each = var.hms_ro_k8s_pdb_settings.max_unavailable != null ? [var.hms_ro_k8s_pdb_settings.max_unavailable] : ["1"] + content { + max_unavailable = var.hms_ro_k8s_pdb_settings.max_unavailable != null ? var.hms_ro_k8s_pdb_settings.max_unavailable : "1" + } + } + + dynamic "min_available" { + for_each = var.hms_ro_k8s_pdb_settings.min_available != null ? [var.hms_ro_k8s_pdb_settings.min_available] : [] + content { + min_available = var.hms_ro_k8s_pdb_settings.min_available + } + } + } +} \ No newline at end of file diff --git a/k8s-readwrite.tf b/k8s-readwrite.tf index aee28f6..8e4a27e 100644 --- a/k8s-readwrite.tf +++ b/k8s-readwrite.tf @@ -366,3 +366,33 @@ data "aws_lb" "k8s_hms_rw_lb" { count = var.hms_instance_type == "k8s" && var.enable_vpc_endpoint_services ? 1 : 0 name = split("-", split(".", kubernetes_service.hms_readwrite[0].status.0.load_balancer.0.ingress.0.hostname).0).0 } + +resource "kubernetes_pod_disruption_budget" "hms_readwrite" { + count = var.hms_instance_type == "k8s" && var.hms_rw_k8s_pdb_settings.enabled ? 1 : 0 + + metadata { + name = "${local.hms_alias}-readwrite" + } + + spec { + selector { + match_labels = { + name = "${local.hms_alias}-readwrite" + } + } + + dynamic "max_unavailable" { + for_each = var.hms_rw_k8s_pdb_settings.max_unavailable != null ? [var.hms_rw_k8s_pdb_settings.max_unavailable] : ["1"] + content { + max_unavailable = var.hms_rw_k8s_pdb_settings.max_unavailable + } + } + + dynamic "min_available" { + for_each = var.hms_rw_k8s_pdb_settings.min_available != null ? [var.hms_rw_k8s_pdb_settings.min_available] : [] + content { + min_available = var.hms_rw_k8s_pdb_settings.min_available + } + } + } +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 20c3fe9..1b2f57d 100644 --- a/variables.tf +++ b/variables.tf @@ -394,6 +394,30 @@ variable "hms_ro_k8s_max_replica_count" { default = 10 } +variable "hms_ro_k8s_pdb_settings" { + description = "PDB settings for HMS RO including enable flag, maxUnavailable, and minAvailable." + type = object({ + enabled = bool + max_unavailable = optional(string) + min_available = optional(string) + }) + default = { + enabled = false + } +} + +variable "hms_rw_k8s_pdb_settings" { + description = "PDB settings for HMS RW including enable flag, maxUnavailable, and minAvailable." + type = object({ + enabled = bool + max_unavailable = optional(string) + min_available = optional(string) + }) + default = { + enabled = false + } +} + variable "hms_rw_node_affinity" { description = <