Skip to content

Commit 5934470

Browse files
committed
Use MANIFEST_PRINT_RBAC_NAMESPACED to generate clickhouse-operator files
This replaces the `ClusterRole` with a `Role` only for posthog namespace. If the clickhouse-operator is only deployed into a single namespace, it only needs access to this namespace and not the whole cluster.
1 parent 5a61f35 commit 5934470

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

charts/posthog/templates/clickhouse-operator/clusterrole.yaml charts/posthog/templates/clickhouse-operator/role.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# Template Parameters:
33
#
44
# NAMESPACE={{ .Values.clickhouse.namespace | default .Release.Namespace }}
5-
# COMMENT=#
6-
# ROLE_KIND=ClusterRole
7-
# ROLE_NAME=clickhouse-operator-{{ .Values.clickhouse.namespace | default .Release.Namespace }}
8-
# ROLE_BINDING_KIND=ClusterRoleBinding
9-
# ROLE_BINDING_NAME=clickhouse-operator-{{ .Values.clickhouse.namespace | default .Release.Namespace }}
5+
# COMMENT=
6+
# ROLE_KIND=Role
7+
# ROLE_NAME=clickhouse-operator
8+
# ROLE_BINDING_KIND=RoleBinding
9+
# ROLE_BINDING_NAME=clickhouse-operator
1010
#
1111
apiVersion: rbac.authorization.k8s.io/v1
12-
kind: ClusterRole
12+
kind: Role
1313
metadata:
14-
name: clickhouse-operator-{{ .Values.clickhouse.namespace | default .Release.Namespace }}
14+
name: clickhouse-operator
1515
namespace: {{ .Values.clickhouse.namespace | default .Release.Namespace }}
1616
labels:
1717
clickhouse.altinity.com/chop: 0.18.4

charts/posthog/templates/clickhouse-operator/clusterrolebinding.yaml charts/posthog/templates/clickhouse-operator/rolebinding.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# Setup ClusterRoleBinding between ClusterRole and ServiceAccount.
33
# ClusterRoleBinding is namespace-less and must have unique name
44
apiVersion: rbac.authorization.k8s.io/v1
5-
kind: ClusterRoleBinding
5+
kind: RoleBinding
66
metadata:
7-
name: clickhouse-operator-{{ .Values.clickhouse.namespace | default .Release.Namespace }}
7+
name: clickhouse-operator
88
namespace: {{ .Values.clickhouse.namespace | default .Release.Namespace }}
99
labels:
1010
clickhouse.altinity.com/chop: 0.18.4
1111
roleRef:
1212
apiGroup: rbac.authorization.k8s.io
13-
kind: ClusterRole
14-
name: clickhouse-operator-{{ .Values.clickhouse.namespace | default .Release.Namespace }}
13+
kind: Role
14+
name: clickhouse-operator
1515
subjects:
1616
- kind: ServiceAccount
1717
name: clickhouse-operator

charts/posthog/tests/clickhouse-operator/__snapshot__/clusterrole.yaml.snap charts/posthog/tests/clickhouse-operator/__snapshot__/role.yaml.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
the manifest should match the snapshot when using default values:
22
1: |
33
apiVersion: rbac.authorization.k8s.io/v1
4-
kind: ClusterRole
4+
kind: Role
55
metadata:
66
labels:
77
clickhouse.altinity.com/chop: 0.18.4
8-
name: clickhouse-operator-NAMESPACE
8+
name: clickhouse-operator
99
namespace: NAMESPACE
1010
rules:
1111
- apiGroups:

charts/posthog/tests/clickhouse-operator/__snapshot__/clusterrolebinding.yaml.snap charts/posthog/tests/clickhouse-operator/__snapshot__/rolebinding.yaml.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
the manifest should match the snapshot when using default values:
22
1: |
33
apiVersion: rbac.authorization.k8s.io/v1
4-
kind: ClusterRoleBinding
4+
kind: RoleBinding
55
metadata:
66
labels:
77
clickhouse.altinity.com/chop: 0.18.4
8-
name: clickhouse-operator-NAMESPACE
8+
name: clickhouse-operator
99
namespace: NAMESPACE
1010
roleRef:
1111
apiGroup: rbac.authorization.k8s.io
12-
kind: ClusterRole
13-
name: clickhouse-operator-NAMESPACE
12+
kind: Role
13+
name: clickhouse-operator
1414
subjects:
1515
- kind: ServiceAccount
1616
name: clickhouse-operator

charts/posthog/tests/clickhouse-operator/clusterrole.yaml charts/posthog/tests/clickhouse-operator/role.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
suite: ClickHouse cluster role definition
1+
suite: ClickHouse role definition
22
templates:
3-
- templates/clickhouse-operator/clusterrole.yaml
3+
- templates/clickhouse-operator/role.yaml
44

55
tests:
66
- it: should be empty if clickhouse.enabled is set to false
@@ -16,7 +16,7 @@ tests:
1616
count: 1
1717
- matchSnapshot: {}
1818

19-
- it: ClusterRole/clickhouse-operator-posthog metadata.namespace override via clickhouse.namespace should work
19+
- it: Role/clickhouse-operator-posthog metadata.namespace override via clickhouse.namespace should work
2020
set:
2121
clickhouse.namespace: "custom-namespace"
2222
documentIndex: 0
@@ -27,7 +27,7 @@ tests:
2727
path: metadata.namespace
2828
value: custom-namespace
2929

