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..76fa8bd 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,19 +14,18 @@ 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: + name: ${_instance} namespace: ${fluentbit:namespace} - name_template: fluent-bit commodore: 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..d3f260b 100644 --- a/component/app.jsonnet +++ b/component/app.jsonnet @@ -3,8 +3,14 @@ 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) { + spec+: { + source+: { + path: 'manifests/fluentbit/' + inv.parameters._instance, + }, + }, +}; { - fluentbit: app, + [inv.parameters._instance]: app, } diff --git a/component/main.jsonnet b/component/main.jsonnet index 5eaf94a..cac07a7 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -4,6 +4,7 @@ local kube = import 'lib/kube.libjsonnet'; local inv = kap.inventory(); // The hiera parameters for the component local params = inv.parameters.fluentbit; +local instanceName = inv.parameters._instance; local render_fluentbit_cfg(type, name, cfg) = local header = '[%s]' % std.asciiUpper(type); @@ -148,7 +149,7 @@ local configmap = kube.ConfigMap(params.configMapName) { namespace: params.namespace, labels+: { 'app.kubernetes.io/name': 'fluent-bit', - 'app.kubernetes.io/instance': 'fluent-bit-cluster', + 'app.kubernetes.io/instance': instanceName, 'app.kubernetes.io/version': std.split(params.images.fluent_bit.tag, '@')[0], 'app.kubernetes.io/component': 'fluent-bit', @@ -162,7 +163,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') { @@ -170,7 +171,7 @@ local configmap = kube.ConfigMap(params.configMapName) { namespace: params.namespace, labels+: { 'app.kubernetes.io/name': 'fluent-bit', - 'app.kubernetes.io/instance': 'fluent-bit-cluster', + 'app.kubernetes.io/instance': instanceName, 'app.kubernetes.io/version': std.split(params.images.fluent_bit.tag, '@')[0], 'app.kubernetes.io/component': 'fluent-bit', @@ -185,7 +186,7 @@ local configmap = kube.ConfigMap(params.configMapName) { selector: { matchLabels: { 'app.kubernetes.io/name': 'fluent-bit', - 'app.kubernetes.io/instance': 'fluent-bit', + 'app.kubernetes.io/instance': instanceName, }, }, }, 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/apps/fluentbit.yaml b/tests/golden/defaults/fluentbit/apps/fluentbit.yaml index e69de29..1d84d89 100644 --- a/tests/golden/defaults/fluentbit/apps/fluentbit.yaml +++ b/tests/golden/defaults/fluentbit/apps/fluentbit.yaml @@ -0,0 +1,3 @@ +spec: + source: + path: manifests/fluentbit/fluentbit 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 85% 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..9ffe5ed 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 @@ -2,12 +2,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/managed-by: Helm 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 78% 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..30554ae 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 @@ -2,17 +2,17 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/managed-by: Helm 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 89% 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..419cebb 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 @@ -2,17 +2,17 @@ apiVersion: apps/v1 kind: DaemonSet metadata: labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/managed-by: Helm 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: matchLabels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/name: fluent-bit template: metadata: @@ -21,7 +21,7 @@ spec: checksum/syn-config: 06e588437d65a5b9ef0171f6ac0a59e7 fluentbit.io/exclude: 'true' labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/name: fluent-bit spec: containers: @@ -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 78% 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..f27d202 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 @@ -2,12 +2,12 @@ apiVersion: v1 kind: Service metadata: labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/managed-by: Helm 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: @@ -16,6 +16,6 @@ spec: protocol: TCP targetPort: http selector: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/name: fluent-bit type: ClusterIP 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 79% 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..b6ff6de 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 @@ -2,10 +2,10 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - app.kubernetes.io/instance: fluent-bit + app.kubernetes.io/instance: fluentbit app.kubernetes.io/managed-by: Helm 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 89% 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..b41c050 100644 --- a/tests/golden/defaults/fluentbit/fluentbit/10_custom_config.yaml +++ b/tests/golden/defaults/fluentbit/fluentbit/fluentbit/10_custom_config.yaml @@ -35,10 +35,10 @@ metadata: annotations: {} labels: app.kubernetes.io/component: fluent-bit - app.kubernetes.io/instance: fluent-bit-cluster + app.kubernetes.io/instance: fluentbit 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