Skip to content

Commit beaef51

Browse files
Improve configuration of transform and partitioner
1 parent 05c4688 commit beaef51

10 files changed

+504
-17
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

EventStore.Replicator.sln.DotSettings

Lines changed: 394 additions & 1 deletion
Large diffs are not rendered by default.

charts/replicator/templates/_helpers.tpl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,69 @@ Return the proper Replicator image name
4545
{{- $repositoryName := .Values.image.repository -}}
4646
{{- $tag := .Values.image.tag | toString -}}
4747
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
48+
{{- end -}}
49+
50+
{{/*
51+
Checks if replicator is configured to use javascript transform
52+
*/}}
53+
{{- define "replicator.shouldUseJavascriptTransform" -}}
54+
{{- if and
55+
.Values.replicator.transform
56+
(eq .Values.replicator.transform.type "js")
57+
.Values.replicator.transform.config
58+
.Values.transformJs
59+
-}}
60+
{{- print "true" }}
61+
{{- end -}}
62+
{{- end -}}
63+
64+
{{/*
65+
Checks if replicator is configured to use a custom partitioner
66+
*/}}
67+
{{- define "replicator.shouldUseCustomPartitioner" -}}
68+
{{- if and
69+
.Values.replicator.sink.partitioner
70+
.Values.partitionerJs
71+
-}}
72+
{{- print "true" }}
73+
{{- end -}}
74+
{{- end -}}
75+
76+
{{- define "replicator.transform.filename" -}}
77+
{{- if eq (include "replicator.shouldUseJavascriptTransform" .) "true" -}}
78+
{{ printf "%s" (include "replicator.helpers.filename" .Values.replicator.transform.config) }}
79+
{{- end -}}
80+
{{- end -}}
81+
82+
{{- define "replicator.transform.filepath" -}}
83+
{{- if eq (include "replicator.shouldUseJavascriptTransform" .) "true" -}}
84+
{{ printf "%s" (include "replicator.helpers.cleansePath" .Values.replicator.transform.config) }}
85+
{{- end -}}
86+
{{- end -}}
87+
88+
{{- define "replicator.sink.partitioner.filename" -}}
89+
{{- if eq (include "replicator.shouldUseCustomPartitioner" .) "true" -}}
90+
{{ printf "%s" (include "replicator.helpers.filename" .Values.replicator.sink.partitioner) }}
91+
{{- end -}}
92+
{{- end -}}
93+
94+
{{- define "replicator.sink.partitioner.filepath" -}}
95+
{{- if eq (include "replicator.shouldUseCustomPartitioner" .) "true" -}}
96+
{{ printf "%s" (include "replicator.helpers.cleansePath" .Values.replicator.sink.partitioner) }}
97+
{{- end -}}
98+
{{- end -}}
99+
100+
{{- define "replicator.helpers.filename" -}}
101+
{{- $file := . -}}
102+
{{- $filename := last (splitList "/" $file) -}}
103+
{{- $filename -}}
104+
{{- end -}}
105+
106+
{{- define "replicator.helpers.cleansePath" -}}
107+
{{- $path := . -}}
108+
{{- $path = replace "./" "/" $path -}}
109+
{{- if not (hasPrefix "/" $path) -}}
110+
{{- $path = printf "/%s" $path -}}
111+
{{- end -}}
112+
{{- $path -}}
48113
{{- end -}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if eq (include "replicator.shouldUseCustomPartitioner" .) "true" -}}
2+
apiVersion: v1
3+
data:
4+
{{ include "replicator.sink.partitioner.filename" . | indent 2 }}: |-
5+
{{ .Values.partitionerJs | indent 4 }}
6+
7+
kind: ConfigMap
8+
metadata:
9+
name: {{ template "replicator.fullname" . }}-partitioner-js
10+
labels:
11+
app: {{ template "replicator.name" . }}
12+
chart: {{ template "replicator.chart" . }}
13+
release: {{ .Release.Name }}
14+
heritage: {{ .Release.Service }}
15+
{{- end }}

