add: resource reqs/limits on K8s template (#6308)

This commit is contained in:
Eric Paulsen 2023-02-26 17:23:45 -07:00 committed by GitHub
parent 7c46f76c82
commit 16364db483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -26,6 +26,34 @@ variable "os" {
default = "ubuntu"
}
variable "cpu" {
description = "CPU (__ cores)"
default = 2
validation {
condition = contains([
"2",
"4",
"6",
"8"
], var.cpu)
error_message = "Invalid cpu!"
}
}
variable "memory" {
description = "Memory (__ GB)"
default = 2
validation {
condition = contains([
"2",
"4",
"6",
"8"
], var.memory)
error_message = "Invalid memory!"
}
}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
@ -80,10 +108,17 @@ resource "kubernetes_pod" "main" {
run_as_user = "1000"
}
resources {
requests = {
"cpu" = "250m"
"memory" = "500Mi"
}
limits = {
# Acquire a FUSE device, powered by smarter-device-manager
"github.com/fuse" : 1
cpu = "${var.cpu}"
memory = "${var.memory}Gi"
}
}
env {
name = "CODER_AGENT_TOKEN"

View File

@ -31,6 +31,34 @@ variable "namespace" {
description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces)"
}
variable "cpu" {
description = "CPU (__ cores)"
default = 2
validation {
condition = contains([
"2",
"4",
"6",
"8"
], var.cpu)
error_message = "Invalid cpu!"
}
}
variable "memory" {
description = "Memory (__ GB)"
default = 2
validation {
condition = contains([
"2",
"4",
"6",
"8"
], var.memory)
error_message = "Invalid memory!"
}
}
variable "home_disk_size" {
type = number
description = "How large would you like your home volume to be (in GB)?"
@ -147,6 +175,16 @@ resource "kubernetes_pod" "main" {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}
resources {
requests = {
"cpu" = "250m"
"memory" = "512Mi"
}
limits = {
"cpu" = "${var.cpu}"
"memory" = "${var.memory}Gi"
}
}
volume_mount {
mount_path = "/home/coder"
name = "home"