Skip to content

Commit

Permalink
feature: PaaS 容器部署适配 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Sep 16, 2021
1 parent 8fa56f5 commit 90b6736
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 97 deletions.
113 changes: 113 additions & 0 deletions app_desc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
spec_version: 2
app_version: "{{APP_VERSION}}"
app:
region: default
bk_app_code: "bk_nodeman"
bk_app_name: "节点管理"
market:
category: 运维工具
introduction: 通过节点管理,可以对蓝鲸体系中的gse agent进行管理,包括状态查询、版本更新、配置管理、健康检查、进程管理等。
display_options:
width: 1300
height: 720
is_win_maximize: True
open_mode: "new_tab"
modules:
default:
is_default: True
source_dir: src
language: Python
services:
- name: mysql
- name: bkrepo
env_variables:
- key: BKAPP_IS_V3_CONTAINER
value: "True"
description: 是否运行在V3容器版本
- key: PIP_VERSION
value: "20.2.3"
description: 固化pip版本

svc_discovery:
bk_saas:
- bk_app_code: "bk_iam"
- bk_app_code: "bk_nodeman"
module_name: "backend"
- bk_app_code: "bk_nodeman"
module_name: "default"
processes:
web:
command: gunicorn wsgi -w 4 -b :5000 --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
plan: 4C2G5R
replicas: 5

backend:
is_default: False
source_dir: src
language: Python
services:
- name: rabbitmq
- name: redis
- name: bkrepo
shared_from: default
- name: mysql
shared_from: default
env_variables:
- key: BKAPP_IS_V3_CONTAINER
value: "True"
description: 是否运行在V3容器版本
- key: REDIS_MODE
value: "standalone"
description: 后台配置的Redis模式
- key: BACKEND_CONFIG
value: "True"
description: 是否启用后台配置,用于同一份代码区分SaaS和后台的差异化配置
- key: PIP_VERSION
value: "20.2.3"
description: 固化pip版本
- key: BKAPP_IS_PAAS_DEPLOY
value: "True"
description: 是否基于PaaS部署

svc_discovery:
bk_saas:
- bk_app_code: "bk_iam"
- bk_app_code: "bk_nodeman"
module_name: "backend"
- bk_app_code: "bk_nodeman"
module_name: "default"


processes:
backend-web:
command: gunicorn --timeout 300 -w 4 -b :5000 -k gevent wsgi:application --access-logfile - --error-logfile - --access-logformat '[%(h)s] %({request_id}i)s %(u)s %(t)s "%(r)s" %(s)s %(D)s %(b)s "%(f)s" "%(a)s"'
plan: 4C2G5R
replicas: 5
celery-beat:
command: celery -A apps.backend beat -l info
plan: 4C2G5R
replicas: 1
worker-d:
command: celery -A apps.backend worker -Q default --autoscale=8,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-b:
command: celery -A apps.backend worker -Q backend --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-b-a:
command: celery -A apps.backend worker -Q backend_additional_task --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p:
command: celery -A apps.backend worker -Q pipeline,pipeline_priority -n pipeline_worker@%h --maxtasksperchild=50 --autoscale=16,2 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p-s:
command: celery -A apps.backend worker -Q service_schedule,service_schedule_priority -n schedule_worker@%h --maxtasksperchild=50 -c 50 -P eventlet -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
worker-p-a:
command: celery -A apps.backend worker -Q pipeline_additional_task,pipeline_additional_task_priority -n common_worker@%h -l info --autoscale=16,2 --maxtasksperchild=50 -O fair --time-limit=1800
plan: 4C2G5R
replicas: 5
4 changes: 2 additions & 2 deletions apps/node_man/handlers/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def subscription_details(self, subscription_id):
"task_actions": task.actions,
"is_auto_trigger": task.is_auto_trigger,
"create_time": task.create_time,
"details": f"{settings.BK_NODEMAN_URL}/api/debug/fetch_task_details?"
"details": f"{settings.BK_NODEMAN_HOST}/api/debug/fetch_task_details?"
f"subscription_id={subscription_id}&task_id={task.id}",
}

Expand Down Expand Up @@ -171,7 +171,7 @@ def fetch_subscriptions_by_host(self, bk_host_id):
result.append(
{
"subscription_id": record.subscription_id,
"subscription_detail": f"{settings.BK_NODEMAN_URL}/api/debug/fetch_subscription_details?"
"subscription_detail": f"{settings.BK_NODEMAN_HOST}/api/debug/fetch_subscription_details?"
f"subscription_id={record.subscription_id}",
}
)
Expand Down
4 changes: 2 additions & 2 deletions apps/node_man/handlers/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IamHandler(APIModel):
]

if settings.USE_IAM:
_iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_IAM_ESB_PAAS_HOST)
_iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)
else:
_iam = object

Expand Down Expand Up @@ -322,7 +322,7 @@ def fetch_redirect_url(self, params, username):
apply_info["related_resource_types"][0]["instances"] = instances
data["actions"].append(apply_info)
ok, message, result = IamHandler._iam._client.get_apply_url(bk_token="", bk_username=username, data=data)
return result or settings.BK_IAM_URL
return result or settings.BK_IAM_SAAS_HOST

