mirror of https://github.com/Mai-with-u/MaiBot.git
feat: 为helm chart兼容WebUI,添加禁止覆盖配置的选项
parent
f558bc191d
commit
95a4e9d8fe
|
|
@ -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)}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }}
|
||||
|
|
@ -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 }}
|
||||
|
|
@ -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 }}
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue