From 95a4e9d8fe6afdf5980c98bb9a28e79ee7c7a1a1 Mon Sep 17 00:00:00 2001 From: zhangxinhui02 Date: Fri, 21 Nov 2025 03:48:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BAhelm=20chart=E5=85=BC=E5=AE=B9?= =?UTF-8?q?WebUI=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=A6=81=E6=AD=A2=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E9=85=8D=E7=BD=AE=E7=9A=84=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter-cm-generator.py | 2 +- .../core-webui-cm-sync/core-webui-cm-sync.py | 20 ++++++++++--------- helm-chart/templates/adapter/statefulset.yaml | 2 +- .../templates/core/configmap-bot-config.yaml | 12 +++++++++++ ...nfigmap.yaml => configmap-env-config.yaml} | 6 +----- .../core/configmap-model-config.yaml | 12 +++++++++++ helm-chart/templates/core/statefulset.yaml | 18 ++++++++++++----- helm-chart/values.yaml | 7 ++++++- 8 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 helm-chart/templates/core/configmap-bot-config.yaml rename helm-chart/templates/core/{configmap.yaml => configmap-env-config.yaml} (59%) create mode 100644 helm-chart/templates/core/configmap-model-config.yaml diff --git a/helm-chart/adapter-cm-generator/adapter-cm-generator.py b/helm-chart/adapter-cm-generator/adapter-cm-generator.py index e860aff3..95d7b65b 100644 --- a/helm-chart/adapter-cm-generator/adapter-cm-generator.py +++ b/helm-chart/adapter-cm-generator/adapter-cm-generator.py @@ -29,7 +29,7 @@ data['maibot_server']['host'] = f'{release_name}-maibot-core' # 根据release data['maibot_server']['port'] = 8000 # 创建/修改configmap -cm_name = f'{release_name}-maibot-adapter' +cm_name = f'{release_name}-maibot-adapter-config' cm = client.V1ConfigMap( metadata=client.V1ObjectMeta(name=cm_name), data={'config.toml': toml.dumps(data)} diff --git a/helm-chart/core-webui-cm-sync/core-webui-cm-sync.py b/helm-chart/core-webui-cm-sync/core-webui-cm-sync.py index 49037f93..e179d6f6 100644 --- a/helm-chart/core-webui-cm-sync/core-webui-cm-sync.py +++ b/helm-chart/core-webui-cm-sync/core-webui-cm-sync.py @@ -19,22 +19,23 @@ core_api = client.CoreV1Api() with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace", "r") as f: namespace = f.read().strip() release_name = os.getenv("RELEASE_NAME") -configmap_name = f'{release_name}-maibot-core' +model_configmap_name = f'{release_name}-maibot-core-model-config' +bot_configmap_name = f'{release_name}-maibot-core-bot-config' # 过滤列表,只监控指定文件 target_files = { - os.path.abspath("model_config.toml"): "model_config.toml", - os.path.abspath("bot_config.toml"): "bot_config.toml" + os.path.abspath("model_config.toml"): (model_configmap_name, "model_config.toml"), + os.path.abspath("bot_config.toml"): (bot_configmap_name, "bot_config.toml") } -def get_configmap(): +def get_configmap(configmap_name: str): """获取core的ConfigMap内容""" cm = core_api.read_namespaced_config_map(name=configmap_name, namespace=namespace) return cm.data -def set_configmap(configmap_data: dict[str, str]): +def set_configmap(configmap_name: str, configmap_data: dict[str, str]): """设置core的ConfigMap内容""" core_api.patch_namespaced_config_map(configmap_name, namespace, {'data': configmap_data}) @@ -47,11 +48,12 @@ class ConfigObserverHandler(FileSystemEventHandler): f'Start to sync...') with open(event.src_path, "r", encoding="utf-8") as _f: current_data = _f.read() + _path = str(os.path.abspath(event.src_path)) new_cm = { - target_files[os.path.abspath("model_config.toml")]: current_data + target_files[_path][1]: current_data } try: - set_configmap(new_cm) + set_configmap(target_files[_path][0], new_cm) print(f'\tSync done.') except client.exceptions.ApiException as _e: print(f'\tError while setting configmap:\n' @@ -63,8 +65,8 @@ if __name__ == '__main__': # 初始化配置文件 print(f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] Initializing config files...') try: - __initial_model_config = get_configmap()['model_config.toml'] - __initial_bot_config = get_configmap()['bot_config.toml'] + __initial_model_config = get_configmap(model_configmap_name)['model_config.toml'] + __initial_bot_config = get_configmap(bot_configmap_name)['bot_config.toml'] except client.exceptions.ApiException as e: print(f'\tError while getting configmap:\n' f'\t\tStatus Code: {e.status}\n' diff --git a/helm-chart/templates/adapter/statefulset.yaml b/helm-chart/templates/adapter/statefulset.yaml index 262891b4..0d9b76da 100644 --- a/helm-chart/templates/adapter/statefulset.yaml +++ b/helm-chart/templates/adapter/statefulset.yaml @@ -58,5 +58,5 @@ spec: items: - key: config.toml path: config.toml - name: {{ .Release.Name }}-maibot-adapter + name: {{ .Release.Name }}-maibot-adapter-config name: config diff --git a/helm-chart/templates/core/configmap-bot-config.yaml b/helm-chart/templates/core/configmap-bot-config.yaml new file mode 100644 index 00000000..447b3396 --- /dev/null +++ b/helm-chart/templates/core/configmap-bot-config.yaml @@ -0,0 +1,12 @@ +{{- if or .Release.IsInstall .Values.config.enable_config_override }} +# 渲染规则: +# 初次安装,或配置了覆盖规则 +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-maibot-core-bot-config + namespace: {{ .Release.Namespace }} +data: + bot_config.toml: | + {{ .Values.config.core_bot_config | nindent 4 }} +{{- end }} diff --git a/helm-chart/templates/core/configmap.yaml b/helm-chart/templates/core/configmap-env-config.yaml similarity index 59% rename from helm-chart/templates/core/configmap.yaml rename to helm-chart/templates/core/configmap-env-config.yaml index 98dadea8..17b1d627 100644 --- a/helm-chart/templates/core/configmap.yaml +++ b/helm-chart/templates/core/configmap-env-config.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Release.Name }}-maibot-core + name: {{ .Release.Name }}-maibot-core-env-config namespace: {{ .Release.Namespace }} data: .env: | @@ -11,7 +11,3 @@ data: WEBUI_MODE=production WEBUI_HOST=0.0.0.0 WEBUI_PORT=8001 - model_config.toml: | - {{ .Values.config.core_model_config | nindent 4 }} - bot_config.toml: | - {{ .Values.config.core_bot_config | nindent 4 }} diff --git a/helm-chart/templates/core/configmap-model-config.yaml b/helm-chart/templates/core/configmap-model-config.yaml new file mode 100644 index 00000000..97c435ff --- /dev/null +++ b/helm-chart/templates/core/configmap-model-config.yaml @@ -0,0 +1,12 @@ +{{- if or .Release.IsInstall .Values.config.enable_config_override }} +# 渲染规则: +# 初次安装,或配置了覆盖规则 +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-maibot-core-model-config + namespace: {{ .Release.Namespace }} +data: + model_config.toml: | + {{ .Values.config.core_model_config | nindent 4 }} +{{- end }} diff --git a/helm-chart/templates/core/statefulset.yaml b/helm-chart/templates/core/statefulset.yaml index 1127021b..db8cda78 100644 --- a/helm-chart/templates/core/statefulset.yaml +++ b/helm-chart/templates/core/statefulset.yaml @@ -56,16 +56,16 @@ spec: readOnly: true subPath: k8s-init.sh - mountPath: /MaiMBot/.env - name: config + name: env-config readOnly: true subPath: .env {{- if not .Values.core.webui.enabled }} - mountPath: /MaiMBot/config/model_config.toml - name: config + name: model-config readOnly: true subPath: model_config.toml - mountPath: /MaiMBot/config/bot_config.toml - name: config + name: bot-config readOnly: true subPath: bot_config.toml {{- end }} @@ -140,12 +140,20 @@ spec: items: - key: .env path: .env + name: {{ .Release.Name }}-maibot-core-env-config + name: env-config + - configMap: + items: - key: model_config.toml path: model_config.toml + name: {{ .Release.Name }}-maibot-core-model-config + name: model-config + - configMap: + items: - key: bot_config.toml path: bot_config.toml - name: {{ .Release.Name }}-maibot-core - name: config + name: {{ .Release.Name }}-maibot-core-bot-config + name: bot-config {{- if .Values.statistics_dashboard.enabled }} - name: statistics persistentVolumeClaim: diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index 16ba0bc7..c9ac969a 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -208,9 +208,14 @@ sqlite_web: path: / pathType: Prefix -# 麦麦各部分组件的运行配置文件 +# 手动设置麦麦各部分组件的运行配置文件 config: + # 启用WebUI后,配置文件的修改即可在WebUI进行。如果通过WebUI修改了配置,则实际的配置文件将与values中的配置存在差异。 + # 为了避免helm升级麦麦时,下面values中的配置覆盖掉已有的配置文件而导致配置丢失,可以在这里禁止本次部署时的配置覆盖。 + # 注:由于adapter的配置无法通过WebUI修改,因此下面的adapter_config配置仍然会覆盖已有配置文件。 + enable_config_override: true # 要禁止覆盖,修改为false + # adapter的config.toml adapter_config: | [inner]