Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple instances #71

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
parameters:
fluentbit:
=_metadata:
multi_instance: true

namespace: syn-fluentbit
createNamespace: true

charts:
fluent-bit:
Expand All @@ -16,7 +20,7 @@ parameters:
annotations:
fluentbit.io/exclude: "true"

configMapName: syn-fluentbit-config
configMapName: ${_instance}
config:
# fluent-bit service config
service:
Expand Down Expand Up @@ -78,6 +82,7 @@ parameters:
tolerations: []

helm_values:
fullnameOverride: ${_instance}
podAnnotations: ${fluentbit:annotations}
image:
repository: ${fluentbit:images:fluent_bit:image}
Expand Down
15 changes: 7 additions & 8 deletions class/fluentbit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 8 additions & 2 deletions component/app.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
9 changes: 5 additions & 4 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand All @@ -162,15 +163,15 @@ 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') {
metadata+: {
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',
Expand All @@ -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,
},
},
},
Expand Down
16 changes: 16 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions tests/golden/defaults/fluentbit/apps/fluentbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spec:
source:
path: manifests/fluentbit/fluentbit
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading