Skip to content

Commit

Permalink
feat: 安装预设插件锁定版本 (closed TencentBlueKing#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpyoung3 committed Dec 17, 2024
1 parent 08c9c9b commit 76c7da0
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions apps/backend/subscription/steps/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,8 @@ def format2policy_packages_new(
os_cpu__config_templates_map = defaultdict(list)
for template in config_templates:
is_main_template = template["is_main"]
if plugin_version in tags and not is_tag[plugin_version]:
tag_packages_version_set = set(packages.values_list("version", flat=True))
plugin_version_set = tag_packages_version_set | {"*"}
else:
plugin_version_set = {plugin_version, "*"}
tag_packages_version_set = set(packages.values_list("version", flat=True))
plugin_version_set = tag_packages_version_set | {"*"}

max_config_tmpl_ids: typing.List[int] = self.max_ids_by_key(
list(
Expand Down Expand Up @@ -477,21 +474,24 @@ def get_matching_package_obj(self, os_type: str, cpu_arch: str, bk_biz_id: int)
return package

def get_matching_config_tmpl_objs(
self, os_type: str, cpu_arch: str, package: models.Packages, bk_biz_id: int, config: Dict
self, os_type: str, cpu_arch: str, package: models.Packages = None, bk_biz_id: int = None, config: Dict = None
) -> List[models.PluginConfigTemplate]:
# 如果当前业务设定了业务最大版本,重新从数据库中获取
if str(bk_biz_id) in self.plugin_version_config():
config_tmpl = (
models.PluginConfigTemplate.objects.filter(
name=config["config_templates"][0]["name"],
plugin_name=package.project,
plugin_version=package.version,
is_main=Value(1 if config["config_templates"][0]["is_main"] else 0),
plugin_config_templates = []
for config_template in config["config_templates"]:
config_tmpl = (
models.PluginConfigTemplate.objects.filter(
name=config_template["name"],
plugin_name=package.project,
plugin_version=package.version,
is_main=Value(1 if config_template["is_main"] else 0),
)
.order_by("-id")
.first()
)
.order_by("-id")
.first()
)
return config_tmpl
plugin_config_templates.append(config_tmpl)
return plugin_config_templates
return self.config_tmpl_obj_gby_os_key.get(self.get_os_key(os_type, cpu_arch), [])

def get_biz_package(self, plugin_name: str, os_type: str, cpu_arch: str, biz_version: str):
Expand Down Expand Up @@ -533,7 +533,7 @@ def get_biz_version(package: models.Packages, bk_biz_id: int):
)
return biz_version

def get_packages(self, plugin_name: str, plugin_version: str, biz_version: str = None):
def get_packages(self, plugin_name: str, plugin_version: str):
"""如果不存在某个版本,则取最大id的版本"""
all_packages = models.Packages.objects.filter(project=plugin_name).values("id", "os", "cpu_arch", "version")
version_packages = {pkg["id"]: pkg for pkg in all_packages if pkg["version"] == plugin_version}
Expand Down

0 comments on commit 76c7da0

Please sign in to comment.