Skip to content

Commit 82c6ca4

Browse files
committed
feat(valkey): add valkey sentinel support
1 parent 24d4d57 commit 82c6ca4

12 files changed

Lines changed: 104 additions & 97 deletions

File tree

.woodpecker/chart.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ steps:
1111
- export APP_VERSION=$([ -z $CI_COMMIT_TAG ] && echo $CI_COMMIT_SHA || echo $VERSION)
1212
- export CHART_VERSION=$([ -z $CI_COMMIT_TAG ] && echo 1.0.0 || echo $VERSION)
1313
- sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/$${CI_REPO_NAME}/values.yaml
14+
- sed -i s#{{repository}}#oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)#g charts/$${CI_REPO_NAME}/Chart.yaml
1415
- helm package -u charts/$${CI_REPO_NAME} --version $CHART_VERSION --app-version $APP_VERSION
1516
- echo $CONTAINER_PASSWORD | helm registry login $DRYCC_REGISTRY -u $CONTAINER_USERNAME --password-stdin
1617
- helm push $${CI_REPO_NAME}-$CHART_VERSION.tgz oci://$DRYCC_REGISTRY/$([ -z $CI_COMMIT_TAG ] && echo charts-testing || echo charts)

charts/helmbroker/Chart.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ dependencies:
66
- name: common
77
repository: oci://registry.drycc.cc/charts
88
version: ~1.1.2
9-
- name: redis
10-
repository: oci://registry.drycc.cc/charts
11-
version: x.x.x
12-
- name: rabbitmq
13-
repository: oci://registry.drycc.cc/charts
9+
- name: valkey
10+
repository: {{repository}}
1411
version: x.x.x
1512
description: Drycc Workflow helmbroker.
1613
maintainers:

charts/helmbroker/templates/_helpers.tpl

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,20 @@ env:
77
value: {{ if .Values.username | default "" | ne "" }}{{ .Values.username }}{{ else }}{{ randAlphaNum 32 }}{{ end }}
88
- name: HELMBROKER_PASSWORD
99
value: {{ if .Values.password | default "" | ne "" }}{{ .Values.password }}{{ else }}{{ randAlphaNum 32 }}{{ end }}
10-
{{- if (.Values.rabbitmqUrl) }}
11-
- name: HELMBROKER_RABBITMQ_URL
12-
value: {{ .Values.rabbitmqUrl }}
13-
{{- else if eq .Values.global.rabbitmqLocation "on-cluster" }}
14-
- name: "HELMBROKER_RABBITMQ_USERNAME"
10+
{{- if (.Values.valkeyUrl) }}
11+
- name: HELMBROKER_VALKEY_URL
1512
valueFrom:
1613
secretKeyRef:
17-
name: rabbitmq-creds
18-
key: username
19-
- name: "HELMBROKER_RABBITMQ_PASSWORD"
14+
name: helmbroker-creds
15+
key: valkey-url
16+
{{- else if eq .Values.global.valkeyLocation "on-cluster" }}
17+
- name: VALKEY_PASSWORD
2018
valueFrom:
2119
secretKeyRef:
22-
name: rabbitmq-creds
20+
name: valkey-creds
2321
key: password
24-
- name: "HELMBROKER_RABBITMQ_URL"
25-
value: "amqp://$(HELMBROKER_RABBITMQ_USERNAME):$(HELMBROKER_RABBITMQ_PASSWORD)@drycc-rabbitmq.{{$.Release.Namespace}}.svc.{{$.Values.global.clusterDomain}}:5672/helmbroker"
26-
{{- end }}
27-
{{- if (.Values.redisUrl) }}
28-
- name: HELMBROKER_REDIS_URL
29-
value: {{ .Values.redisUrl }}
30-
{{- else if eq .Values.global.redisLocation "on-cluster" }}
31-
- name: "HELMBROKER_REDIS_ADDRS"
32-
valueFrom:
33-
secretKeyRef:
34-
name: redis-creds
35-
key: addrs
36-
- name: "HELMBROKER_REDIS_PASSWORD"
37-
valueFrom:
38-
secretKeyRef:
39-
name: redis-creds
40-
key: password
41-
- name: "HELMBROKER_REDIS_URL"
42-
value: "redis://:$(HELMBROKER_REDIS_PASSWORD)@$(HELMBROKER_REDIS_ADDRS)/0"
22+
- name: HELMBROKER_VALKEY_URL
23+
value: "redis://:$(VALKEY_PASSWORD)@drycc-valkey.{{.Release.Namespace}}.svc.{{.Values.global.clusterDomain}}:26379/0?master_set=drycc"
4324
{{- end }}
4425
{{- range $key, $value := .Values.environment }}
4526
- name: {{ $key }}

