forked from PostHog/charts-clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickhouse_operator_sync.sh
executable file
·73 lines (63 loc) · 3.32 KB
/
clickhouse_operator_sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
#
# This tool fetches and formats 'Altinity/clickhouse-operator'
# k8s resource definitions into our chart.
#
# Why do we need this? The 'clickhouse-operator' doesn't expose a Helm
# package so we need to collect and bundle the resources by our own.
#
set -e
set -u
set -o pipefail
CURRENT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd -P)"
CHART_PATH_RAW="${CURRENT_DIR}/../charts/posthog"
CHART_PATH=$(cd "$CHART_PATH_RAW" 2> /dev/null && pwd -P)
TMP_FOLDER="$(mktemp -d)"
trap 'rm -rf -- "$TMP_FOLDER"' EXIT
CLICKHOUSE_OPERATOR_TAG="0.18.4"
URL="https://raw.githubusercontent.com/Altinity/clickhouse-operator/${CLICKHOUSE_OPERATOR_TAG}/deploy/operator/clickhouse-operator-install-template.yaml"
#
# Download the 'altinity/clickhouse-operator' definition and save it as temporary file.
#
# see: https://github.com/Altinity/clickhouse-operator/blob/master/docs/quick_start.md#in-case-you-can-not-run-scripts-from-internet-in-your-protected-environment
#
OPERATOR_NAMESPACE="PLACEHOLDER"
METRICS_EXPORTER_NAMESPACE="${OPERATOR_NAMESPACE}"
# NOTE: we pin to 0.19.0 here which is different to the 0.16.1 manifest version.
# Prior to pinning we were specifying latest, so to ensure that the version
# doesn't change on existing installs we pin to latest as of writing, thereby
# mitigating the possibility that chart will unexpectedly update, while also
# maintaining current functionality.
OPERATOR_IMAGE="${OPERATOR_IMAGE:-altinity/clickhouse-operator:0.19.0}"
METRICS_EXPORTER_IMAGE="${METRICS_EXPORTER_IMAGE:-altinity/metrics-exporter:latest}"
curl -s "${URL}" | \
OPERATOR_IMAGE="${OPERATOR_IMAGE}" \
OPERATOR_NAMESPACE="${OPERATOR_NAMESPACE}" \
METRICS_EXPORTER_IMAGE="${METRICS_EXPORTER_IMAGE}" \
METRICS_EXPORTER_NAMESPACE="${METRICS_EXPORTER_NAMESPACE}" \
envsubst > "$TMP_FOLDER/clickhouse-operator.yaml"
#
# Use 'altinity/clickhouse-operator' definition file we fetched and parsed and slice it
# in different files, based on the resource kind
#
go install github.com/patrickdappollonio/[email protected]
rm -rf "${CHART_PATH}/templates/clickhouse-operator"
mkdir -p "${CHART_PATH}/templates/clickhouse-operator"
kubectl-slice -f "$TMP_FOLDER/clickhouse-operator.yaml" -o "${CHART_PATH}/crds" --include-kind CustomResourceDefinition --template '{{.metadata.name}}.yaml'
kubectl-slice -f "$TMP_FOLDER/clickhouse-operator.yaml" -o "${CHART_PATH}/templates/clickhouse-operator" --exclude-kind CustomResourceDefinition --template '{{.kind | lower}}.yaml'
#
# Add a {{- if .Values.clickhouse.enabled }} and {{- end }} at the end of each non-crds resource.
# Also replace 'namespace: posthog' and '#namespace: posthog' with
# {{ .Values.clickhouse.namespace | default .Release.Namespace }} so we can keep customizing where the operator is installed
#
FILES="${CHART_PATH}/templates/clickhouse-operator/*"
for f in $FILES
do
# NOTE: previously we were using sed with the `-i` option to specify that we
# should to the modifications in place. The option behaviour between GNU and
# BSD versions, hence here we opt for using perl instead.
perl -pi -e 'print "{{- if .Values.clickhouse.enabled }}\n" if $. == 1' "$f"
echo "{{- end }}" >> "$f"
perl -pi -e 's/PLACEHOLDER$/{{ .Values.clickhouse.namespace | default .Release.Namespace }}/g' "$f"
perl -pi -e 's/#namespace: /namespace: /g' "$f"
done