@staticmethod
def return_resource_instance_creator(resource_id, instance_id, instance_name, creator):
Expand Down
2 changes: 1 addition & 1 deletion apps/node_man/iam_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class IamRegister(object):
]

def __init__(self):
self._iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_PAAS_INNER_HOST)
self._iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)

def register_system(self):
# ***需要将placeholder改为内网访问地址***
Expand Down
8 changes: 4 additions & 4 deletions apps/node_man/tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def test_subscription_details(self):
self.assertEqual(result[0]["task_id"], self.subscription_task_obj.id)
self.assertEqual(
result[0]["details"],
f"{settings.BK_NODEMAN_URL}/api/debug/fetch_task_details?"
f"subscription_id={self.subscription_obj.id}&task_id={self.subscription_task_obj.id}"
f"{settings.BK_NODEMAN_HOST}/api/debug/fetch_task_details?"
f"subscription_id={self.subscription_obj.id}&task_id={self.subscription_task_obj.id}",
)

def test_fetch_hosts_by_subscription(self):
Expand All @@ -99,8 +99,8 @@ def test_fetch_subscriptions_by_host(self):
[
{
"subscription_id": self.subscription_obj.id,
"subscription_detail": f"{settings.BK_NODEMAN_URL}/api/debug/fetch_subscription_details?"
f"subscription_id={self.subscription_obj.id}",
"subscription_detail": f"{settings.BK_NODEMAN_HOST}/api/debug/fetch_subscription_details?"
f"subscription_id={self.subscription_obj.id}",
}
],
)
4 changes: 2 additions & 2 deletions apps/node_man/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
cmdb,
debug,
host,
install_channel,
job,
meta,
permission,
plugin,
policy,
tjj,
install_channel,
)
from apps.node_man.views.healthz import HealthzViewSet
from apps.node_man.views.host_v2 import HostV2ViewSet
from apps.node_man.views.plugin import GsePluginViewSet
from apps.node_man.views.plugin_v2 import PluginV2ViewSet

iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_HOST, settings.BK_PAAS_INNER_HOST)
iam = IAM(settings.APP_CODE, settings.SECRET_KEY, settings.BK_IAM_INNER_HOST, settings.BK_PAAS_INNER_HOST)

router = routers.DefaultRouter(trailing_slash=True)

Expand Down
2 changes: 1 addition & 1 deletion blueking/component/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

APP_CODE = settings.APP_ID
SECRET_KEY = settings.APP_TOKEN
COMPONENT_SYSTEM_HOST = getattr(settings, "BK_PAAS_INNER_HOST", settings.BK_PAAS_HOST)
COMPONENT_SYSTEM_HOST = getattr(settings, "BK_COMPONENT_API_URL", settings.BK_PAAS_INNER_HOST)
DEFAULT_BK_API_VER = getattr(settings, "DEFAULT_BK_API_VER", "v2")
except Exception:
APP_CODE = ""
Expand Down
3 changes: 1 addition & 2 deletions common/api/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

from django.conf import settings

BK_PAAS_HOST = settings.BK_PAAS_INNER_HOST or settings.BK_PAAS_HOST or ""
ESB_PREFIX_V2 = os.getenv("ESB_PREFIX_V2") or "/api/c/compapi/v2/"


def gen_api_root(api_gw_env_key: str, suffix: str) -> str:
"""生成API根路径,首先从环境变量获取,若环境变量没有,则按默认规则拼接"""
return os.getenv(api_gw_env_key) or f"{BK_PAAS_HOST}/{ESB_PREFIX_V2}/{suffix}/"
return os.getenv(api_gw_env_key) or f"{settings.BK_COMPONENT_API_URL}/{ESB_PREFIX_V2}/{suffix}/"


# 蓝鲸平台模块域名
Expand Down
8 changes: 8 additions & 0 deletions common/api/modules/bk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class _BKNodeApi(object):

def __init__(self):

self.metric_list = DataAPI(
method="POST",
url=BK_NODE_APIGATEWAY_ROOT + "backend/package/upload_cos/",
module=self.MODULE,
description=u"上传插件",
before_request=add_esb_info_before_request,
)

self.create_subscription = DataAPI(
method="POST",
url=BK_NODE_APIGATEWAY_ROOT + "backend/api/subscription/create/",
Expand Down
3 changes: 3 additions & 0 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def get_env_or_raise(key):

# SaaS运行版本,如非必要请勿修改
RUN_VER = os.environ.get("BKPAAS_ENGINE_REGION", "open")
# 兼容 V3 取值差异
if RUN_VER == "default":
RUN_VER = "open"

APP_ID = APP_CODE = os.environ.get("APP_ID", "bk_nodeman")
APP_TOKEN = SECRET_KEY = os.environ.get("APP_TOKEN", "")
Expand Down
Loading

0 comments on commit 90b6736

Please sign in to comment.