Skip to content

Commit

Permalink
testing node affinities and tolerations
Browse files Browse the repository at this point in the history
  • Loading branch information
givanovexpe committed Sep 23, 2024
1 parent e1d451e commit ee67471
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
32 changes: 32 additions & 0 deletions k8s-readonly.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@ resource "kubernetes_deployment_v1" "apiary_hms_readonly" {
spec {
service_account_name = kubernetes_service_account_v1.hms_readonly[0].metadata.0.name
automount_service_account_token = true

dynamic "tolerations" {
for_each = var.hms_ro_tolerations
content {
effect = lookup(tolerations.value, "effect", null)
key = lookup(tolerations.value, "key", null)
operator = lookup(tolerations.value, "operator", null)
value = lookup(tolerations.value, "value", null)
}
}

dynamic "affinity" {
for_each = var.hms_ro_node_affinity
content {
node_affinity {
required_during_scheduling_ignored_during_execution {
dynamic "node_selector_terms" {
for_each = lookup(affinity.value, "node_selector_terms", [])
content {
match_expressions {
key = lookup(node_selector_terms.value, "key", null)
operator = lookup(node_selector_terms.value, "operator", null)
values = lookup(node_selector_terms.value, "values", [])
}
}
}
}
}
}
}

dynamic "security_context" {
for_each = var.enable_tcp_keepalive ? ["enabled"] : []
content {
Expand All @@ -59,6 +90,7 @@ resource "kubernetes_deployment_v1" "apiary_hms_readonly" {
}
}
}

dynamic "init_container" {
for_each = var.external_database_host == "" ? ["enabled"] : []

Expand Down
32 changes: 32 additions & 0 deletions k8s-readwrite.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@ resource "kubernetes_deployment_v1" "apiary_hms_readwrite" {
spec {
service_account_name = kubernetes_service_account_v1.hms_readwrite[0].metadata.0.name
automount_service_account_token = true

dynamic "tolerations" {
for_each = var.hms_rw_tolerations
content {
effect = lookup(tolerations.value, "effect", null)
key = lookup(tolerations.value, "key", null)
operator = lookup(tolerations.value, "operator", null)
value = lookup(tolerations.value, "value", null)
}
}

dynamic "affinity" {
for_each = var.hms_rw_node_affinity
content {
node_affinity {
required_during_scheduling_ignored_during_execution {
dynamic "node_selector_terms" {
for_each = lookup(affinity.value, "node_selector_terms", [])
content {
match_expressions {
key = lookup(node_selector_terms.value, "key", null)
operator = lookup(node_selector_terms.value, "operator", null)
values = lookup(node_selector_terms.value, "values", [])
}
}
}
}
}
}
}

dynamic "security_context" {
for_each = var.enable_tcp_keepalive ? ["enabled"] : []
content {
Expand All @@ -59,6 +90,7 @@ resource "kubernetes_deployment_v1" "apiary_hms_readwrite" {
}
}
}

dynamic "init_container" {
for_each = var.external_database_host == "" ? ["enabled"] : []
content {
Expand Down
42 changes: 42 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,48 @@ variable "hms_ro_k8s_max_replica_count" {
default = 10
}

variable "hms_rw_node_affinity" {
type = list(object({
node_selector_terms = list(object({
key = string
operator = string
values = list(string)
}))
}))
default = [] # Default to an empty list
}

variable "hms_rw_tolerations" {
type = list(object({
effect = string
key = string
operator = string
value = string
}))
default = []
}

variable "hms_ro_node_affinity" {
type = list(object({
node_selector_terms = list(object({
key = string
operator = string
values = list(string)
}))
}))
default = []
}

variable "hms_ro_tolerations" {
type = list(object({
effect = string
key = string
operator = string
value = string
}))
default = []
}

variable "enable_autoscaling" {
description = "Enable read only Hive Metastore k8s horizontal pod autoscaling"
type = bool
Expand Down

0 comments on commit ee67471

Please sign in to comment.