charts/helmbroker/templates/helmbroker-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
- netcat
3535
- -v
3636
- -u
37-
- $(HELMBROKER_REDIS_URL),$(HELMBROKER_RABBITMQ_URL)
37+
- $(HELMBROKER_VALKEY_URL)
3838
{{- include "helmbroker.envs" . | indent 10 }}
3939
- name: drycc-helmbroker-fetch
4040
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/helmbroker:{{.Values.imageTag}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: helmbroker-creds
5+
labels:
6+
heritage: drycc
7+
data:
8+
{{- if (.Values.valkeyUrl) }}
9+
valkey-url: {{ .Values.valkeyUrl | b64enc }}
10+
{{- end }}

charts/helmbroker/values.yaml

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ diagnosticMode:
2323

2424
## config the helm-broker repositories
2525
repositories:
26-
- name: drycc-helm-broker
27-
url: https://github.com/drycc/addons/releases/download/latest/index.yaml
26+
- name: drycc-helm-broker
27+
url: https://github.com/drycc/addons/releases/download/latest/index.yaml
2828

2929
celeryReplicas: 1
3030

@@ -33,11 +33,8 @@ celeryReplicas: 1
3333
username: admin
3434
password: admin
3535

36-
# Configuring this will no longer use the built-in redis component
37-
redisUrl: ""
38-
39-
# Configuring this will no longer use the built-in rabbitmq component
40-
rabbitmqUrl: ""
36+
# Configuring this will no longer use the built-in valkey component
37+
valkeyUrl: ""
4138

4239
# Any custom controller environment variables
4340
# can be specified as key-value pairs under environment
@@ -51,7 +48,7 @@ api:
5148
key: "drycc.cc/node"
5249
type: "soft"
5350
values:
54-
- "true"
51+
- "true"
5552
podAffinityPreset:
5653
type: ""
5754
extraMatchLabels:
@@ -66,7 +63,7 @@ celery:
6663
key: "drycc.cc/node"
6764
type: "soft"
6865
values:
69-
- "true"
66+
- "true"
7067
podAffinityPreset:
7168
type: ""
7269
extraMatchLabels:
@@ -76,10 +73,6 @@ celery:
7673
extraMatchLabels:
7774
app: "drycc-helmbroker-celery"
7875

79-
# drycc redis replicas must always be set to 1
80-
redis:
81-
replicas: 1
82-
8376
# Default override of addon values
8477
addonValues: {}
8578

@@ -91,16 +84,11 @@ persistence:
9184
volumeName: ""
9285

9386
global:
94-
# Set the location of Workflow's redis instance
95-
# Valid values are:
96-
# - on-cluster: Run Redis within the Kubernetes cluster
97-
# - off-cluster: Run Redis outside the Kubernetes cluster (configure in controller section)
98-
redisLocation: "on-cluster"
99-
# Set the location of Workflow's rabbitmq instance
87+
# Set the location of Workflow's valkey instance
10088
# Valid values are:
101-
# - on-cluster: Run Rabbitmq within the Kubernetes cluster
102-
# - off-cluster: Run Rabbitmq outside the Kubernetes cluster (configure in controller section)
103-
rabbitmqLocation: "on-cluster"
89+
# - on-cluster: Run Valkey within the Kubernetes cluster
90+
# - off-cluster: Run Valkey outside the Kubernetes cluster (configure in controller section)
91+
valkeyLocation: "on-cluster"
10492
# Enable usage of RBAC authorization mode
10593
#
10694
# Valid values are:

rootfs/helmbroker/celery.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
import os
2+
from urllib.parse import urlparse, parse_qs, urlencode
23
from kombu import Exchange, Queue
34
from celery import Celery
5+
from .config import VALKEY_URL
46

57

68
class Config(object):
79
# Celery Configuration Options
8-
timezone = "Asia/Shanghai"
910
enable_utc = True
1011
task_serializer = 'pickle'
1112
accept_content = frozenset([
12-
'application/data',
13-
'application/text',
14-
'application/json',
15-
'application/x-python-serialize',
13+
'application/data',
14+
'application/text',
15+
'application/json',
16+
'application/x-python-serialize',
1617
])
1718
task_track_started = True
1819
task_time_limit = 30 * 60
1920
worker_max_tasks_per_child = 200
21+
worker_prefetch_multiplier = 1
2022
result_expires = 24 * 60 * 60
21-
broker_url = os.environ.get("HELMBROKER_RABBITMQ_URL", 'amqp://guest:guest@127.0.0.1:5672/')
22-
broker_connection_retry_on_startup = True
23-
task_default_queue = 'helmbroker.low'
23+
cache_backend = 'django-cache'
24+
task_default_queue = 'helmbroker.middle'
2425
task_default_exchange = 'helmbroker.priority'
25-
task_default_routing_key = 'helmbroker.priority.low'
26+
task_default_routing_key = 'helmbroker.priority.middle'
27+
broker_transport_options = {"queue_order_strategy": "sorted"}
28+
task_create_missing_queues = True
29+
task_inherit_parent_priority = True
2630
broker_connection_retry_on_startup = True
2731
worker_cancel_long_running_tasks_on_connection_loss = True
2832

2933

3034
app = Celery('helmbroker')
3135
app.config_from_object(Config())
3236
app.conf.update(
37+
timezone=os.environ.get('TZ', 'UTC'),
3338
task_routes={
3439
'helmbroker.tasks.provision': {
3540
'queue': 'helmbroker.high',
@@ -51,22 +56,36 @@ class Config(object):
5156
task_queues=(
5257
Queue(
5358
'helmbroker.low', exchange=Exchange('helmbroker.priority', type="direct"),
54-
routing_key='helmbroker.priority.low', queue_arguments={'x-queue-type': 'quorum'},
59+
routing_key='helmbroker.priority.low',
5560
),
5661
Queue(
5762
'helmbroker.high', exchange=Exchange('helmbroker.priority', type="direct"),
58-
routing_key='helmbroker.priority.high', queue_arguments={'x-queue-type': 'quorum'},
63+
routing_key='helmbroker.priority.high',
5964
),
6065
Queue(
6166
'helmbroker.middle', exchange=Exchange('helmbroker.priority', type="direct"),
62-
routing_key='helmbroker.priority.middle', queue_arguments={'x-queue-type': 'quorum'},
67+
routing_key='helmbroker.priority.middle',
6368
),
6469
),
6570
)
6671
app.autodiscover_tasks(("helmbroker.tasks",))
67-
68-
69-
app.config_from_object(Config())
72+
url = urlparse(VALKEY_URL)
73+
query = parse_qs(url.query)
74+
broker_transport_options = {"queue_order_strategy": "sorted", "visibility_timeout": 43200}
75+
result_backend_transport_options = {}
76+
if 'master_set' in query:
77+
master_name = query.pop('master_set')[0]
78+
password = url.netloc.split("@")[0].split(":")[1]
79+
kwargs = {'sentinel_kwargs': {'password': password}, 'master_name': master_name}
80+
broker_transport_options.update(kwargs)
81+
result_backend_transport_options.update(kwargs)
82+
VALKEY_URL = f"sentinel://{url.netloc}{url.path}?{urlencode(query)}"
83+
app.conf.update(
84+
broker_url=VALKEY_URL,
85+
result_backend=VALKEY_URL,
86+
broker_transport_options=broker_transport_options,
87+
result_backend_transport_options=result_backend_transport_options,
88+
)
7089

7190
if __name__ == '__main__':
7291
app.start()

rootfs/helmbroker/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
USERNAME = os.environ.get('HELMBROKER_USERNAME')
1111
PASSWORD = os.environ.get('HELMBROKER_PASSWORD')
1212

13-
REDIS_URL = os.environ.get("HELMBROKER_REDIS_URL", 'redis://localhost:6379/0')
13+
VALKEY_URL = os.environ.get("HELMBROKER_VALKEY_URL", 'redis://localhost:6379/0')
1414

1515

1616
class Config:

rootfs/helmbroker/database/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _fetch_addon(url, dest):
5858
os.makedirs(dest, exist_ok=True)
5959
with tarfile.open(fileobj=tgz_file, mode="r:gz") as tarobj:
6060
for tarinfo in tarobj:
61-
tarobj.extract(tarinfo.name, dest)
61+
tarobj.extract(tarinfo.name, dest, filter='data')
6262
filename1 = os.path.join(dest, "meta.yaml")
6363
with open(filename1, "r") as f1:
6464
meta = yaml.load(stream=f1, Loader=yaml.Loader)

rootfs/helmbroker/database/metadata.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import logging
55
import jsonschema
66

7-
from redis import client
8-
from ..config import ADDONS_PATH, REDIS_URL
7+
from ..utils import get_valkey_client
8+
from ..config import ADDONS_PATH
99

1010
logger = logging.getLogger(__name__)
1111

@@ -116,21 +116,20 @@ def save_instance_meta(instance_id, data):
116116
json_data = json.dumps(data, sort_keys=True, indent=2)
117117
with open(file, "w") as f:
118118
f.write(json_data)
119-
redis = client.Redis.from_url(REDIS_URL)
120-
redis.set(cache_key, json_data)
119+
get_valkey_client().set(cache_key, json_data)
121120

122121

123122
def load_instance_meta(instance_id):
124123
cache_key = f"helmbroker:instance:{instance_id}"
125-
redis = client.Redis.from_url(REDIS_URL)
124+
valkey = get_valkey_client()
126125

127-
json_data = redis.get(cache_key)
126+
json_data = valkey.get(cache_key)
128127
if not json_data:
129128
from .query import get_instance_file
130129
file = get_instance_file(instance_id)
131130
with open(file) as f:
132131
json_data = f.read()
133-
redis.set(cache_key, json_data)
132+
valkey.set(cache_key, json_data)
134133
return json.loads(json_data)
135134

136135

@@ -144,20 +143,19 @@ def save_binding_meta(instance_id, data):
144143
json_data = json.dumps(data, sort_keys=True, indent=2)
145144
with open(file, "w") as f:
146145
f.write(json_data)
147-
redis = client.Redis.from_url(REDIS_URL)
148-
redis.set(cache_key, json_data)
146+
get_valkey_client().set(cache_key, json_data)
149147

150148

151149
def load_binding_meta(instance_id):
152150
from .query import get_binding_file
153151
cache_key = f"helmbroker:binding:{instance_id}"
154-
redis = client.Redis.from_url(REDIS_URL)
155-
json_data = redis.get(cache_key)
152+
valkey = get_valkey_client()
153+
json_data = valkey.get(cache_key)
156154
if not json_data:
157155
file = get_binding_file(instance_id)
158156
with open(file, 'r') as f:
159157
json_data = f.read()
160-
redis.set(cache_key, json_data)
158+
valkey.set(cache_key, json_data)
161159
return json.loads(json_data)
162160

163161

@@ -170,18 +168,17 @@ def save_addons_meta(data):
170168
json_data = json.dumps(data, sort_keys=True, indent=2)
171169
with open(file, "w") as f:
172170
f.write(json_data)
173-
redis = client.Redis.from_url(REDIS_URL)
174-
redis.set(cache_key, json_data)
171+
get_valkey_client().set(cache_key, json_data)
175172

176173

177174
def load_addons_meta():
178175
cache_key = "helmbroker:addons"
179-
redis = client.Redis.from_url(REDIS_URL)
176+
valkey = get_valkey_client()
180177

181-
json_data = redis.get(cache_key)
178+
json_data = valkey.get(cache_key)
182179
if not json_data:
183180
file = os.path.join(ADDONS_PATH, "addons.json")
184181
with open(file, 'r') as f:
185182
json_data = f.read()
186-
redis.set(cache_key, json_data)
183+
valkey.set(cache_key, json_data)
187184
return json.loads(json_data)

0 commit comments

Comments
 (0)