From 3283b2b15ef7f4b6d210dd02a34485edf07a25f6 Mon Sep 17 00:00:00 2001 From: Stephan Feurer Date: Fri, 9 Aug 2024 10:11:40 +0200 Subject: [PATCH] Support multiple instances --- class/defaults.yml | 6 +++++- class/fluentbit.yml | 13 ++++++------- component/app.jsonnet | 4 ++-- component/main.jsonnet | 2 +- .../ROOT/pages/references/parameters.adoc | 16 ++++++++++++++++ .../fluentbit/{ => fluentbit}/00_namespace.yaml | 0 .../fluent-bit/templates/clusterrole.yaml | 0 .../fluent-bit/templates/clusterrolebinding.yaml | 0 .../fluent-bit/templates/daemonset.yaml | 2 +- .../fluent-bit/templates/service.yaml | 0 .../fluent-bit/templates/serviceaccount.yaml | 0 .../{ => fluentbit}/10_custom_config.yaml | 4 ++-- 12 files changed, 33 insertions(+), 14 deletions(-) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/00_namespace.yaml (100%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/clusterrole.yaml (100%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml (100%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml (98%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/service.yaml (100%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml (100%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/10_custom_config.yaml (94%) diff --git a/class/defaults.yml b/class/defaults.yml index f0d26d2..93593da 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -1,6 +1,10 @@ parameters: fluentbit: + =_metadata: + multi_instance: true + namespace: syn-fluentbit + createNamespace: true charts: fluent-bit: @@ -16,7 +20,7 @@ parameters: annotations: fluentbit.io/exclude: "true" - configMapName: syn-fluentbit-config + configMapName: fluentbit-${_instance} config: # fluent-bit service config service: diff --git a/class/fluentbit.yml b/class/fluentbit.yml index f8f461c..6f34ebb 100644 --- a/class/fluentbit.yml +++ b/class/fluentbit.yml @@ -2,7 +2,7 @@ parameters: kapitan: dependencies: - type: helm - output_path: dependencies/fluentbit/helmcharts/fluent-bit-${fluentbit:charts:fluent-bit:version} + output_path: dependencies/${_instance}/helmcharts/fluent-bit-${fluentbit:charts:fluent-bit:version} source: ${fluentbit:charts:fluent-bit:source} version: ${fluentbit:charts:fluent-bit:version} chart_name: fluent-bit @@ -14,12 +14,11 @@ parameters: - input_paths: - fluentbit/component/main.jsonnet input_type: jsonnet - output_path: fluentbit/ - - output_path: fluentbit/01_fluentbit_helmchart + output_path: fluentbit/${_instance}/ + - input_paths: + - dependencies/${_instance}/helmcharts/fluent-bit-${fluentbit:charts:fluent-bit:version} input_type: helm - output_type: yaml - input_paths: - - fluentbit/helmcharts/fluent-bit-${fluentbit:charts:fluent-bit:version} + output_path: fluentbit/${_instance}/01_fluentbit_helmchart helm_values: ${fluentbit:helm_values} helm_params: namespace: ${fluentbit:namespace} @@ -28,5 +27,5 @@ parameters: postprocess: filters: - type: jsonnet - path: fluentbit/01_fluentbit_helmchart/fluent-bit/templates + path: fluentbit/${_instance}/01_fluentbit_helmchart/fluent-bit/templates filter: postprocess/patch_helm_output.jsonnet diff --git a/component/app.jsonnet b/component/app.jsonnet index 7dd2511..dee21da 100644 --- a/component/app.jsonnet +++ b/component/app.jsonnet @@ -3,8 +3,8 @@ local inv = kap.inventory(); local params = inv.parameters.fluentbit; local argocd = import 'lib/argocd.libjsonnet'; -local app = argocd.App('fluentbit', params.namespace); +local app = argocd.App(inv.parameters._instance, params.namespace); { - fluentbit: app, + [inv.parameters._instance]: app, } diff --git a/component/main.jsonnet b/component/main.jsonnet index 5eaf94a..6d2cc47 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -162,7 +162,7 @@ local configmap = kube.ConfigMap(params.configMapName) { }; { - '00_namespace': kube.Namespace(params.namespace), + [if params.createNamespace then '00_namespace']: kube.Namespace(params.namespace), '10_custom_config': configmap, [if params.monitoring.enabled then '20_service_monitor']: kube._Object('monitoring.coreos.com/v1', 'ServiceMonitor', 'fluent-bit') { diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index 04b0bd4..8e6dfe2 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -10,6 +10,22 @@ default:: `syn-fluentbit` The namespace in which to deploy this component. +== `createNamespace` + +[horizontal] +type:: bool +default:: true + +Wether to create the configured namespace or not. + +== `configMapName` + +[horizontal] +type:: string +default:: `fluentbit-${_instance}` + +The name of the generated ConfigMap. + == `config` [horizontal] diff --git a/tests/golden/defaults/fluentbit/fluentbit/00_namespace.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/00_namespace.yaml similarity index 100% rename from tests/golden/defaults/fluentbit/fluentbit/00_namespace.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/00_namespace.yaml diff --git a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrole.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrole.yaml similarity index 100% rename from tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrole.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrole.yaml diff --git a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml similarity index 100% rename from tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml diff --git a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml similarity index 98% rename from tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml index b851e80..0da4f16 100644 --- a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml +++ b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml @@ -61,7 +61,7 @@ spec: serviceAccountName: fluent-bit volumes: - configMap: - name: syn-fluentbit-config + name: fluentbit-fluentbit name: config - hostPath: path: /var/log diff --git a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/service.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/service.yaml similarity index 100% rename from tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/service.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/service.yaml diff --git a/tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml similarity index 100% rename from tests/golden/defaults/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml diff --git a/tests/golden/defaults/fluentbit/fluentbit/10_custom_config.yaml b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/10_custom_config.yaml similarity index 94% rename from tests/golden/defaults/fluentbit/fluentbit/10_custom_config.yaml rename to tests/golden/defaults/fluentbit/fluentbit/fluentbit/10_custom_config.yaml index 31012b1..f25308a 100644 --- a/tests/golden/defaults/fluentbit/fluentbit/10_custom_config.yaml +++ b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/10_custom_config.yaml @@ -39,6 +39,6 @@ metadata: app.kubernetes.io/managed-by: commodore app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 - name: syn-fluentbit-config - name: syn-fluentbit-config + name: fluentbit-fluentbit + name: fluentbit-fluentbit namespace: syn-fluentbit