Skip to content

Commit

Permalink
Add Webhook (#159)
Browse files Browse the repository at this point in the history
* initial attempt at adding roleOverride

* add comma

* removed comma as breaks single nf application

* remove prints

* fixed linting + updated history

* fixed bug in nfd processor for vnfs; updated nsd tests

* fixed lives tests

* markups

* markups2

---------

Co-authored-by: Jordan <jordan.layton@metaswitch.com>
  • Loading branch information
jordlay and Jordan authored Apr 8, 2024
1 parent 78a7aff commit b7d6cbf
Show file tree
Hide file tree
Showing 7 changed files with 655 additions and 666 deletions.
3 changes: 2 additions & 1 deletion src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History

2.0.0b1
++++++++
* Added: mutating webhook for injectArtifactStoreDetails
* Added: Users can specify multiple image sources from all types of registries (not just ACRs). General improvements in how CNF image sources are handled.
* Fixed: Namespace appeared twice in the `artifacts.json` file, leading to errors in the publish step of the CLI.
* Changed configurationType for NF Resources from Secret to Open
Expand All @@ -23,7 +24,7 @@ Release History
* No changes, building wheel from correct branch
* Fixed: customLocation missing from Nexus
* Fixed: helm charts not uploading correctly
* Added Nexus support
* Added: Nexus support
* Add `publisher` command group for management of publisher resources.
* Changed the name of the `path_to_mappings` parameter in the CNF input file to `default_values`
* Added a `helm template` validation step to the `az aosm nfd build` command for the `cnf` definition type
Expand Down
38 changes: 29 additions & 9 deletions src/aosm/azext_aosm/build_processors/nfd_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
NFDResourceElementTemplate, NSDArtifactProfile,
ReferencedResource, TemplateType, ContainerizedNetworkFunctionDefinitionVersion,
VirtualNetworkFunctionDefinitionVersion)
from azext_aosm.common.constants import NSD_OUTPUT_FOLDER_FILENAME, NSD_NF_TEMPLATE_FILENAME, NSD_TEMPLATE_FOLDER_NAME
from azext_aosm.common.constants import (
NSD_OUTPUT_FOLDER_FILENAME, NSD_NF_TEMPLATE_FILENAME,
NSD_TEMPLATE_FOLDER_NAME, VNF_TYPE, CNF_TYPE)
from azext_aosm.common.utils import render_bicep_contents_from_j2, get_template_path
logger = get_logger(__name__)

Expand Down Expand Up @@ -80,11 +82,13 @@ def get_artifact_details(

# This horrendous if statement is required because:
# - the 'properties' and 'network_function_template' attributes are optional
# - the isinstance check is because the base NetworkFunctionDefinitionVersionPropertiesFormat class
# - the isinstance check is because the base
# NetworkFunctionDefinitionVersionPropertiesFormat class
# doesn't define the network_function_template attribute, even though both subclasses do.
# Not switching to EAFP style because mypy doesn't account for `except AttributeError` (for good reason).
# Similar test required in the NFD input, but we can't deduplicate the code because mypy doesn't
# propagate type narrowing from isinstance().
# Not switching to EAFP style because mypy doesn't
# account for `except AttributeError` (for good reason).
# Similar test required in the NFD input, but we can't deduplicate the code because mypy
# doesn't propagate type narrowing from isinstance().
if (
self.input_artifact.network_function_definition.properties
and isinstance(
Expand All @@ -96,10 +100,26 @@ def get_artifact_details(
)
and self.input_artifact.network_function_definition.properties.network_function_template
):
params = {
"nfvi_type":
self.input_artifact.network_function_definition.properties.network_function_template.nfvi_type
}
# Split for line-too-long linting errors
nf_type = self.input_artifact.network_function_definition.properties.network_function_type
nf_templates = self.input_artifact.network_function_definition.properties.network_function_template

if nf_type == CNF_TYPE:
nf_application_names = [nf_app.name for nf_app in nf_templates.network_function_applications]
params = {
"nfvi_type":
nf_templates.nfvi_type,
"is_cnf": True,
"nf_application_names": nf_application_names
}
elif nf_type == VNF_TYPE:
params = {
"nfvi_type":
nf_templates.nfvi_type,
"is_cnf": False
}
else:
raise ResourceNotFoundError(f"The NFDV provided has invalid network function type: {nf_type}")
else:
raise ResourceNotFoundError("The NFDV provided has no nfvi type.")
bicep_contents = render_bicep_contents_from_j2(template_path, params)
Expand Down
3 changes: 3 additions & 0 deletions src/aosm/azext_aosm/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ManifestsExist(str, Enum):
SOME = "some"


CNF_TYPE = "ContainerizedNetworkFunction"
VNF_TYPE = "VirtualNetworkFunction"

# Names of files used in the repo
# TODO: remove unused constants
BASE_FOLDER_NAME = "base"
Expand Down
7 changes: 7 additions & 0 deletions src/aosm/azext_aosm/common/templates/nsd/nf_template.bicep.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@ resource nfResource 'Microsoft.HybridNetwork/networkFunctions@2023-09-01' = [for
allowSoftwareUpdate: true
configurationType: 'Open'
deploymentValues: string(values)
{%- if is_cnf %}
roleOverrideValues: [
{%- for nf_app_name in nf_application_names %}
'{"name":"{{nf_app_name}}","deployParametersMappingRuleProfile":{"helmMappingRuleProfile":{"options":{"installOptions":{"injectArtifactStoreDetails":"true"},"upgradeOptions":{"injectArtifactStoreDetails":"true"}}}}}'
{%- endfor %}
]
{%- endif %}
}
}]
Loading

0 comments on commit b7d6cbf

Please sign in to comment.