Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16364db

Browse files
authored
add: resource reqs/limits on K8s template (#6308)
1 parent 7c46f76 commit 16364db

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

examples/templates/kubernetes-with-podman/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ variable "os" {
2626
default = "ubuntu"
2727
}
2828

29+
variable "cpu" {
30+
description = "CPU (__ cores)"
31+
default = 2
32+
validation {
33+
condition = contains([
34+
"2",
35+
"4",
36+
"6",
37+
"8"
38+
], var.cpu)
39+
error_message = "Invalid cpu!"
40+
}
41+
}
42+
43+
variable "memory" {
44+
description = "Memory (__ GB)"
45+
default = 2
46+
validation {
47+
condition = contains([
48+
"2",
49+
"4",
50+
"6",
51+
"8"
52+
], var.memory)
53+
error_message = "Invalid memory!"
54+
}
55+
}
56+
2957
resource "coder_agent" "dev" {
3058
os = "linux"
3159
arch = "amd64"
@@ -80,10 +108,17 @@ resource "kubernetes_pod" "main" {
80108
run_as_user = "1000"
81109
}
82110
resources {
111+
requests = {
112+
"cpu" = "250m"
113+
"memory" = "500Mi"
114+
}
83115
limits = {
84116
# Acquire a FUSE device, powered by smarter-device-manager
85117
"github.com/fuse" : 1
118+
cpu = "${var.cpu}"
119+
memory = "${var.memory}Gi"
86120
}
121+
87122
}
88123
env {
89124
name = "CODER_AGENT_TOKEN"

examples/templates/kubernetes/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ variable "namespace" {
3131
description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces)"
3232
}
3333

34+
variable "cpu" {
35+
description = "CPU (__ cores)"
36+
default = 2
37+
validation {
38+
condition = contains([
39+
"2",
40+
"4",
41+
"6",
42+
"8"
43+
], var.cpu)
44+
error_message = "Invalid cpu!"
45+
}
46+
}
47+
48+
variable "memory" {
49+
description = "Memory (__ GB)"
50+
default = 2
51+
validation {
52+
condition = contains([
53+
"2",
54+
"4",
55+
"6",
56+
"8"
57+
], var.memory)
58+
error_message = "Invalid memory!"
59+
}
60+
}
61+
3462
variable "home_disk_size" {
3563
type = number
3664
description = "How large would you like your home volume to be (in GB)?"
@@ -147,6 +175,16 @@ resource "kubernetes_pod" "main" {
147175
name = "CODER_AGENT_TOKEN"
148176
value = coder_agent.main.token
149177
}
178+
resources {
179+
requests = {
180+
"cpu" = "250m"
181+
"memory" = "512Mi"
182+
}
183+
limits = {
184+
"cpu" = "${var.cpu}"
185+
"memory" = "${var.memory}Gi"
186+
}
187+
}
150188
volume_mount {
151189
mount_path = "/home/coder"
152190
name = "home"

0 commit comments

Comments
 (0)