Skip to content

Commit

Permalink
feature: Agent 额外配置目录支持 (closed TencentBlueKing#1756) (TencentBlueKin…
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW authored Sep 6, 2023
1 parent bb4e17b commit 98bda8e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
15 changes: 15 additions & 0 deletions apps/backend/agent/solution_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def choose_script_file(cls, host: models.Host, is_execute_on_target: bool) -> st
script_file_name = constants.SCRIPT_FILE_NAME_MAP[host.os_type]
return script_file_name

@staticmethod
def get_gse_extra_config_dir(os_type: str):
if os_type.upper() == constants.OsType.WINDOWS:
return settings.GSE_ENVIRON_WIN_DIR
else:
return settings.GSE_ENVIRON_DIR


class BaseExecutionSolutionMaker(metaclass=abc.ABCMeta):
# 是否直接在目标机器上执行
Expand Down Expand Up @@ -349,11 +356,19 @@ def get_create_pre_dirs_step(self, is_shell_adapter: bool = False) -> ExecutionS
"""
# 目前依赖文件路径相关配置分两类:1-文件名路径,创建上级目录,2-目录路径,暂无需求
filepath_config_names: typing.List[str] = []
filepath_necessary_names: typing.List[str] = []

if self.host.os_type != constants.OsType.WINDOWS:
filepath_config_names.extend(["dataipc"])

if not self.agent_setup_info.is_legacy:
# GSE 1.0 不需要创建额外配置目录
filepath_necessary_names.append(ExecutionSolutionTools.get_gse_extra_config_dir(self.host.os_type))

dirs_to_be_created: typing.Set[str] = {self.dest_dir}
for filepath_necessary_name in filepath_necessary_names:
dirs_to_be_created.add(filepath_necessary_name)

# 获取到相应操作系统
agent_config: typing.Dict[str, typing.Any] = self.host_ap.get_agent_config(self.host.os_type)
for filepath_config_name in filepath_config_names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django.conf import settings

from apps.backend.agent import tools
from apps.backend.agent.solution_maker import ExecutionSolutionTools
from apps.backend.utils.data_renderer import nested_render_data
from apps.node_man import constants, models

Expand Down Expand Up @@ -115,6 +116,7 @@ def __post_init__(self):
]
)
],
extra_config_directory=ExecutionSolutionTools.get_gse_extra_config_dir(self.host.os_type),
),
context_dataclass.AccessConfigContext(
cluster_endpoints=",".join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def structure_common_inputs(self):
inputs["meta"] = {"GSE_VERSION": GseVersion.V2.value}
return inputs

@override_settings(GSE_ENVIRON_WIN_DIR=mock_data_utils.GSE_ENVIRON_WIN_DIR)
def test_batch_solution(self):
host = models.Host.objects.get(bk_host_id=self.obj_factory.bk_host_ids[0])
agent_step_adapter: AgentStepAdapter = AgentStepAdapter(
Expand All @@ -423,6 +424,7 @@ def test_batch_solution(self):
self.assertEqual(
solution_parse_result["cmds"],
[
f"mkdir {mock_data_utils.GSE_ENVIRON_WIN_DIR}",
f"mkdir {installation_tool.dest_dir}",
# f"{installation_tool.dest_dir}curl.exe http://127.0.0.1/download/setup_agent.bat"
# f" -o {installation_tool.dest_dir}setup_agent.bat -sSfg",
Expand Down Expand Up @@ -748,6 +750,7 @@ def structure_common_inputs(self):
inputs["meta"] = {"GSE_VERSION": GseVersion.V2.value}
return inputs

@override_settings(GSE_ENVIRON_DIR=mock_data_utils.GSE_ENVIRON_DIR)
def test_shell_solution(self):
host = models.Host.objects.get(bk_host_id=self.obj_factory.bk_host_ids[0])
agent_step_adapter: AgentStepAdapter = AgentStepAdapter(
Expand All @@ -771,6 +774,7 @@ def test_shell_solution(self):
self.assertEqual(
solution_parse_result["cmds"],
[
f"mkdir -p {mock_data_utils.GSE_ENVIRON_DIR}",
f"mkdir -p {installation_tool.dest_dir}",
f"mkdir -p {self.CUSTOM_DATAIPC_DIR}",
f"curl http://127.0.0.1/download/agent_tools/agent2/setup_agent.sh "
Expand Down
4 changes: 4 additions & 0 deletions apps/mock_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

JOB_TASK_PIPELINE_ID = "1ae89ce9deec319bbd8727a0c4b2ca82"

GSE_ENVIRON_DIR = "/etc/sysconfig/gse/bk_test/user_conf"

GSE_ENVIRON_WIN_DIR = "C:\\Windows\\System32\\config\\gse\\bk_test\\user_conf"


class MockReturnType(EnhanceEnum):

Expand Down
4 changes: 2 additions & 2 deletions docs/solution/how-to-install-agent2.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ config:
gseVersion: V2
bkAppBkGseApiGateway: { { BKAPP_BK_GSE_APIGATEWAY } }
gseEnablePushEnvironFile: true
gseEnvironDir: /etc/sysconfig/gse/{{ ENV }}
gseEnvironWinDir: C:\\Windows\\System32\\config\\gse\\{{ ENV }}
gseEnvironDir: /etc/sysconfig/gse/{{ ENV }}/user_conf
gseEnvironWinDir: C:\\Windows\\System32\\config\\gse\\{{ ENV }}\\user_conf
```
环境变量说明请参考:[bk-nodman 系统配置](https://github.com/TencentBlueKing/bk-nodeman/blob/v2.3.x/support-files/kubernetes/helm/bk-nodeman/README.md#bk-nodeman-%E7%B3%BB%E7%BB%9F%E9%85%8D%E7%BD%AE)
Expand Down
6 changes: 4 additions & 2 deletions env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@
GSE_ENABLE_PUSH_ENVIRON_FILE = get_type_env(key="GSE_ENABLE_PUSH_ENVIRON_FILE", default=False, _type=bool)

# GSE 环境变量目录
GSE_ENVIRON_DIR = get_type_env(key="GSE_ENVIRON_DIR", default="", _type=str)
GSE_ENVIRON_DIR = get_type_env(key="GSE_ENVIRON_DIR", default="/etc/sysconfig/gse/bk/user_conf", _type=str)

# GSE 环境变量目录(Windows)
GSE_ENVIRON_WIN_DIR = get_type_env(key="GSE_ENVIRON_WIN_DIR", default="", _type=str)
GSE_ENVIRON_WIN_DIR = get_type_env(
key="GSE_ENVIRON_WIN_DIR", default="C:\\Windows\\System32\\config\\gse\\bk\\user_conf", _type=str
)

# ===============================================================================
# 可观测
Expand Down
4 changes: 2 additions & 2 deletions support-files/kubernetes/helm/bk-nodeman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ externalRabbitMQ:
| `config.gseVersion` | 蓝鲸管控平台版本,默认为 `V1`,可选:`V1` `V2` | `V1` |
| `config.gseCertPath` | GSE 本地证书路径,渲染时为空默认取 `/data/bk{{ .Values.config.bkAppRunEnv }}/cert` | `""` |
| `config.gseEnablePushEnvironFile` | 是否启用推送 GSE 环境变量文件,如果启用,将在 Agent `安装`/`重装`/`重载配置`/`灰度` 操作成功后,进行如下操作:<br />Windows:推送 `environ.sh` & `environ.bat` 到目标机器的 `GSE_ENVIRON_WIN_DIR` 路径<br />Linux:推送 `environ.sh` 到目标机器的 `GSE_ENVIRON_DIR` 路径 | `false` |
| `config.gseEnvironDir` | GSE 环境变量目录 | `""` |
| `config.gseEnvironWinDir` | GSE 环境变量目录(Windows) | `""` |
| `config.gseEnvironDir` | GSE 环境变量目录 | `/etc/sysconfig/gse/bk/user_conf` |
| `config.gseEnvironWinDir` | GSE 环境变量目录(Windows) | `C:\\Windows\\System32\\config\\gse\\ bk\\user_conf` |
| `config.gseEnableSvrDisCovery` | 蓝鲸管控平台 Agent,AgentXXDir 仅在初次部署有效,后续可以在页面「全局配置」维护。是否启用 GSE 服务探测,默认为 `true` | `true` |
| `config.bkAppGseZkHost` | 蓝鲸管控平台 Agent,zk hosts 信息,host:port,多个 hosts 以 `,` 分隔<br />⚠️ ZK hosts 将作为 Agent 配置,需要保证 Agent 可访问,所以不能使用 k8s service 信息 进行配置<br />如果 zk 通过 k8s 部署,建议通过 NodePort 等方式暴露服务,使用 NodeIP:NodePort 进行配置 | `127.0.0.1:2181` |
| `config.bkAppGseZkAuth` | 蓝鲸管控平台 Agent,ZK 认证信息,用户名:密码 | `bkzk:zkpass` |
Expand Down
4 changes: 2 additions & 2 deletions support-files/kubernetes/helm/bk-nodeman/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ config:
## Linux:推送 `environ.sh` 到目标机器的 `GSE_ENVIRON_DIR` 路径
gseEnablePushEnvironFile: false
## GSE 环境变量目录
gseEnvironDir: ""
gseEnvironDir: "/etc/sysconfig/gse/bk/user_conf"
## GSE 环境变量目录(Windows)
gseEnvironWinDir: ""
gseEnvironWinDir: "C:\\Windows\\System32\\config\\gse\\bk\\user_conf"
## 是否启用 GSE 服务探测,为 `true` 将定期更新默认接入点的 gse svr 信息
gseEnableSvrDisCovery: true
## ZK hosts 信息,host:port,多个 hosts 以 `,` 分隔
Expand Down

0 comments on commit 98bda8e

Please sign in to comment.