From 7e24a8739a4a955707e3e2823ca5e04061647572 Mon Sep 17 00:00:00 2001 From: zhangxinhui02 Date: Fri, 31 Oct 2025 10:57:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8helm=20chart=E7=9A=84=20job-ge?= =?UTF-8?q?n-adapter-cm=E6=9B=B4=E6=96=B0=E5=AE=8C=E6=AF=95configmap?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E8=87=AA=E5=8A=A8=E9=87=8D=E5=90=AFadapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter-cm-generator.py | 30 +++++++++++++++++-- .../job-post-install/rbac-gen-adapter-cm.yaml | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/helm-chart/adapter-cm-generator/adapter-cm-generator.py b/helm-chart/adapter-cm-generator/adapter-cm-generator.py index d2370daf..a1ed293a 100644 --- a/helm-chart/adapter-cm-generator/adapter-cm-generator.py +++ b/helm-chart/adapter-cm-generator/adapter-cm-generator.py @@ -7,9 +7,11 @@ import os import toml import base64 from kubernetes import client, config +from datetime import datetime, timezone config.load_incluster_config() -v1 = client.CoreV1Api() +core_api = client.CoreV1Api() +apps_api = client.AppsV1Api() # 读取部署的关键信息 namespace = os.getenv("NAMESPACE") @@ -33,11 +35,33 @@ cm = client.V1ConfigMap( data={'config.toml': toml.dumps(data)} ) try: - v1.create_namespaced_config_map(namespace, cm) + core_api.create_namespaced_config_map(namespace, cm) print(f"ConfigMap `{cm_name}` created successfully") except client.exceptions.ApiException as e: if e.status == 409: # 已存在,更新 - v1.replace_namespaced_config_map(cm_name, namespace, cm) + core_api.replace_namespaced_config_map(cm_name, namespace, cm) print(f"ConfigMap `{cm_name}` replaced successfully") else: raise + +# 重启adapter的statefulset +now = datetime.now(timezone.utc).isoformat() +body = { + "spec": { + "template": { + "metadata": { + "annotations": { + "kubectl.kubernetes.io/restartedAt": now + } + } + } + } +} +resp = apps_api.patch_namespaced_stateful_set( + name=f'{release_name}-maibot-adapter', + namespace=namespace, + body=body, +) +print(f"StatefulSet `{release_name}-maibot-adapter` restarted successfully") + +print('Job succeed.') diff --git a/helm-chart/templates/job-post-install/rbac-gen-adapter-cm.yaml b/helm-chart/templates/job-post-install/rbac-gen-adapter-cm.yaml index 69fefbef..be299f3f 100644 --- a/helm-chart/templates/job-post-install/rbac-gen-adapter-cm.yaml +++ b/helm-chart/templates/job-post-install/rbac-gen-adapter-cm.yaml @@ -12,7 +12,7 @@ metadata: namespace: {{ .Release.Namespace }} rules: - apiGroups: [""] - resources: ["configmaps"] + resources: ["configmaps", "statefulsets"] verbs: ["get", "list", "create", "update", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1