Skip to content

Commit

Permalink
Implement support for taking over library prefix of deprecated compon…
Browse files Browse the repository at this point in the history
…ents

Commodore will verify that either the component who's prefix we're
trying to take over isn't present in the cluster configuration (in this
case the alias is just a regular alias) or that the component is
deprecated, and has nominated us as their replacement component. Library
prefixes of non-deprecated components, or deprecated components which
don't specify a replacement can't be taken over.
  • Loading branch information
simu committed Feb 7, 2023
1 parent 6dc4ae8 commit ff85b41
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions commodore/dependency_mgmt/component_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ def validate_component_library_name(cname: str, lib: Path) -> Path:
return lib


def _check_library_alias_prefixes(libalias: str, cn: str, component_prefixes: set[str]):
for p in component_prefixes - {cn}:
def _check_library_alias_prefixes(
libalias: str,
cn: str,
component_prefixes: set[str],
additional_cname: str,
):
prefixes = component_prefixes - {cn}
if additional_cname:
prefixes = prefixes - {additional_cname}
for p in prefixes:
if libalias.startswith(p):
raise click.ClickException(
f"Invalid alias prefix '{p}' "
Expand All @@ -40,8 +48,27 @@ def _check_library_alias_collisions(cfg: Config, cluster_params: dict[str, Any])
for cn, component in components.items():
cmeta = cluster_params[component.parameters_key].get("_metadata", {})
aliases = cmeta.get("library_aliases", {})
# If component replaces another component, and wants to use the old component's
# library prefix, it should set `_metadata.replaces` to the old component name.
additional_cname = cmeta.get("replaces", "")
if additional_cname and additional_cname in components:
ometa = cluster_params[components[additional_cname].parameters_key].get(
"_metadata", {}
)
odeprecated = ometa.get("deprecated", False)
if not odeprecated:
click.secho(
f" > Ignoring additional library prefix '{additional_cname}' "
+ f"requested by '{cn}', component with requested name is "
+ "also deployed on the cluster.",
fg="yellow",
)
additional_cname = ""

for libalias in aliases.keys():
_check_library_alias_prefixes(libalias, cn, component_prefixes)
_check_library_alias_prefixes(
libalias, cn, component_prefixes, additional_cname
)
collisions.setdefault(libalias, set()).add(cn)

for libalias, cnames in collisions.items():
Expand All @@ -56,7 +83,9 @@ def _check_library_alias_collisions(cfg: Config, cluster_params: dict[str, Any])
def create_component_library_aliases(cfg: Config, cluster_params: dict[str, Any]):
_check_library_alias_collisions(cfg, cluster_params)

for _, component in cfg.get_components().items():
components = cfg.get_components()

for cn, component in components.items():
cmeta = cluster_params[component.parameters_key].get("_metadata", {})
aliases = cmeta.get("library_aliases", {}).items()

Expand Down

0 comments on commit ff85b41

Please sign in to comment.