Skip to content

Commit

Permalink
feat(backend): dbm注册到通知中心 #3645
Browse files Browse the repository at this point in the history
  • Loading branch information
ygcyao authored and zhangzhw8 committed Mar 25, 2024
1 parent cebce1c commit 68cfb1a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dbm-ui/backend/dbm_init/management/commands/services_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@ def add_arguments(self, parser):
parser.add_argument(
"srv_type",
type=str,
choices=["all", "itsm", "bklog", "bkcc", "bkmonitor_alarm", "bkmonitor_channel", "bkjob", "ssl"],
choices=[
"all",
"itsm",
"bklog",
"bkcc",
"bkmonitor_alarm",
"bkmonitor_channel",
"bkjob",
"ssl",
"register_application",
],
help="all: initialize all services, "
"itsm: initialize itsm service, "
"bklog: initialize bk-log services"
"bkcc: initialize bk-cc services"
"bkjob: initialize bk-job services"
"ssl: create and upload ssl files to bkrepo"
"bkmonitor_channel: initialize bk-monitor report services"
"bkmonitor_alarm: initialize bk-bkmonitor alarm services",
"bkmonitor_alarm: initialize bk-bkmonitor alarm services"
"register_application: register applications into bk_notice",
)

def handle(self, *args, **options):
Expand All @@ -55,3 +66,6 @@ def handle(self, *args, **options):

if srv_type == "all" or srv_type == "ssl":
Services.auto_create_ssl_service()

if srv_type == "all" or srv_type == "register_application":
Services.auto_register_application()
15 changes: 15 additions & 0 deletions dbm-ui/backend/dbm_init/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import subprocess

from bk_notice_sdk.views import api_call
from django.conf import settings
from django.utils import timezone

Expand Down Expand Up @@ -482,3 +483,17 @@ def auto_create_bkjob_service(cls):
access_params={"base_url": settings.BKREPO_ENDPOINT_URL},
)
logger.info("auto_create_bkjob_service success")

@classmethod
def auto_register_application(cls):
"""初始化注册 dbm 到通知中心"""
try:
response = api_call(
api_method="register_application", success_message="注册平台成功", error_message="注册平台异常", success_code=201
)
if response.get("result") is True:
logger.info("dbm成功注册平台到通知中心")
else:
logger.info("dbm注册平台失败:" + response["message"])
except Exception as e:
logger.info("dbm注册平台异常: %s" % str(e))
4 changes: 4 additions & 0 deletions helm-charts/bk-dbm/charts/dbm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ environment variables
{{- printf "%s-%s-%d" (include "dbm.fullname" .) "db-ssl-init" .Release.Revision }}
{{- end }}

{{- define "dbm.bknoticeInitJobName" -}}
{{- printf "%s-%s-%d" (include "dbm.fullname" .) "db-notice-init" .Release.Revision }}
{{- end }}

{{- define "dbm.mediumInitJobName" -}}
{{- printf "%s-%s-%d" (include "dbm.fullname" .) "db-medium-init" .Release.Revision }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.serviceInit.bknoticeEnabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "dbm.bknoticeInitJobName" . }}
labels:
{{- include "dbm.labels" . | nindent 4 }}
spec:
template:
metadata:
labels:
{{- include "dbm.labels" . | nindent 8 }}
spec:
{{- with .Values.global.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "dbm.serviceAccountName" . }}
restartPolicy: Never
containers:
- name: dbm-bknotice-init
image: "{{ .Values.global.imageRegistry | default .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -c
args:
- "python manage.py services_init register_application"
{{- include "dbm.container_env" . | nindent 10 }}
resources:
{{- toYaml .Values.initJob.resources | nindent 12 }}
{{- include "dbm.initContainersWaitForMigrate" . | nindent 6 }}
{{- end }}
1 change: 1 addition & 0 deletions helm-charts/bk-dbm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dbm:
mediumEnabled: true
bkmonitorEnabled: true
sslEnabled: true
bknoticeEnabled: true

image:
registry: "mirrors.tencent.com"
Expand Down

0 comments on commit 68cfb1a

Please sign in to comment.