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

Adding a validation to check if base resources are already deployed. #184

Merged
merged 18 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
5 changes: 4 additions & 1 deletion src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Release History

2.0.0b1
++++++++
* Renamed nfdvName to nfdv in CGVs
* Added useful comments to input files
* Added 1:1 mapping between NFVIsFromSite and NF RETs
* Added expose_all parameter in input file to expose all parameters in deployParameters and CGS
* Removed multiple_instances and depends_on from input file
* Added: mutating webhook for injectArtifactStoreDetails
Expand All @@ -23,7 +26,6 @@ Release History
* Fixed: Manifest name built from ACR name, so clashes
* Fixed: Nexus image version must be semver
* Fixed: Sensible error when no type given in helm chart schema
* No changes, building wheel from correct branch
* Fixed: customLocation missing from Nexus
* Fixed: helm charts not uploading correctly
* Added: Nexus support
Expand All @@ -33,6 +35,7 @@ Release History
* Added validation of the values file for helm charts when using the `az aosm nfd build` command for the `cnf` definition type
* Fixed helm chart image parsing in the `az aosm nfd build` command for the `cnf` definition type. This means that the images can now be extracted correctly from the helm chart.
* Fixed: infinite loop bug when retrying failed artifact uploads to the ACR
* Added a check to determine if all base resources are already deployed. If they all are, the deployment of base bicep is skipped.