charts/replicator/templates/configmap-transform.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
{{- if eq (include "replicator.shouldUseJavascriptTransform" .) "true" -}}
12
apiVersion: v1
23
data:
3-
transform.js: |-
4+
{{ include "replicator.transform.filename" . | indent 2 }}: |-
45
{{ .Values.transformJs | indent 4 }}
56

67
kind: ConfigMap
@@ -11,3 +12,4 @@ metadata:
1112
chart: {{ template "replicator.chart" . }}
1213
release: {{ .Release.Name }}
1314
heritage: {{ .Release.Service }}
15+
{{- end }}

charts/replicator/templates/statefulset.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ spec:
5050
mountPath: /app/js/{{ .fileName }}
5151
subPath: {{ .fileName }}
5252
{{- end }}
53+
{{- if eq (include "replicator.shouldUseJavascriptTransform" .) "true" }}
5354
- name: transform-js
54-
mountPath: /app/transform.js
55-
subPath: transform.js
55+
mountPath: /app{{ include "replicator.transform.filepath" . }}
56+
subPath: {{ include "replicator.transform.filename" . }}
57+
{{- end }}
58+
{{- if eq (include "replicator.shouldUseCustomPartitioner" .) "true" }}
59+
- name: partitioner-js
60+
mountPath: /app{{ include "replicator.sink.partitioner.filepath" . }}
61+
subPath: {{ include "replicator.sink.partitioner.filename" . }}
62+
{{- end }}
5663
resources:
5764
{{ toYaml .Values.resources | indent 10 }}
5865
imagePullSecrets: []
@@ -66,9 +73,16 @@ spec:
6673
configMap:
6774
name: {{ .configMapName }}
6875
{{- end }}
76+
{{- if eq (include "replicator.shouldUseJavascriptTransform" .) "true" }}
6977
- name: transform-js
7078
configMap:
7179
name: {{ template "replicator.fullname" . }}-transform-js
80+
{{- end }}
81+
{{- if eq (include "replicator.shouldUseCustomPartitioner" .) "true" }}
82+
- name: partitioner-js
83+
configMap:
84+
name: {{ template "replicator.fullname" . }}-partitioner-js
85+
{{- end }}
7286
- name: {{ template "replicator.name" . }}
7387
persistentVolumeClaim:
7488
claimName: {{ template "replicator.fullname" . }}

charts/replicator/values.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,5 @@ replicator:
3030
scavenge: true
3131
filters: []
3232
transform: null
33-
transformJs: |-
34-
3533
# restartOnFailure: false
3634
# runContinuously: true

src/es-replicator/Settings/ReplicatorSettings.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
2-
31
// ReSharper disable UnusedAutoPropertyAccessor.Global
42

53
#nullable disable
6-
namespace es_replicator.Settings;
4+
namespace es_replicator.Settings;
75

86
public record EsdbSettings {
97
public string ConnectionString { get; init; }
@@ -57,10 +55,10 @@ public static class ConfigExtensions {
5755
}
5856

5957
public static void AddOptions<T>(
60-
this IServiceCollection services, IConfiguration configuration
58+
this IServiceCollection services,
59+
IConfiguration configuration
6160
)
6261
where T : class {
6362
services.Configure<T>(configuration.GetSection(typeof(T).Name));
6463
}
65-
}
66-
#nullable enable
64+
}

src/es-replicator/Settings/Transformers.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ public static TransformEvent GetTransformer(Replicator settings) {
1111

1212
return type switch {
1313
"default" => Transforms.DefaultWithExtraMeta,
14-
"http" => new HttpTransform(settings.Transform?.Config).Transform,
14+
"http" => GetHttpTransform().Transform,
1515
"js" => GetJsTransform().Transform,
1616
_ => Transforms.DefaultWithExtraMeta,
1717
};
1818

19+
HttpTransform GetHttpTransform() {
20+
Ensure.NotEmpty(settings.Transform?.Config, "Transform config");
21+
22+
return new HttpTransform(settings.Transform!.Config);
23+
}
24+
1925
JsTransform GetJsTransform() {
2026
Ensure.NotEmpty(settings.Transform?.Config, "Transform config");
2127

src/es-replicator/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Immutable;
21
using es_replicator.HttpApi;
32
using es_replicator.Settings;
43
using EventStore.Replicator;

0 commit comments

Comments
 (0)