Skip to content

Commit 35cd04e

Browse files
yassannineinchnick
authored andcommitted
Add support for Database resource group manager
1 parent 1e7c08a commit 35cd04e

8 files changed

+156
-8
lines changed

charts/trino/README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,23 @@ Fast distributed SQL query engine for big data analytics that helps you explore
175175
```
176176
* `resourceGroups` - object, default: `{}`
177177

178-
Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
179-
Example:
178+
[Resource groups control](https://trino.io/docs/current/admin/resource-groups.html)
179+
Set the type property to either:
180+
* `configmap`, and provide the Resource groups file contents in `resourceGroupsConfig`,
181+
* `properties`, and provide configuration properties in `properties`.
182+
Properties example:
180183
```yaml
184+
type: properties
185+
properties: |
186+
resource-groups.configuration-manager=db
187+
resource-groups.config-db-url=jdbc:postgresql://trino-postgresql.postgresql.svc.cluster.local:3306/resource_groups
188+
resource-groups.config-db-user=username
189+
resource-groups.config-db-password=password
190+
```
191+
Config map example:
192+
```yaml
193+
type: configmap
194+
# Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
181195
resourceGroupsConfig: |-
182196
{
183197
"rootGroups": [

charts/trino/templates/configmap-coordinator.yaml

+12-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,20 @@ data:
105105
{{- end }}
106106

107107
{{- if .Values.resourceGroups }}
108+
{{- if eq .Values.resourceGroups.type "configmap" }}
108109
resource-groups.properties: |
109110
resource-groups.configuration-manager=file
110111
resource-groups.config-file={{ .Values.server.config.path }}/resource-groups/resource-groups.json
112+
{{- else if eq .Values.resourceGroups.type "properties" }}
113+
resource-groups.properties: |
114+
{{- if .Values.resourceGroups.properties }}
115+
{{- .Values.resourceGroups.properties | nindent 4 }}
116+
{{- else}}
117+
{{- fail "resourceGroups.properties is required when resourceGroups.type is 'properties'." }}
118+
{{- end }}
119+
{{- else}}
120+
{{- fail "Invalid resourceGroups.type value. It must be either 'configmap' or 'properties'." }}
121+
{{- end }}
111122
{{- end }}
112123

113124
{{- if .Values.server.exchangeManager }}
@@ -151,7 +162,7 @@ data:
151162
{{ $fileName }}: |
152163
{{- tpl $fileContent $ | nindent 4 }}
153164
{{- end }}
154-
{{- if .Values.resourceGroups }}
165+
{{- if eq .Values.resourceGroups.type "configmap" }}
155166
---
156167
apiVersion: v1
157168
kind: ConfigMap

charts/trino/templates/deployment-coordinator.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ spec:
6969
configMap:
7070
name: {{ template "trino.fullname" . }}-access-control-volume-coordinator
7171
{{- end }}
72-
{{- if .Values.resourceGroups }}
72+
{{- if eq .Values.resourceGroups.type "configmap" }}
7373
- name: resource-groups-volume
7474
configMap:
7575
name: {{ template "trino.fullname" . }}-resource-groups-volume-coordinator
@@ -150,7 +150,7 @@ spec:
150150
- mountPath: {{ .Values.server.config.path }}/access-control
151151
name: access-control-volume
152152
{{- end }}
153-
{{- if .Values.resourceGroups }}
153+
{{- if eq .Values.resourceGroups.type "configmap" }}
154154
- mountPath: {{ .Values.server.config.path }}/resource-groups
155155
name: resource-groups-volume
156156
{{- end }}

charts/trino/templates/tests/test-connection.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ metadata:
99
annotations:
1010
"helm.sh/hook": test
1111
spec:
12+
{{- if eq .Values.resourceGroups.type "properties" }}
13+
initContainers:
14+
- name: postgresql-client
15+
image: bitnami/postgresql:17.1.0
16+
command:
17+
- /bin/sh
18+
- -c
19+
- |
20+
echo "Inserting resource groups data";
21+
PGUSER=trino PGPASSWORD=pass0000 psql -h trino-resource-groups-db-postgresql.postgresql.svc.cluster.local resource_groups <<SQL
22+
-- create a root group 'admin' with NULL parent
23+
INSERT INTO resource_groups (name, soft_memory_limit, hard_concurrency_limit, max_queued, scheduling_policy, environment)
24+
VALUES ('admin', '100%', 50, 100, 'query_priority', 'production');
25+
-- use ID of 'admin' resource group for selector
26+
INSERT INTO selectors (resource_group_id, user_regex, priority) VALUES ((SELECT resource_group_id FROM resource_groups WHERE name = 'admin'), 'admin', 6);
27+
SQL
28+
{{- end }}
1229
containers:
1330
- name: cli
1431
image: {{ include "trino.image" . }}

charts/trino/values.yaml

+16-2
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,24 @@ accessControl: {}
183183
# ```
184184

185185
resourceGroups: {}
186-
# resourceGroups -- Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
186+
# resourceGroups -- [Resource groups control](https://trino.io/docs/current/admin/resource-groups.html)
187187
# @raw
188-
# Example:
188+
# Set the type property to either:
189+
# * `configmap`, and provide the Resource groups file contents in `resourceGroupsConfig`,
190+
# * `properties`, and provide configuration properties in `properties`.
191+
# Properties example:
189192
# ```yaml
193+
# type: properties
194+
# properties: |
195+
# resource-groups.configuration-manager=db
196+
# resource-groups.config-db-url=jdbc:postgresql://trino-postgresql.postgresql.svc.cluster.local:3306/resource_groups
197+
# resource-groups.config-db-user=username
198+
# resource-groups.config-db-password=password
199+
# ```
200+
# Config map example:
201+
# ```yaml
202+
# type: configmap
203+
# # Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
190204
# resourceGroupsConfig: |-
191205
# {
192206
# "rootGroups": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Resource Groups 'properties' values to test.
2+
# This is a YAML-formatted file.
3+
4+
server:
5+
log:
6+
trino:
7+
level: INFO
8+
9+
resourceGroups:
10+
type: properties
11+
properties: |
12+
resource-groups.configuration-manager=db
13+
resource-groups.config-db-url=jdbc:postgresql://trino-resource-groups-db-postgresql.postgresql.svc.cluster.local:5432/resource_groups
14+
resource-groups.config-db-user=trino
15+
resource-groups.config-db-password=pass0000

test-values.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,66 @@ accessControl:
172172
]
173173
}
174174
175+
resourceGroups:
176+
type: configmap
177+
resourceGroupsConfig: |-
178+
{
179+
"rootGroups": [
180+
{
181+
"name": "global",
182+
"softMemoryLimit": "80%",
183+
"hardConcurrencyLimit": 100,
184+
"maxQueued": 100,
185+
"schedulingPolicy": "fair",
186+
"jmxExport": true,
187+
"subGroups": [
188+
{
189+
"name": "admin",
190+
"softMemoryLimit": "30%",
191+
"hardConcurrencyLimit": 20,
192+
"maxQueued": 10
193+
},
194+
{
195+
"name": "finance_human_resources",
196+
"softMemoryLimit": "20%",
197+
"hardConcurrencyLimit": 15,
198+
"maxQueued": 10
199+
},
200+
{
201+
"name": "general",
202+
"softMemoryLimit": "30%",
203+
"hardConcurrencyLimit": 20,
204+
"maxQueued": 10
205+
},
206+
{
207+
"name": "readonly",
208+
"softMemoryLimit": "10%",
209+
"hardConcurrencyLimit": 5,
210+
"maxQueued": 5
211+
}
212+
]
213+
}
214+
],
215+
"selectors": [
216+
{
217+
"user": "admin",
218+
"group": "global.admin"
219+
},
220+
{
221+
"group": "finance|human_resources",
222+
"group": "global.finance_human_resources"
223+
},
224+
{
225+
"user": "alice",
226+
"group": "global.readonly"
227+
},
228+
{
229+
"group": "global.general"
230+
}
231+
]
232+
}
233+
234+
175235
jmx:
176236
enabled: true
177237
registryPort: 9080

