Skip to content

Commit

Permalink
feature: 新增安装通道上游配置项,适配更复杂网络场景(close TencentBlueKing#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW authored and zhangzhw8 committed Nov 11, 2021
1 parent 300abd5 commit 21e3fc0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
11 changes: 11 additions & 0 deletions apps/backend/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ def gen_commands(host: models.Host, pipeline_id: str, is_uninstall: bool) -> Ins
]
)

# 通道特殊配置
if host.install_channel_id:
__, upstream_servers = host.install_channel()
agent_download_proxy = upstream_servers.get("agent_download_proxy", True)
if agent_download_proxy:
# 打开agent下载代理选项时传入
run_cmd_params.extend([f"-ADP '{agent_download_proxy}'"])
channel_proxy_address = upstream_servers.get("channel_proxy_address", None)
if channel_proxy_address:
run_cmd_params.extend([f"-CPA '{channel_proxy_address}'"])

run_cmd = " ".join(run_cmd_params)

download_cmd = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ def setUp(self):
install_channel = models.InstallChannel.objects.create(
bk_cloud_id=constants.DEFAULT_CLOUD,
jump_servers=["1.1.1.1"],
upstream_servers={"taskserver": ["127.0.0.1"], "btfileserver": ["127.0.0.1"], "dataserver": ["127.0.0.1"]},
upstream_servers={
"taskserver": ["127.0.0.1"],
"btfileserver": ["127.0.0.1"],
"dataserver": ["127.0.0.1"],
"channel_proxy_address": "http://127.0.0.1:17981",
"agent_download_proxy": True,
},
)
models.Host.objects.filter(bk_host_id=utils.BK_HOST_ID).update(install_channel_id=install_channel.id)
# 创建可用安装通道节点
Expand Down Expand Up @@ -527,6 +533,7 @@ def test_gen_install_channel_agent_command(self):
f" -HPP '17981' -HSN 'setup_agent.sh' -HS 'bash'"
f" -p '/usr/local/gse' -I 1.1.1.1"
f" -o http://1.1.1.1:{settings.BK_NODEMAN_NGINX_DOWNLOAD_PORT}/ "
f" -ADP 'True' -CPA 'http://127.0.0.1:17981'"
)
self.assertEqual(installation_tool.run_cmd, run_cmd)

Expand Down
5 changes: 4 additions & 1 deletion apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,10 @@ class InstallChannel(models.Model):
安装通道,利用 jump_servers 作为跳板登录到目标机器执行脚本,使用 upstream_servers 作为上游来渲染配置,
由于各种特殊网络环境,目前安装通道需手动安装
jump_servers = ["127.0.0.1", "127.0.0.2"]
upstream_servers = {"taskserver": ["127.0.0.1"], "btfileserver": ["127.0.0.1"],"dataserver": ["127.0.0.1"]}
upstream_servers = {
"taskserver": ["127.0.0.1"], "btfileserver": ["127.0.0.1"],"dataserver": ["127.0.0.1"],
"agent_download_proxy": true, "channel_proxy_address": "http://127.0.0.1:17981"
}
"""

name = models.CharField(_("名称"), max_length=45)
Expand Down
3 changes: 3 additions & 0 deletions dev_log/2.1.354/xcwang_202110271604.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
feature:
- "新增安装通道上游配置项,适配更复杂网络场景(close #234)"
45 changes: 32 additions & 13 deletions script_tools/setup_pagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def arg_parser() -> argparse.ArgumentParser:
parser.add_argument("-HPP", "--host-proxy-port", type=int, default=17981, help="Host Proxy Port")
parser.add_argument("-HSN", "--host-script-name", type=str, help="Host Script Name")
parser.add_argument("-HS", "--host-shell", type=str, help="Host Shell")

parser.add_argument("-CPA", "--channel-proxy-address", type=str, help="Channel Proxy Address", default=None)
parser.add_argument("-ADP", "--agent-download-proxy", type=str, help="Agent Download Proxy", default=True)
return parser


Expand Down Expand Up @@ -415,7 +416,14 @@ def report_log(step, text, status="-"):
}
],
}
r = requests.post(f"{args.callback_url}/report_log/", json=data)
if args.channel_proxy_address:
proxy_address = {
"http": args.channel_proxy_address,
"https": args.channel_proxy_address,
}
r = requests.post(f"{args.callback_url}/report_log/", json=data, proxies=proxy_address)
else:
r = requests.post(f"{args.callback_url}/report_log/", json=data)
return r


Expand All @@ -440,7 +448,14 @@ def main() -> None:
if shell and _os not in ["windows"]:
cmd = [
f"rm -f {tmp_dir}{script_name}",
f"curl {args.download_url}/{script_name} -o {tmp_dir}{script_name} -sSf -x {http_proxy_url}",
]
download_cmd = (
f"curl {args.download_url}/{script_name} -o {tmp_dir}{script_name} -sSf "
if args.agent_download_proxy
else f"curl {args.download_url}/{script_name} -o {tmp_dir}{script_name} -sSf -x {http_proxy_url} "
)
cmd.append(download_cmd)
cmd.append(
"nohup {} {dest_dir}{script_name} -T {dest_dir} -i {} -I {} -s {} -c {} -l {} -r {} -p {} -e {} "
"-a {} -k {} -x {} -N PROXY {} -O {} -E {} -A {} -V {} -B {} -S {} -Z {} -K {} 2>&1 &".format(
shell,
Expand All @@ -466,15 +481,19 @@ def main() -> None:
args.tracker_port,
script_name=script_name,
dest_dir=tmp_dir,
),
]
)
)
else:
cmd = [
f"del /q /s /f {tmp_dir}{script_name} {tmp_dir}gsectl.bat",
f"{tmp_dir}curl.exe {args.download_url}/{script_name} -o {tmp_dir}{script_name} "
f"-x http://{args.lan_eth_ip}:{DEFAULT_HTTP_PROXY_SERVER_PORT} -sSf",
f"{tmp_dir}curl.exe {args.download_url}/gsectl.bat -o {tmp_dir}gsectl.bat "
f"-x http://{args.lan_eth_ip}:{DEFAULT_HTTP_PROXY_SERVER_PORT} -sSf",
cmd = [f"del /q /s /f {tmp_dir}{script_name} {tmp_dir}gsectl.bat"]
download_cmd = (
f"{tmp_dir}curl.exe {args.download_url}/{script_name} -o {tmp_dir}{script_name} -sSf "
if args.agent_download_proxy
else f"{tmp_dir}curl.exe {args.download_url}/{script_name}"
f"-o {tmp_dir}{script_name} -sSf -x {http_proxy_url} "
)
cmd.append(download_cmd)

cmd.append(
"{dest_dir}{script_name} -T {dest_dir} -i {} -I {} -s {} -c {} -l {} -r {} -p {} "
'-e "{}" -a "{}" -k "{}" -x {} -N PROXY {} -O {} -E {} -A {} -V {} -B {} -S {} -Z {} -K {}'.format(
cloud_id,
Expand All @@ -499,8 +518,8 @@ def main() -> None:
args.tracker_port,
script_name=script_name,
dest_dir=tmp_dir,
),
]
)
)

_function = {"aix": rcmd_aix, "linux": rcmd, "windows": windows_cmd, "solaris": rcmd}

Expand Down

0 comments on commit 21e3fc0

Please sign in to comment.