From aed01a77f6e646f3830a82133806755235f0471d Mon Sep 17 00:00:00 2001 From: "Audun V. Nes" Date: Fri, 8 Nov 2024 14:50:33 +0100 Subject: [PATCH] Prepare Flux for multi-tenancy support (#1608) * Add missing dependency between Grafana helm chart and the resources it uses from the kube-prometheus-stack * Prepare for multi-tenancy support * Add support for Flux multi-tenancy * Remove unused variables. Add support for Trivy in pre-commit. * Prepare druid-operator for Flux multi-tenancy * Prepare Trivy Operator for Flux multi-tenancy --- .pre-commit-config.yaml | 70 ++++++++++--------- _sub/compute/atlantis/flux.tf | 2 + _sub/compute/atlantis/values/app-config.yaml | 15 ++++ _sub/compute/atlantis/values/patch.yaml | 1 + _sub/compute/druid-operator/main.tf | 2 + .../druid-operator/values/app-config.yaml | 15 ++++ _sub/compute/druid-operator/values/patch.yaml | 1 + .../github-arc-runners/dependencies.tf | 17 ++++- _sub/compute/github-arc-runners/vars.tf | 32 ++++----- .../github-arc-ss-controller/dependencies.tf | 19 ++++- .../dependencies.tf | 3 +- _sub/compute/k8s-fluxcd/dependencies.tf | 4 +- _sub/compute/k8s-fluxcd/main.tf | 7 +- .../k8s-fluxcd/values/flux-system-patch.yaml | 30 ++++++++ .../values/shared-manifests.yaml | 15 ++++ _sub/compute/k8s-traefik-flux/main.tf | 2 + .../k8s-traefik-flux/values/app-config.yaml | 1 + .../k8s-traefik-flux/values/app-helm.yaml | 36 +++++++--- .../k8s-traefik-flux/values/helm-patch.yaml | 5 +- _sub/compute/nvidia-device-plugin/main.tf | 12 ++-- .../values/app-config.yaml | 15 ++++ .../nvidia-device-plugin/values/patch.yaml | 1 + _sub/compute/trivy-operator/main.tf | 2 + .../trivy-operator/values/app-config.yaml | 15 ++++ _sub/compute/trivy-operator/values/patch.yaml | 1 + _sub/monitoring/blackbox-exporter/main.tf | 2 + .../blackbox-exporter/values/app-config.yaml | 15 ++++ .../blackbox-exporter/values/patch.yaml | 1 + _sub/monitoring/goldpinger/main.tf | 2 + .../goldpinger/values/app-config.yaml | 15 ++++ _sub/monitoring/goldpinger/values/patch.yaml | 1 + _sub/monitoring/helm-exporter/main.tf | 2 + .../helm-exporter/values/app-config.yaml | 15 ++++ .../helm-exporter/values/patch.yaml | 1 + .../monitoring/kafka-exporter/dependencies.tf | 20 +++++- _sub/monitoring/kafka-exporter/main.tf | 2 +- _sub/monitoring/kafka-exporter/vars.tf | 14 +--- .../monitoring/metrics-server/dependencies.tf | 46 ++++++++---- .../security/external-secrets/dependencies.tf | 17 ++++- .../external-snapshotter/values/config.yaml | 1 + .../values/controller.yaml | 1 + .../external-snapshotter/values/crd.yaml | 1 + _sub/storage/velero/main.tf | 2 + _sub/storage/velero/values/app-config.yaml | 15 ++++ _sub/storage/velero/values/patch.yaml | 1 + compute/k8s-services/main.tf | 26 +++---- 46 files changed, 402 insertions(+), 121 deletions(-) create mode 100644 _sub/compute/k8s-fluxcd/values/flux-system-patch.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa93e9083..e5829858f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,35 +1,37 @@ repos: -- repo: https://github.com/antonbabenko/pre-commit-terraform - rev: v1.96.2 - hooks: - - id: terraform_fmt - exclude: test/integration/suite/vendor/.* - - id: terraform_tfsec - exclude: test/integration/suite/vendor/.* - files: (\.tf|\.tfvars)$ -- repo: https://github.com/Yelp/detect-secrets - rev: v1.5.0 - hooks: - - id: detect-secrets - exclude: test/integration/suite/vendor/.* -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: trailing-whitespace - exclude: test/integration/suite/vendor/.* - - id: check-added-large-files - exclude: test/integration/suite/vendor/.* - - id: check-merge-conflict - - id: detect-aws-credentials - exclude: test/integration/suite/vendor/.* - args: - - "--allow-missing-credentials" - - id: detect-private-key -- repo: https://github.com/gruntwork-io/pre-commit - rev: v0.1.24 - hooks: - - id: tflint - exclude: test/integration/suite/vendor/.* - args: - - "--module" - - "--config=.tflint.hcl" + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.96.2 + hooks: + - id: terraform_fmt + exclude: test/integration/suite/vendor/.* + - id: terraform_trivy + args: + - "--args=--skip-dirs=test/integration/suite/vendor/.*" + - "--args=--severity HIGH,CRITICAL" + files: (\.tf|\.tfvars)$ + - repo: https://github.com/Yelp/detect-secrets + rev: v1.5.0 + hooks: + - id: detect-secrets + exclude: test/integration/suite/vendor/.* + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + exclude: test/integration/suite/vendor/.* + - id: check-added-large-files + exclude: test/integration/suite/vendor/.* + - id: check-merge-conflict + - id: detect-aws-credentials + exclude: test/integration/suite/vendor/.* + args: + - "--allow-missing-credentials" + - id: detect-private-key + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.24 + hooks: + - id: tflint + exclude: test/integration/suite/vendor/.* + args: + - "--call-module-type=all" + - "--config=__GIT_ROOT__/.tflint.hcl" diff --git a/_sub/compute/atlantis/flux.tf b/_sub/compute/atlantis/flux.tf index cdca50895..5d69c7c09 100644 --- a/_sub/compute/atlantis/flux.tf +++ b/_sub/compute/atlantis/flux.tf @@ -7,6 +7,8 @@ resource "github_repository_file" "helm" { branch = local.repo_branch file = "${local.cluster_repo_path}/${local.app_install_name}-helm.yaml" content = templatefile("${path.module}/values/app-config.yaml", { + deploy_name = local.deploy_name + namespace = local.namespace app_install_name = local.app_install_name helm_repo_path = local.helm_repo_path prune = var.prune diff --git a/_sub/compute/atlantis/values/app-config.yaml b/_sub/compute/atlantis/values/app-config.yaml index 5a2031825..773ed999f 100644 --- a/_sub/compute/atlantis/values/app-config.yaml +++ b/_sub/compute/atlantis/values/app-config.yaml @@ -1,9 +1,24 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cluster-reconciler-${deploy_name} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: + - kind: ServiceAccount + name: helm-controller + namespace: ${namespace} +--- apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: ${app_install_name}-helm namespace: flux-system spec: + serviceAccountName: kustomize-controller interval: 1m0s dependsOn: - name: platform-apps-sources diff --git a/_sub/compute/atlantis/values/patch.yaml b/_sub/compute/atlantis/values/patch.yaml index 1b8715129..ec7dd16b1 100644 --- a/_sub/compute/atlantis/values/patch.yaml +++ b/_sub/compute/atlantis/values/patch.yaml @@ -4,6 +4,7 @@ metadata: name: ${deploy_name} namespace: ${namespace} spec: + serviceAccountName: helm-controller chart: spec: version: "${chart_version}" diff --git a/_sub/compute/druid-operator/main.tf b/_sub/compute/druid-operator/main.tf index d5001ea74..d88b85a5f 100644 --- a/_sub/compute/druid-operator/main.tf +++ b/_sub/compute/druid-operator/main.tf @@ -8,6 +8,8 @@ resource "github_repository_file" "helm" { content = templatefile("${path.module}/values/app-config.yaml", { app_install_name = local.app_install_name helm_repo_path = local.helm_repo_path + deploy_name = var.deploy_name + namespace = var.namespace prune = var.prune }) overwrite_on_create = var.overwrite_on_create diff --git a/_sub/compute/druid-operator/values/app-config.yaml b/_sub/compute/druid-operator/values/app-config.yaml index 40600a93b..4c606f5d3 100644 --- a/_sub/compute/druid-operator/values/app-config.yaml +++ b/_sub/compute/druid-operator/values/app-config.yaml @@ -1,9 +1,24 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cluster-reconciler-${deploy_name} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: + - kind: ServiceAccount + name: helm-controller + namespace: ${namespace} +--- apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: ${app_install_name}-helm namespace: flux-system spec: + serviceAccountName: kustomize-controller interval: 1m0s dependsOn: - name: platform-apps-sources diff --git a/_sub/compute/druid-operator/values/patch.yaml b/_sub/compute/druid-operator/values/patch.yaml index 209fabecb..d2caa32e5 100644 --- a/_sub/compute/druid-operator/values/patch.yaml +++ b/_sub/compute/druid-operator/values/patch.yaml @@ -4,6 +4,7 @@ metadata: name: ${deploy_name} namespace: ${namespace} spec: + serviceAccountName: helm-controller chart: spec: version: "${chart_version}" diff --git a/_sub/compute/github-arc-runners/dependencies.tf b/_sub/compute/github-arc-runners/dependencies.tf index 39c09e941..a728c4f61 100644 --- a/_sub/compute/github-arc-runners/dependencies.tf +++ b/_sub/compute/github-arc-runners/dependencies.tf @@ -12,17 +12,31 @@ locals { locals { app_helm_path = <