test.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare -A testCases=(
1111
[exchange_manager_values]="--values test-exchange-manager-values.yaml"
1212
[graceful_shutdown]="--values test-graceful-shutdown-values.yaml"
1313
[gateway]=""
14+
[resource_groups_properties]="--values test-resource-groups-properties-values.yaml"
1415
)
1516

1617
declare -A testCaseCharts=(
@@ -22,6 +23,7 @@ declare -A testCaseCharts=(
2223
[exchange_manager_values]="charts/trino"
2324
[graceful_shutdown]="charts/trino"
2425
[gateway]="charts/gateway"
26+
[resource_groups_properties]="charts/trino"
2527
)
2628

2729
function join_by {
@@ -33,13 +35,14 @@ function join_by {
3335

3436
# default to randomly generated namespace, same as chart-testing would do, but we need to load secrets into the same namespace
3537
NAMESPACE=trino-$(LC_ALL=C tr -dc 'a-z0-9' </dev/urandom | head -c 6 || true)
38+
DB_NAMESPACE=postgresql
3639
HELM_EXTRA_SET_ARGS=
3740
CT_ARGS=(
3841
--skip-clean-up
3942
--helm-extra-args="--timeout 2m"
4043
)
4144
CLEANUP_NAMESPACE=true
42-
TEST_NAMES=(default single_node complete_values access_control_properties_values exchange_manager_values graceful_shutdown)
45+
TEST_NAMES=(default single_node complete_values access_control_properties_values exchange_manager_values graceful_shutdown resource_groups_properties)
4346

4447
usage() {
4548
cat <<EOF 1>&2
@@ -115,6 +118,18 @@ if printf '%s\0' "${TEST_NAMES[@]}" | grep -qwz complete_values; then
115118
kubectl rollout status --watch deployments -l release=prometheus-operator -n "$NAMESPACE"
116119
fi
117120

121+
# only install the PostgreSQL Helm chart when running the `resource_groups_properties` test
122+
if printf '%s\0' "${TEST_NAMES[@]}" | grep -qwz resource_groups_properties; then
123+
helm upgrade --install trino-resource-groups-db oci://registry-1.docker.io/bitnamicharts/postgresql -n "$DB_NAMESPACE" \
124+
--create-namespace \
125+
--version "16.2.1" \
126+
--set auth.username=trino \
127+
--set auth.password=pass0000 \
128+
--set auth.database=resource_groups \
129+
--set primary.persistence.enabled=false
130+
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=postgresql --timeout=300s -n "$DB_NAMESPACE"
131+
fi
132+
118133
CT_ARGS+=(--namespace "$NAMESPACE")
119134

120135
result=0
@@ -139,6 +154,8 @@ for test_name in "${TEST_NAMES[@]}"; do
139154
done
140155

141156
if [ "$CLEANUP_NAMESPACE" == "true" ]; then
157+
helm -n "$DB_NAMESPACE" uninstall trino-resource-groups-db --ignore-not-found
158+
kubectl delete namespace "$DB_NAMESPACE" --ignore-not-found
142159
helm -n "$NAMESPACE" uninstall prometheus-operator --ignore-not-found
143160
kubectl delete namespace "$NAMESPACE"
144161
mapfile -t crds < <(kubectl api-resources --api-group=monitoring.coreos.com --output name)

0 commit comments

Comments
 (0)