diff --git a/src/dashboard/apigateway/apigateway/conf/default.py b/src/dashboard/apigateway/apigateway/conf/default.py index 6c944361f..d195d923f 100644 --- a/src/dashboard/apigateway/apigateway/conf/default.py +++ b/src/dashboard/apigateway/apigateway/conf/default.py @@ -560,8 +560,8 @@ } # 微网关 chart 信息 -BCS_MICRO_GATEWAY_CHART_NAME = "bk-micro-gateway-operator" -BCS_MICRO_GATEWAY_CHART_VERSION = "0.0.1" +BCS_MICRO_GATEWAY_CHART_NAME = "bk-micro-gateway" +BCS_MICRO_GATEWAY_CHART_VERSION = "v1.0.0-alpha.2" BCS_MICRO_GATEWAY_IMAGE_REGISTRY = "" BCS_MICRO_GATEWAY_SENTRY_DSN = env.str("BCS_MICRO_GATEWAY_SENTRY_DSN", "") @@ -650,7 +650,7 @@ } APISIX_CONFIG = { - "plugin_attr": { + "pluginAttrs": { "log-rotate": { # 每间隔多长时间切分一次日志,秒为单位 "interval": 60 * 60, diff --git a/src/dashboard/apigateway/apigateway/controller/helm/values_generator.py b/src/dashboard/apigateway/apigateway/controller/helm/values_generator.py index 033c3cc6e..775d1e3c2 100644 --- a/src/dashboard/apigateway/apigateway/controller/helm/values_generator.py +++ b/src/dashboard/apigateway/apigateway/controller/helm/values_generator.py @@ -22,7 +22,7 @@ from django.conf import settings from apigateway.controller.crds.config_controller import create_config_controller -from apigateway.core.micro_gateway_config import MicroGatewayHTTPInfo, MicroGatewayJWTAuth +from apigateway.core.micro_gateway_config import MicroGatewayHTTPInfo from apigateway.core.models import MicroGateway, Stage @@ -37,7 +37,9 @@ class MicroGatewayValuesGenerator: def __attrs_post_init__(self): self.micro_gateway_config = self.micro_gateway.config self.stage = self.micro_gateway.stage_set.first() - self.http_info = MicroGatewayHTTPInfo.from_micro_gateway_config(self.micro_gateway_config) + self.http_info = MicroGatewayHTTPInfo.from_micro_gateway_config( + self.micro_gateway_config + ) # NOTE 配置一个url, 用于状态上报 self.values = self.micro_gateway_config.get("values", {}) def _merge_dict(self, to: Dict[str, Any], from_: Dict[str, Any]): @@ -62,52 +64,56 @@ def generate_values(self) -> Dict[str, Any]: values = { "global": { "imageRegistry": settings.BCS_MICRO_GATEWAY_IMAGE_REGISTRY, - "serviceMonitor": { - "enabled": True, - }, + }, + "serviceMonitor": { + "enabled": True, }, "replicaCount": 2, - "sentry": { - "enabled": settings.BCS_MICRO_GATEWAY_SENTRY_DSN != "", - "dsn": settings.BCS_MICRO_GATEWAY_SENTRY_DSN, + "operator": { + "sentryDsn": settings.BCS_MICRO_GATEWAY_SENTRY_DSN, }, "service": { "type": "NodePort", }, - "gomicro-discovery-operator": { - "enabled": False, - }, - "apisixConfig": self._get_apisix_config(), + "apisix": self._get_apisix_config(), } self._merge_dict(values, deepcopy(self.values)) - jwt_auth_info = MicroGatewayJWTAuth.from_micro_gateway_config(self.micro_gateway.config) - self._merge_dict( - values, - { - "gatewayConfigEnabled": True, - "gatewayConfig": { - "instance_id": self.micro_gateway.instance_id, - "controller": { - "endpoints": [settings.BK_API_URL_TMPL.format(api_name="bk-apigateway")], - "base_path": settings.EDGE_CONTROLLER_API_BASE_PATH, - "jwt_auth": { - "secret": jwt_auth_info.secret_key, - }, - }, - }, - "gatewayStageEnabled": False, - }, - ) + # TODO 暂时不支持配置, 等状态上报的方案确定 + # jwt_auth_info = MicroGatewayJWTAuth.from_micro_gateway_config(self.micro_gateway.config) + # self._merge_dict( + # values, + # { + # "gatewayConfigEnabled": True, + # "gatewayConfig": { + # "instance_id": self.micro_gateway.instance_id, + # "controller": { + # "endpoints": [settings.BK_API_URL_TMPL.format(api_name="bk-apigateway")], + # "base_path": settings.EDGE_CONTROLLER_API_BASE_PATH, + # "jwt_auth": { + # "secret": jwt_auth_info.secret_key, + # }, + # }, + # }, + # "gatewayStageEnabled": False, + # }, + # ) return values def _get_apisix_config(self) -> Dict[str, Any]: controller = create_config_controller(self.micro_gateway) config = { - "bk_gateway": { - "instance_id": self.micro_gateway.instance_id, - "controller": controller.dict(), + # TODO 后续需要支持bk_gateway的全套配置 + # "bk_gateway": { + # "instance_id": self.micro_gateway.instance_id, + # "controller": controller.dict(), + # } + "bkGateway": { + "instance": { + "id": self.micro_gateway.instance_id, + "secret": controller.jwt_auth.secret_key, + } } } diff --git a/src/dashboard/apigateway/apigateway/tests/controller/helm/test_values_generator.py b/src/dashboard/apigateway/apigateway/tests/controller/helm/test_values_generator.py index 979ce1531..4d5cee7a1 100644 --- a/src/dashboard/apigateway/apigateway/tests/controller/helm/test_values_generator.py +++ b/src/dashboard/apigateway/apigateway/tests/controller/helm/test_values_generator.py @@ -46,7 +46,7 @@ def setup_settings(self, settings, faker): def test_generate_values(self, mocker, micro_gateway, settings): settings.APISIX_CONFIG = { - "plugin_attr": { + "pluginAttrs": { "log-rotate": { # 每间隔多长时间切分一次日志,秒为单位 "interval": 60 * 60, @@ -67,35 +67,19 @@ def test_generate_values(self, mocker, micro_gateway, settings): assert values == { "global": { "imageRegistry": settings.BCS_MICRO_GATEWAY_IMAGE_REGISTRY, - "serviceMonitor": { - "enabled": True, - }, }, - "sentry": { - "enabled": settings.BCS_MICRO_GATEWAY_SENTRY_DSN != "", - "dsn": settings.BCS_MICRO_GATEWAY_SENTRY_DSN, + "serviceMonitor": { + "enabled": True, + }, + "operator": { + "sentryDsn": settings.BCS_MICRO_GATEWAY_SENTRY_DSN, }, "replicaCount": 2, - "gatewayStageEnabled": False, "service": { "type": "NodePort", }, - "gatewayConfigEnabled": True, - "gatewayConfig": { - "instance_id": micro_gateway.instance_id, - "controller": { - "endpoints": [settings.BK_API_URL_TMPL.format(api_name="bk-apigateway")], - "base_path": settings.EDGE_CONTROLLER_API_BASE_PATH, - "jwt_auth": { - "secret": "jwt_secret_key", - }, - }, - }, - "gomicro-discovery-operator": { - "enabled": False, - }, - "apisixConfig": { - "plugin_attr": { + "apisix": { + "pluginAttrs": { "log-rotate": { "interval": 60 * 60, "max_kept": 24 * 7, @@ -106,12 +90,10 @@ def test_generate_values(self, mocker, micro_gateway, settings): }, }, }, - "bk_gateway": { - "instance_id": micro_gateway.instance_id, - "controller": { - "endpoints": [settings.BK_API_URL_TMPL.format(api_name="bk-apigateway")], - "base_path": settings.EDGE_CONTROLLER_API_BASE_PATH, - "jwt_auth": {"secret": "jwt_secret_key"}, + "bkGateway": { + "instance": { + "id": micro_gateway.instance_id, + "secret": "jwt_secret_key", }, }, }, @@ -123,9 +105,10 @@ def test_generate_values_with_extra_config(self, micro_gateway): "values": { "extraEnvVarsSecret": "env-vars-secret", "replicaCount": 1, - "gatewayConfigEnabled": True, - "gatewayConfig": { - "instance_id": "not-allowed", + "bkGateway": { + "instance": { + "id": "not-allowed", + } }, }, } @@ -135,4 +118,4 @@ def test_generate_values_with_extra_config(self, micro_gateway): assert values["replicaCount"] == 1 assert values["extraEnvVarsSecret"] == "env-vars-secret" - assert values["gatewayConfig"]["instance_id"] == micro_gateway.instance_id + assert values["bkGateway"]["instance"]["id"] == micro_gateway.instance_id