From 23719674e48e56841d819597d37ae6977b2c170e 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 | 7 ++++++- 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 | 2 +- .../fluent-bit/templates/clusterrolebinding.yaml | 6 +++--- .../fluent-bit/templates/daemonset.yaml | 6 +++--- .../fluent-bit/templates/service.yaml | 2 +- .../fluent-bit/templates/serviceaccount.yaml | 2 +- .../{ => fluentbit}/10_custom_config.yaml | 4 ++-- 12 files changed, 42 insertions(+), 22 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 (95%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/clusterrolebinding.yaml (87%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/daemonset.yaml (95%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/service.yaml (96%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/01_fluentbit_helmchart/fluent-bit/templates/serviceaccount.yaml (93%) rename tests/golden/defaults/fluentbit/fluentbit/{ => fluentbit}/10_custom_config.yaml (94%) diff --git a/class/defaults.yml b/class/defaults.yml index f0d26d2..dc3e501 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: ${_instance} config: # fluent-bit service config service: @@ -78,6 +82,7 @@ parameters: tolerations: [] helm_values: + fullnameOverride: ${_instance} podAnnotations: ${fluentbit:annotations} image: repository: ${fluentbit:images:fluent_bit:image} diff --git a/class/fluentbit.yml b/class/fluentbit.yml index f8f461c..dfddc62 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: ${_base_directory}/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: + - ${_base_directory}/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..78c96ef 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:: `${_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 95% 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 index afec30d..55f39db 100644 --- 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 @@ -7,7 +7,7 @@ metadata: app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 helm.sh/chart: fluent-bit-0.47.5 - name: fluent-bit + name: fluentbit rules: - apiGroups: - '' 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 87% 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 index 09d2315..dadf1a8 100644 --- 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 @@ -7,12 +7,12 @@ metadata: app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 helm.sh/chart: fluent-bit-0.47.5 - name: fluent-bit + name: fluentbit roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: fluent-bit + name: fluentbit subjects: - kind: ServiceAccount - name: fluent-bit + name: fluentbit namespace: syn-fluentbit 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 95% 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..cb0f1bb 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 @@ -7,7 +7,7 @@ metadata: app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 helm.sh/chart: fluent-bit-0.47.5 - name: fluent-bit + name: fluentbit namespace: syn-fluentbit spec: selector: @@ -58,10 +58,10 @@ spec: readOnly: true dnsPolicy: ClusterFirst hostNetwork: false - serviceAccountName: fluent-bit + serviceAccountName: fluentbit volumes: - configMap: - name: syn-fluentbit-config + name: 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 96% 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 index fb8c25e..9181077 100644 --- 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 @@ -7,7 +7,7 @@ metadata: app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 helm.sh/chart: fluent-bit-0.47.5 - name: fluent-bit + name: fluentbit namespace: syn-fluentbit spec: ports: 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 93% 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 index d9b88c0..bc2caf7 100644 --- 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 @@ -7,5 +7,5 @@ metadata: app.kubernetes.io/name: fluent-bit app.kubernetes.io/version: 3.1.4 helm.sh/chart: fluent-bit-0.47.5 - name: fluent-bit + name: fluentbit namespace: syn-fluentbit 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..f916492 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 + name: fluentbit namespace: syn-fluentbit