30-
- it: ClusterRole/clickhouse-operator-posthog metadata.namespace override via Release.Namespace should work
30+
- it: Role/clickhouse-operator-posthog metadata.namespace override via Release.Namespace should work
3131
release:
3232
namespace: custom-namespace-from-release
3333
documentIndex: 0

charts/posthog/tests/clickhouse-operator/clusterrolebinding.yaml charts/posthog/tests/clickhouse-operator/rolebinding.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
suite: ClickHouse cluster role binding definition
1+
suite: ClickHouse role binding definition
22
templates:
3-
- templates/clickhouse-operator/clusterrolebinding.yaml
3+
- templates/clickhouse-operator/rolebinding.yaml
44

55
tests:
66
- it: should be empty if clickhouse.enabled is set to false
@@ -16,7 +16,7 @@ tests:
1616
count: 1
1717
- matchSnapshot: {}
1818

19-
- it: ClusterRoleBinding/clickhouse-operator-posthog metadata.namespace override via clickhouse.namespace should work
19+
- it: RoleBinding/clickhouse-operator-posthog metadata.namespace override via clickhouse.namespace should work
2020
set:
2121
clickhouse.namespace: "custom-namespace"
2222
documentIndex: 0
@@ -27,7 +27,7 @@ tests:
2727
path: metadata.namespace
2828
value: custom-namespace
2929

30-
- it: ClusterRoleBinding/clickhouse-operator-posthog metadata.namespace override via Release.Namespace should work
30+
- it: RoleBinding/clickhouse-operator-posthog metadata.namespace override via Release.Namespace should work
3131
release:
3232
namespace: custom-namespace-from-release
3333
documentIndex: 0
@@ -38,7 +38,7 @@ tests:
3838
path: metadata.namespace
3939
value: custom-namespace-from-release
4040

41-
- it: ClusterRoleBinding/clickhouse-operator-posthog subjects[0].namespace override via clickhouse.namespace should work
41+
- it: RoleBinding/clickhouse-operator-posthog subjects[0].namespace override via clickhouse.namespace should work
4242
set:
4343
clickhouse.namespace: "custom-namespace"
4444
documentIndex: 0
@@ -49,7 +49,7 @@ tests:
4949
path: subjects[0].namespace
5050
value: custom-namespace
5151

52-
- it: ClusterRoleBinding/clickhouse-operator-posthog subjects[0].namespace override via Release.Namespace should work
52+
- it: RoleBinding/clickhouse-operator-posthog subjects[0].namespace override via Release.Namespace should work
5353
release:
5454
namespace: custom-namespace-from-release
5555
documentIndex: 0

scripts/clickhouse_operator_sync.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ TMP_FOLDER="$(mktemp -d)"
1818
trap 'rm -rf -- "$TMP_FOLDER"' EXIT
1919

2020
CLICKHOUSE_OPERATOR_TAG="0.18.4"
21-
URL="https://raw.githubusercontent.com/Altinity/clickhouse-operator/${CLICKHOUSE_OPERATOR_TAG}/deploy/operator/clickhouse-operator-install-template.yaml"
21+
REPO_URL="https://github.com/Altinity/clickhouse-operator.git"
2222

2323
#
24-
# Download the 'altinity/clickhouse-operator' definition and save it as temporary file.
25-
#
26-
# 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
24+
# Clone the 'altinity/clickhouse-operator' repo to temp folder.
2725
#
26+
git clone --depth 1 --branch ${CLICKHOUSE_OPERATOR_TAG} ${REPO_URL} "${TMP_FOLDER}"
27+
2828
OPERATOR_NAMESPACE="PLACEHOLDER"
2929
METRICS_EXPORTER_NAMESPACE="${OPERATOR_NAMESPACE}"
3030
# NOTE: we pin to 0.19.0 here which is different to the 0.16.1 manifest version.
@@ -35,12 +35,12 @@ METRICS_EXPORTER_NAMESPACE="${OPERATOR_NAMESPACE}"
3535
OPERATOR_IMAGE="${OPERATOR_IMAGE:-altinity/clickhouse-operator:0.19.0}"
3636
METRICS_EXPORTER_IMAGE="${METRICS_EXPORTER_IMAGE:-altinity/metrics-exporter:latest}"
3737

38-
curl -s "${URL}" | \
39-
OPERATOR_IMAGE="${OPERATOR_IMAGE}" \
40-
OPERATOR_NAMESPACE="${OPERATOR_NAMESPACE}" \
41-
METRICS_EXPORTER_IMAGE="${METRICS_EXPORTER_IMAGE}" \
42-
METRICS_EXPORTER_NAMESPACE="${METRICS_EXPORTER_NAMESPACE}" \
43-
envsubst > "$TMP_FOLDER/clickhouse-operator.yaml"
38+
OPERATOR_IMAGE="${OPERATOR_IMAGE}" \
39+
OPERATOR_NAMESPACE="${OPERATOR_NAMESPACE}" \
40+
METRICS_EXPORTER_IMAGE="${METRICS_EXPORTER_IMAGE}" \
41+
METRICS_EXPORTER_NAMESPACE="${METRICS_EXPORTER_NAMESPACE}" \
42+
MANIFEST_PRINT_RBAC_NAMESPACED=yes \
43+
"${TMP_FOLDER}/deploy/builder/cat-clickhouse-operator-install-yaml.sh" > "${TMP_FOLDER}/clickhouse-operator.yaml"
4444

4545
#
4646
# Use 'altinity/clickhouse-operator' definition file we fetched and parsed and slice it

0 commit comments

Comments
 (0)