Skip to content

Commit

Permalink
Move coredns to separate namespace
Browse files Browse the repository at this point in the history
Terraform code generation with Nix too.
  • Loading branch information
Lillecarl committed Jan 24, 2025
1 parent 1eb15d2 commit bf6483b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
19 changes: 19 additions & 0 deletions cloud/coredns/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ config, ... }:
{
imports = [
../nix
];

config = {
state = "coredns";
remoteStates = [ ];
locals.chartParentPath = toString (
config.kv.downloadHelmChart {
repo = "https://coredns.github.io/helm";
chart = "coredns";
version = "1.37.0";
chartHash = "sha256-V1492bMu4TzGxk02R39nlZjpZyVei198CI6ZDzk72t0=";
}
);
};
}
19 changes: 8 additions & 11 deletions cloud/coredns/main.tf
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
variable "paths" { type = map(string) }
variable "deploy" { type = bool }
locals {
ids-this-stage0 = data.kustomization_overlay.this.ids_prio[0]
ids-this-stage1 = var.deploy ? data.kustomization_overlay.this.ids_prio[1] : []
ids-this-stage2 = var.deploy ? data.kustomization_overlay.this.ids_prio[2] : []
helm_values = {
replicaCount = 2
service = { clusterIP = "10.43.0.10" }
deployment = { skipConfig = true }
}
namespace = "coredns"
}
data "kustomization_overlay" "this" {
resources = [for file in tolist(fileset(path.module, "*.yaml")) : "${path.module}/${file}"]
namespace = local.namespace
helm_charts {
name = "coredns"
release_name = "coredns"
namespace = "kube-system"
namespace = local.namespace
include_crds = true
values_inline = yamlencode(local.helm_values)
}
helm_globals {
chart_home = var.paths.charts
chart_home = local.chartParentPath
}
kustomize_options {
load_restrictor = "none"
enable_helm = true
helm_path = var.paths.helm-path
helm_path = local.helmBinPath
}
}
resource "kubectl_manifest" "stage0" {
for_each = local.ids-this-stage0
for_each = data.kustomization_overlay.this.ids_prio[0]
yaml_body = data.kustomization_overlay.this.manifests[each.value]
depends_on = []

Expand All @@ -40,7 +37,7 @@ resource "kubectl_manifest" "stage0" {
timeouts { create = "1m" }
}
resource "kubectl_manifest" "stage1" {
for_each = local.ids-this-stage1
for_each = data.kustomization_overlay.this.ids_prio[1]
yaml_body = data.kustomization_overlay.this.manifests[each.value]
depends_on = [kubectl_manifest.stage0]

Expand All @@ -50,7 +47,7 @@ resource "kubectl_manifest" "stage1" {
timeouts { create = "1m" }
}
resource "kubectl_manifest" "stage2" {
for_each = local.ids-this-stage2
for_each = data.kustomization_overlay.this.ids_prio[2]
yaml_body = data.kustomization_overlay.this.manifests[each.value]
depends_on = [kubectl_manifest.stage1]

Expand Down
4 changes: 4 additions & 0 deletions cloud/coredns/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: coredns
16 changes: 0 additions & 16 deletions cloud/coredns/terragrunt.hcl

This file was deleted.

0 comments on commit bf6483b

Please sign in to comment.