Skip to content

Commit ee0b888

Browse files
committed
feat: add support for node affinity
Signed-off-by: Ales Verbic <[email protected]>
1 parent c9ed9cd commit ee0b888

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

Diff for: bootstrap/instance/main.tf

+44-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,56 @@ variable "salt" {
1919
type = string
2020
}
2121

22-
variable "node_private_dns" {
22+
variable "network" {
2323
type = string
2424
}
2525

26-
variable "network" {
26+
variable "node_private_dns" {
2727
type = string
2828
}
2929

30+
variable "node_affinity" {
31+
type = object({
32+
required_during_scheduling_ignored_during_execution = optional(
33+
object({
34+
node_selector_term = optional(
35+
list(object({
36+
match_expressions = optional(
37+
list(object({
38+
key = string
39+
operator = string
40+
values = list(string)
41+
})), []
42+
)
43+
})), []
44+
)
45+
}), {}
46+
)
47+
preferred_during_scheduling_ignored_during_execution = optional(
48+
list(object({
49+
weight = number
50+
preference = object({
51+
match_expressions = optional(
52+
list(object({
53+
key = string
54+
operator = string
55+
values = list(string)
56+
})), []
57+
)
58+
match_fields = optional(
59+
list(object({
60+
key = string
61+
operator = string
62+
values = list(string)
63+
})), []
64+
)
65+
})
66+
})), []
67+
)
68+
})
69+
default = {}
70+
}
71+
3072
variable "replicas" {
3173
type = number
3274
default = 1

Diff for: bootstrap/instance/ogmios.tf

+69
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,75 @@ resource "kubernetes_deployment_v1" "ogmios" {
6565
fs_group = 1000
6666
}
6767

68+
dynamic "affinity" {
69+
for_each = (
70+
var.node_affinity != null &&
71+
(
72+
try(length(var.node_affinity.required_during_scheduling_ignored_during_execution.node_selector_term), 0) > 0 ||
73+
try(length(var.node_affinity.preferred_during_scheduling_ignored_during_execution), 0) > 0
74+
)
75+
) ? [var.node_affinity] : []
76+
content {
77+
node_affinity {
78+
dynamic "required_during_scheduling_ignored_during_execution" {
79+
for_each = (
80+
var.node_affinity.required_during_scheduling_ignored_during_execution != null &&
81+
length(var.node_affinity.required_during_scheduling_ignored_during_execution.node_selector_term) > 0
82+
) ? [var.node_affinity.required_during_scheduling_ignored_during_execution] : []
83+
content {
84+
dynamic "node_selector_term" {
85+
for_each = required_during_scheduling_ignored_during_execution.value.node_selector_term
86+
content {
87+
dynamic "match_expressions" {
88+
for_each = length(node_selector_term.value.match_expressions) > 0 ? node_selector_term.value.match_expressions : []
89+
content {
90+
key = match_expressions.value.key
91+
operator = match_expressions.value.operator
92+
values = match_expressions.value.values
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
dynamic "preferred_during_scheduling_ignored_during_execution" {
100+
for_each = (
101+
var.node_affinity.preferred_during_scheduling_ignored_during_execution != null &&
102+
length(var.node_affinity.preferred_during_scheduling_ignored_during_execution) > 0
103+
) ? var.node_affinity.preferred_during_scheduling_ignored_during_execution : []
104+
content {
105+
weight = preferred_during_scheduling_ignored_during_execution.value.weight
106+
107+
dynamic "preference" {
108+
for_each = (
109+
length(preferred_during_scheduling_ignored_during_execution.value.preference.match_expressions) > 0 ||
110+
length(preferred_during_scheduling_ignored_during_execution.value.preference.match_fields) > 0
111+
) ? [preferred_during_scheduling_ignored_during_execution.value.preference] : []
112+
content {
113+
dynamic "match_expressions" {
114+
for_each = length(preference.value.match_expressions) > 0 ? preference.value.match_expressions : []
115+
content {
116+
key = match_expressions.value.key
117+
operator = match_expressions.value.operator
118+
values = match_expressions.value.values
119+
}
120+
}
121+
dynamic "match_fields" {
122+
for_each = length(preference.value.match_fields) > 0 ? preference.value.match_fields : []
123+
content {
124+
key = match_fields.value.key
125+
operator = match_fields.value.operator
126+
values = match_fields.value.values
127+
}
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}
136+
68137
container {
69138
name = "main"
70139
image = local.image

Diff for: bootstrap/main.tf

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ module "ogmios_instances" {
101101
value = "consistent"
102102
}
103103
])
104+
node_affinity = coalesce(each.value.node_affinity, {
105+
required_during_scheduling_ignored_during_execution = {}
106+
preferred_during_scheduling_ignored_during_execution = []
107+
})
104108
}
105109

106110
module "ogmios_services" {

Diff for: bootstrap/variables.tf

+38
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,43 @@ variable "instances" {
189189
operator = string
190190
value = optional(string)
191191
})))
192+
node_affinity = optional(object({
193+
required_during_scheduling_ignored_during_execution = optional(
194+
object({
195+
node_selector_term = optional(
196+
list(object({
197+
match_expressions = optional(
198+
list(object({
199+
key = string
200+
operator = string
201+
values = list(string)
202+
})), []
203+
)
204+
})), []
205+
)
206+
}), {}
207+
)
208+
preferred_during_scheduling_ignored_during_execution = optional(
209+
list(object({
210+
weight = number
211+
preference = object({
212+
match_expressions = optional(
213+
list(object({
214+
key = string
215+
operator = string
216+
values = list(string)
217+
})), []
218+
)
219+
match_fields = optional(
220+
list(object({
221+
key = string
222+
operator = string
223+
values = list(string)
224+
})), []
225+
)
226+
})
227+
})), []
228+
)
229+
}))
192230
}))
193231
}

0 commit comments

Comments
 (0)