Skip to content

Commit 38d1c2a

Browse files
committed
Give the AKS Kubernetes resources a real dependency on the namespace
The cluster role binding, ECR pull secret, DaemonSet and load-generator Job all named the namespace with the local string, which gives terraform no dependency edge. All four were therefore launched in the same parallel batch as kubernetes_namespace.cwagent instead of after it, and whichever lost the race against the namespace create failed with "namespaces not found". Run 30580467483 lost it on the secret: the namespace took 437ms to create while the secret started 3ms behind it. The preceding run took 150ms for the same call and the secret landed just after the namespace existed, which is why this had passed until now. The service account was already immune because it referenced the namespace resource rather than the string. All four now reference kubernetes_namespace.cwagent.metadata[0].name, matching the service account, so terraform orders them after the namespace.
1 parent 0ad57db commit 38d1c2a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

terraform/azure/aks/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ resource "kubernetes_cluster_role_binding" "cwagent" {
163163
subject {
164164
kind = "ServiceAccount"
165165
name = kubernetes_service_account.cwagent.metadata[0].name
166-
namespace = local.namespace
166+
namespace = kubernetes_namespace.cwagent.metadata[0].name
167167
}
168168
}
169169

@@ -183,7 +183,7 @@ data "aws_ecr_authorization_token" "ecr" {
183183
resource "kubernetes_secret" "ecr_pull" {
184184
metadata {
185185
name = "ecr-pull-secret"
186-
namespace = local.namespace
186+
namespace = kubernetes_namespace.cwagent.metadata[0].name
187187
}
188188
type = "kubernetes.io/dockerconfigjson"
189189
data = {
@@ -200,7 +200,7 @@ resource "kubernetes_secret" "ecr_pull" {
200200
resource "kubernetes_daemon_set_v1" "cwagent" {
201201
metadata {
202202
name = "cloudwatch-agent"
203-
namespace = local.namespace
203+
namespace = kubernetes_namespace.cwagent.metadata[0].name
204204
}
205205

206206
spec {
@@ -321,7 +321,7 @@ resource "kubernetes_daemon_set_v1" "cwagent" {
321321
resource "kubernetes_job_v1" "otlp_load" {
322322
metadata {
323323
name = "otlp-load-generator"
324-
namespace = local.namespace
324+
namespace = kubernetes_namespace.cwagent.metadata[0].name
325325
}
326326

327327
spec {

0 commit comments

Comments
 (0)