Skip to content

Commit a41eeb5

Browse files
committed
chore: Updated k8s devcontainer template to auto-populate git credentials
1 parent 49da404 commit a41eeb5

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • templates/kubernetes-devcontainer

templates/kubernetes-devcontainer/main.tf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ variable "use_kubeconfig" {
4040

4141
variable "namespace" {
4242
type = string
43-
default = "default"
43+
default = "coder"
4444
description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces). If the Coder host is itself running as a Pod on the same Kubernetes cluster as you are deploying workspaces to, set this to the same namespace."
4545
}
4646

@@ -143,10 +143,14 @@ data "kubernetes_secret_v1" "cache_repo_dockerconfig_secret" {
143143
count = var.cache_repo_secret_name == "" ? 0 : 1
144144
metadata {
145145
name = var.cache_repo_secret_name
146-
namespace = var.namespace
146+
namespace = "coder"
147147
}
148148
}
149149

150+
data "coder_external_auth" "github" {
151+
id = "primary-github"
152+
}
153+
150154
locals {
151155
deployment_name = "coder-${lower(data.coder_workspace.me.id)}"
152156
devcontainer_builder_image = data.coder_parameter.devcontainer_builder.value
@@ -170,6 +174,7 @@ locals {
170174
# For example, when testing in KinD, it was necessary to set `/product_name` and `/product_uuid` in
171175
# addition to `/var/run`.
172176
# "ENVBUILDER_IGNORE_PATHS": "/product_name,/product_uuid,/var/run",
177+
"ENVBUILDER_GIT_TOKEN" : data.coder_external_auth.github.access_token
173178
}
174179
}
175180

@@ -187,7 +192,7 @@ resource "envbuilder_cached_image" "cached" {
187192
resource "kubernetes_persistent_volume_claim_v1" "workspaces" {
188193
metadata {
189194
name = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
190-
namespace = var.namespace
195+
namespace = "coder"
191196
labels = {
192197
"app.kubernetes.io/name" = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
193198
"app.kubernetes.io/instance" = "coder-${lower(data.coder_workspace.me.id)}-workspaces"
@@ -223,7 +228,7 @@ resource "kubernetes_deployment_v1" "main" {
223228
wait_for_rollout = false
224229
metadata {
225230
name = local.deployment_name
226-
namespace = var.namespace
231+
namespace = "coder"
227232
labels = {
228233
"app.kubernetes.io/name" = "coder-workspace"
229234
"app.kubernetes.io/instance" = local.deployment_name
@@ -333,6 +338,10 @@ resource "coder_agent" "main" {
333338
set -e
334339
335340
# Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here
341+
git config --global user.name ${local.git_author_name}
342+
git config --global user.email ${local.git_author_email}
343+
344+
coder git_auth setup primary-github
336345
EOT
337346
dir = "/workspaces"
338347

@@ -423,6 +432,7 @@ module "code-server" {
423432
version = "~> 1.0"
424433

425434
agent_id = coder_agent.main.id
435+
426436
order = 1
427437
}
428438

0 commit comments

Comments
 (0)