Skip to content

Commit faf2f9a

Browse files
bobdoahRobert Williams
and
Robert Williams
authored
Ensure serviceaccount created in correct namespace (#398)
* Ensure serviceaccount created in correct namespace The serviceaccount for a module is created via the IRSA module. If the namespace of a module differs from the default, it needs to also be passed to the IRSA module. Otherwise any deployments tied to the serviceaccount will fail to deploy pods. * Create a non-default namespace Create the namespace, if it is not the default "kube-system" which (typically) exists on every cluster. To allow the namespace to be created external to this module, allow the IRSA config to be overridden. This should fit both my and @vara-bonthu's proposed use cases. * Apply reccommended changes * Apply the fix to cert-manager Co-authored-by: Robert Williams <[email protected]>
1 parent 6d50f39 commit faf2f9a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

modules/irsa/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "kubernetes_namespace_v1" "irsa" {
2-
count = var.create_kubernetes_namespace ? 1 : 0
2+
count = var.create_kubernetes_namespace && var.kubernetes_namespace != "kube-system" ? 1 : 0
33
metadata {
44
name = var.kubernetes_namespace
55

modules/kubernetes-addons/aws-load-balancer-controller/locals.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ locals {
4141
}
4242

4343
irsa_config = {
44-
kubernetes_namespace = "kube-system"
44+
kubernetes_namespace = local.helm_config["namespace"]
4545
kubernetes_service_account = local.service_account_name
46-
create_kubernetes_namespace = false
46+
create_kubernetes_namespace = try(local.helm_config["create_namespace"], true)
4747
create_kubernetes_service_account = true
4848
irsa_iam_policies = [aws_iam_policy.aws_load_balancer_controller.arn]
4949
}

modules/kubernetes-addons/cert-manager/locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ locals {
3333
irsa_config = {
3434
kubernetes_namespace = local.helm_config["namespace"]
3535
kubernetes_service_account = local.service_account_name
36-
create_kubernetes_namespace = true
36+
create_kubernetes_namespace = try(local.helm_config["create_namespace"], true)
3737
create_kubernetes_service_account = true
3838
}
3939

0 commit comments

Comments
 (0)