1.0.0b4
++++++++
Expand Down
1 change: 1 addition & 0 deletions src/aosm/azext_aosm/aaz/latest/aosm/__cmd_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@register_command_group(
"aosm",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage Azure Operator Service Manager resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@register_command_group(
"aosm publisher",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Commands to manage publisher resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@register_command_group(
"aosm publisher artifact-manifest",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Commands to manage artifact manifest resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class List(AAZCommand):
"""List information about the artifact manifest.

:example: List information about the artifact manifest in the 'contoso' artifact store of the 'contoso' publisher
az aosm publisher artifact-manifest list --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

@register_command(
"aosm publisher artifact-manifest list-credential",
is_preview=True,
)
class ListCredential(AAZCommand):
"""List credential for publishing artifacts defined in artifact manifest.

:example: List credential to use for publishing an artifact from the 'contoso-manifest' manifest
az aosm publisher artifact-manifest list-credential --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso --name contoso-manifest
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class UpdateState(AAZCommand):
"""Update state for artifact manifest.

:example: Update the 'contoso-manifest' artifact manifest's state to 'Uploaded'
az aosm publisher artifact-manifest update-state --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso --name contoso-manifest --state Uploaded
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class List(AAZCommand):
"""List all the available artifacts in the parent Artifact Store.

:example: List all available artifacts in the 'contoso' artifact store of the 'contoso' publisher
az aosm publisher artifact-store artifact list --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class List(AAZCommand):
"""List a Artifact overview information.

:example: List overview information for the 'nginx' artifact in the 'contoso' artifact store of the 'contoso' publisher
az aosm publisher artifact-store artifact version list --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso --artifact-name nginx
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class UpdateState(AAZCommand):
"""Update artifact state defined in artifact store.

:example: Deprecate the 1.0.0 version of the 'nginx' artifact in the 'contoso' artifact store of the 'contoso' publisher
az aosm publisher artifact-store artifact version update-state --resource-group contoso-aosm --publisher-name contoso --artifact-store-name contoso --artifact-name nginx --name 1.0.0 --artifact-state Deprecated
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class List(AAZCommand):
"""List information of the configuration group schemas under a publisher.

:example: List the configuration group schemas defined under the contoso publisher
az aosm publisher configuration-group-schema list --resource-group contoso-aosm --publisher-name contoso
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class UpdateState(AAZCommand):
"""Update configuration group schema state.

:example: Change the 'nginx-cgs' config group schema to 'Active' state
az aosm publisher configuration-group-schema update-state --resource-group contoso-aosm --publisher-name contoso --name nginx-cgs --version-state Active
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
is_preview=True,
)
class List(AAZCommand):
"""List information about a list of network function definition versions under a network function definition group.
"""List information about the network function definition versions available in the specified network function definition group.

:example: List information about the network function definition versions available in the 'nginx' network function definition group
az aosm publisher network-function-definition version list --resource-group contoso-aosm --publisher-name contoso --group-name nginx
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class UpdateState(AAZCommand):
"""Update network function definition version state.

:example: Change version 2.0.0 of the 'nginx' network function definition group to 'Active' state
az aosm publisher network-function-definition version update-state --resource-group contoso-aosm --publisher-name contoso --group-name nginx --version-name 2.0.0 --version-state Active
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
is_preview=True,
)
class List(AAZCommand):
"""List information about a list of network service design versions under a network service design group.
"""List information about the network service design versions available under the specified network service design group.

:example: List information about the network service design versions available in the 'contoso-service' network service design group
az aosm publisher network-function-definition version list --resource-group contoso-aosm --publisher-name contoso --group-name contoso-service
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
)
class UpdateState(AAZCommand):
"""Update network service design version state.

:example: Change version 1.0.0 of the 'contoso-service' network service design group to 'Deprecated' state
az aosm publisher network-service-design version update-state --resource-group contoso-aosm --publisher-name contoso --group-name contoso-service --version-name 1.0.0 --version-state Deprecated
"""

_aaz_info = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class OnboardingCNFInputConfig(OnboardingNFDBaseInputConfig):
metadata={
"comment": (
"List of registries from which to pull the image(s).\n"
"For example [sourceacr.azurecr.io/test, myacr2.azurecr.io, ghcr.io/path].\n"
'For example ["sourceacr.azurecr.io/test", "myacr2.azurecr.io", "ghcr.io/path"].\n'
"For non Azure Container Registries, ensure you have run a docker login command before running build.\n"
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
from knack.log import get_logger
from azext_aosm.common.command_context import CommandContext
from azext_aosm.common.utils import convert_bicep_to_arm
from azext_aosm.configuration_models.common_parameters_config import \
BaseCommonParametersConfig, CoreVNFCommonParametersConfig
from azext_aosm.configuration_models.common_parameters_config import (
BaseCommonParametersConfig,
CoreVNFCommonParametersConfig,
NFDCommonParametersConfig,
NSDCommonParametersConfig
)
from azext_aosm.definition_folder.reader.base_definition import \
BaseDefinitionElement
from azext_aosm.common.constants import ManifestsExist
from azext_aosm.common.constants import (
ManifestsExist,
)

logger = get_logger(__name__)

Expand Down Expand Up @@ -153,6 +159,71 @@ def _artifact_manifests_exist(

return ManifestsExist.NONE

@staticmethod
rkaraddi marked this conversation as resolved.
Show resolved Hide resolved
def _base_resources_exist(
config: BaseCommonParametersConfig, command_context: CommandContext
) -> bool:
"""

Returns True if all base resources exist, False if even one does not.

Current code only allows one manifest for ACR, and one manifest for SA (if applicable),
so that's all we check for.
"""
try:
command_context.aosm_client.publishers.get(
resource_group_name=config.publisherResourceGroupName,
publisher_name=config.publisherName,
)
base_resources_exist = True
except azure_exceptions.ResourceNotFoundError:
base_resources_exist = False

try:
command_context.aosm_client.artifact_stores.get(
resource_group_name=config.publisherResourceGroupName,
publisher_name=config.publisherName,
artifact_store_name=config.acrArtifactStoreName,
)
base_resources_exist = True
except azure_exceptions.ResourceNotFoundError:
base_resources_exist = False

if isinstance(config, NFDCommonParametersConfig):
try:
command_context.aosm_client.network_function_definition_groups.get(
resource_group_name=config.publisherResourceGroupName,
publisher_name=config.publisherName,
network_function_definition_group_name=config.nfDefinitionGroup,
)
base_resources_exist = True
except azure_exceptions.ResourceNotFoundError:
base_resources_exist = False

if isinstance(config, CoreVNFCommonParametersConfig):
try:
command_context.aosm_client.artifact_stores.get(
resource_group_name=config.publisherResourceGroupName,
publisher_name=config.publisherName,
artifact_store_name=config.saArtifactStoreName,
)
base_resources_exist = True
except azure_exceptions.ResourceNotFoundError:
base_resources_exist = False

if isinstance(config, NSDCommonParametersConfig):
try:
command_context.aosm_client.network_service_design_groups.get(
resource_group_name=config.publisherResourceGroupName,
publisher_name=config.publisherName,
network_service_design_group_name=config.nsDesignGroup,
)
base_resources_exist = True
except azure_exceptions.ResourceNotFoundError:
base_resources_exist = False

return base_resources_exist

def deploy(
self, config: BaseCommonParametersConfig, command_context: CommandContext
):
Expand All @@ -168,6 +239,14 @@ def deploy(
# Currently, _only_ manifests are special, but if we need to add any more custom code,
# breaking this into a separate class (like we do for artifacts) is probably the right
# thing to do.
if self.path.name == "base":
base_resources_exist = self._base_resources_exist(
config=config, command_context=command_context
)
if base_resources_exist:
logger.info("Base resources already exist; skipping deployment.")
return

if self.path.name == "artifactManifest":
manifests_exist = self._artifact_manifests_exist(
config=config, command_context=command_context
Expand Down
Loading