Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation requirements on helm names #109

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,69 @@ class Artifact:


@dataclass
class NFApplicationConfiguration:
class NFApplicationConfiguration: # pylint: disable=too-many-instance-attributes
name: str
chartName: str
chartVersion: str
releaseName: str
dependsOnProfile: List[str]
registryValuesPaths: List[str]
imagePullSecretsValuesPaths: List[str]
valueMappingsFile: str

def __post_init__(self):
"""Format the fields based on the NFDV validation rules."""
self._format_name()
self._format_release_name()

def _format_name(self):
"""
Format the name field.

The name should start with a alphabetic character, have alphanumeric characters
or '-' in-between and end with alphanumerc character, and be less than 64
characters long. See NfdVersionValidationHelper.cs in pez codebase
"""
# Replace any non (alphanumeric or '-') characters with '-'
self.name = re.sub("[^0-9a-zA-Z-]+", "-", self.name)
sunnycarter marked this conversation as resolved.
Show resolved Hide resolved
# Strip leading or trailing -
self.name = self.name.strip("-")
self.name = self.name[:64]
sunnycarter marked this conversation as resolved.
Show resolved Hide resolved

if not self.name:
raise InvalidTemplateError(
"The name field of the NF application configuration for helm package "
f"{self.chartName} is empty after removing invalid characters. "
"Valid characters are alphanumeric and '-'. Please fix this in the name"
" field for the helm package in your input config file."
)

def _format_release_name(self):
"""
Format release name.

It must consist of lower case alphanumeric characters, '-' or '.', and must
start and end with an alphanumeric character See
AzureArcKubernetesRuleBuilderExtensions.cs and
AzureArcKubernetesNfValidationMessage.cs in pez codebase
"""
self.releaseName = self.releaseName.lower()
# Replace any non (alphanumeric or '-' or '.') characters with '-'
self.releaseName = re.sub("[^0-9a-z-.]+", "-", self.releaseName)
sunnycarter marked this conversation as resolved.
Show resolved Hide resolved
# Strip leading - or .
self.releaseName = self.releaseName.strip("-")
self.releaseName = self.releaseName.strip(".")
if not self.releaseName:
raise InvalidTemplateError(
"The releaseName field of the NF application configuration for helm "
f"chart {self.chartName} is empty after formatting and removing invalid"
"characters. Valid characters are alphanumeric, -.' and '-' and the "
"releaseName must start and end with an alphanumeric character. The "
"value of this field is taken from Chart.yaml within the helm package. "
"Please fix up the helm package. Before removing invalid characters"
f", the releaseName was {self.chartName}."
)


@dataclass
class ImageInfo:
Expand Down Expand Up @@ -378,6 +432,7 @@ def _generate_nf_application_config(
name=helm_package.name,
chartName=name,
chartVersion=version,
releaseName=name,
dependsOnProfile=helm_package.depends_on,
registryValuesPaths=list(registry_values_paths),
imagePullSecretsValuesPaths=list(image_pull_secrets_values_paths),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup
deployParametersMappingRuleProfile: {
applicationEnablement: 'Enabled'
helmMappingRuleProfile: {
releaseNamespace: '{{ configuration.chartName }}'
releaseName: '{{ configuration.chartName }}'
releaseNamespace: '{{ configuration.releaseName }}'
releaseName: '{{ configuration.releaseName }}'
helmPackageVersion: '{{ configuration.chartVersion }}'
values: string(loadJsonContent('configMappings/{{ configuration.valueMappingsFile }}'))
}
Expand Down