Skip to content

Commit

Permalink
Pre release lower case acr (#113)
Browse files Browse the repository at this point in the history
* Lower case acr names (#112)

* Lower case ACR names and fix interactive mode for lists

* lint

* remove duplicate else branch

* history
  • Loading branch information
sunnycarter authored Oct 9, 2023
1 parent 141dec2 commit ede9d73
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ upcoming
* Fix CNF image import from cross-subscription ACR
* Fix unexpected bracket symbol added to list deployParameters during list parsing
* Format helm names according to RP validation rules
* Always force ACR names to be lower-case
* Fix interactive mode for lists of deployParameters

0.2.0
++++++
Expand Down
13 changes: 13 additions & 0 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ class CNFImageConfig:
source_registry_namespace: str = ""
source_local_docker_image: str = ""

def __post_init__(self):
"""
Ensure that all config is lower case.
ACR names can be uppercase but the login server is always lower case and docker
and az acr import commands require lower case. Might as well do the namespace
and docker image too although much less likely that the user has accidentally
pasted these with upper case.
"""
self.source_registry = self.source_registry.lower()
self.source_registry_namespace = self.source_registry_namespace.lower()
self.source_local_docker_image = self.source_local_docker_image.lower()

@classmethod
def helptext(cls) -> "CNFImageConfig":
"""
Expand Down
32 changes: 13 additions & 19 deletions src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,24 +731,11 @@ def _replace_values_with_deploy_params(
"""
logger.debug("Replacing values with deploy parameters")
final_values_mapping_dict: Dict[Any, Any] = {}
for k, v in values_yaml_dict.items():
for k, v in values_yaml_dict.items(): # pylint: disable=too-many-nested-blocks
# if value is a string and contains deployParameters.
logger.debug("Processing key %s", k)
param_name = k if param_prefix is None else f"{param_prefix}_{k}"
if isinstance(v, (str, int, bool)):
# Replace the parameter with {deploymentParameter.keyname}
if self.interactive:
# Interactive mode. Prompt user to include or exclude parameters
# This requires the enter key after the y/n input which isn't ideal
if not input_ack("y", f"Expose parameter {param_name}? y/n "):
logger.debug("Excluding parameter %s", param_name)
final_values_mapping_dict.update({k: v})
continue
replacement_value = f"{{deployParameters.{param_name}}}"

# add the schema for k (from the big schema) to the (smaller) schema
final_values_mapping_dict.update({k: replacement_value})
elif isinstance(v, dict):
if isinstance(v, dict):
final_values_mapping_dict[k] = self._replace_values_with_deploy_params(
v, param_name
)
Expand All @@ -764,18 +751,25 @@ def _replace_values_with_deploy_params(
final_values_mapping_dict[k].append(
self._replace_values_with_deploy_params(item, param_name)
)
elif isinstance(item, (str, int, bool)) or not v:
elif isinstance(item, (str, int, bool)) or not item:
if self.interactive:
if not input_ack(
"y", f"Expose parameter {param_name}? y/n "
):
logger.debug("Excluding parameter %s", param_name)
final_values_mapping_dict[k].append(item)
continue
replacement_value = f"{{deployParameters.{param_name}}}"
final_values_mapping_dict[k].append(replacement_value)
else:
raise ValueError(
f"Found an unexpected type {type(item)} of key {k} in "
"values.yaml, cannot generate values mapping file."
)
elif not v:
# V is blank so we don't know what type it is. Assuming it is an
# empty string (but do this after checking for dict and list)
elif isinstance(v, (str, int, bool)) or not v:
# Replace the parameter with {deploymentParameter.keyname}
# If v is blank we don't know what type it is. Assuming it is an
# empty string (but do this after checking for dict and list)
if self.interactive:
# Interactive mode. Prompt user to include or exclude parameters
# This requires the enter key after the y/n input which isn't ideal
Expand Down

0 comments on commit ede9d73

Please sign in to comment.