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

{containerapp} remove additional conversion of binding name of Java component #7335

Merged
merged 19 commits into from
Mar 1, 2024
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
1 change: 0 additions & 1 deletion src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
CONNECTED_CLUSTER_TYPE = "connectedClusters"
AZURE_FILE_STORAGE_TYPE = "azureFile"
NFS_AZURE_FILE_STORAGE_TYPE = "nfsAzureFile"
JAVA_COMPONENT_RESOURCE_TYPE = "javaComponents"

MAXIMUM_SECRET_LENGTH = 20
MAXIMUM_CONTAINER_APP_NAME_LENGTH = 32
Expand Down
13 changes: 1 addition & 12 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ._constants import (CONTAINER_APP_EXTENSION_TYPE,
CONNECTED_ENV_CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE, DEV_SERVICE_LIST,
MANAGED_ENVIRONMENT_RESOURCE_TYPE, CONTAINER_APPS_RP, CONNECTED_CLUSTER_TYPE,
DEFAULT_CONNECTED_CLUSTER_EXTENSION_NAMESPACE, JAVA_COMPONENT_RESOURCE_TYPE)
DEFAULT_CONNECTED_CLUSTER_EXTENSION_NAMESPACE)

logger = get_logger(__name__)

Expand Down Expand Up @@ -114,11 +114,6 @@ def validate_binding_name(binding_name):
return bool(re.match(pattern, binding_name))


def is_valid_java_component_resource_id(resource_id):
java_component_dict = parse_resource_id(resource_id)
return java_component_dict.get("type") == MANAGED_ENVIRONMENT_RESOURCE_TYPE and java_component_dict.get("resource_type") == JAVA_COMPONENT_RESOURCE_TYPE


def check_unique_bindings(cmd, service_connectors_def_list, service_bindings_def_list, resource_group_name, name):
linker_client = get_linker_client(cmd)
containerapp_def = None
Expand Down Expand Up @@ -167,7 +162,6 @@ def parse_service_bindings(cmd, service_bindings_list, resource_group_name, name
managed_env_name = parsed_managed_env['name']
managed_env_rg = parsed_managed_env['resource_group']
java_component_list = JavaComponentPreviewClient.list(cmd, managed_env_rg, managed_env_name)
java_component_name_set = {java_component["name"] for java_component in java_component_list}

for service_binding_str in service_bindings_list:
parts = service_binding_str.split(",")
Expand All @@ -190,11 +184,6 @@ def parse_service_bindings(cmd, service_bindings_list, resource_group_name, name
else:
binding_name = service_binding[1]

# If resource is Java component, will automatically change the '-' in binding name to '_'
if service_name in java_component_name_set and '-' in binding_name:
logger.info("automatically change the '-' in binding name of Java component to '_'.")
binding_name = binding_name.replace('-', '_')

if not validate_binding_name(binding_name):
raise InvalidArgumentValueError("The Binding Name can only contain letters, numbers (0-9), periods ('.'), "
"and underscores ('_'). The length must not be more than 60 characters. "
Expand Down
11 changes: 1 addition & 10 deletions src/containerapp/azext_containerapp/containerapp_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from ._decorator_utils import (create_deserializer,
process_loaded_yaml,
load_yaml_file)
from ._utils import parse_service_bindings, check_unique_bindings, is_valid_java_component_resource_id
from ._utils import parse_service_bindings, check_unique_bindings
from ._validators import validate_create

from ._constants import (HELLO_WORLD_IMAGE,
Expand Down Expand Up @@ -1187,20 +1187,11 @@ def set_up_unbind_service_bindings(self):
new_template["serviceBinds"] = existing_template.get("serviceBinds", [])

service_bindings_dict = {}
java_component_name_set = {}
if new_template["serviceBinds"]:
service_bindings_dict = {service_binding["name"]: index for index, service_binding in
enumerate(new_template.get("serviceBinds", []))}
java_component_name_set = {binding["name"].replace('_', '-') for binding in new_template["serviceBinds"]
if is_valid_java_component_resource_id(binding["serviceId"])}

for item in self.get_argument_unbind_service_bindings():

# If resource is Java component, will automatically change the '-' in binding name to '_'
if item in java_component_name_set and '-' in item:
logger.info("automatically change the '-' in binding name of Java component to '_'.")
item = item.replace('-', '_')

if item in service_bindings_dict:
new_template["serviceBinds"] = [binding for binding in new_template["serviceBinds"] if
binding["name"] != item]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any, Dict

from azure.cli.core.commands import AzCliCommand
from azure.cli.core.azclierror import ValidationError
from azure.cli.core.azclierror import ValidationError, CLIInternalError
from azure.cli.command_modules.containerapp.base_resource import BaseResource
from knack.log import get_logger

Expand Down Expand Up @@ -57,6 +57,10 @@ def create(self):
environment_name=self.get_argument_environment_name(), name=self.get_argument_java_component_name(),
java_component_envelope=self.java_component_def, no_wait=self.get_argument_no_wait())
except Exception as e:
stringErr = str(e)
if "JavaComponentsNotAllowedForSubscription" in stringErr:
ShichaoQiu marked this conversation as resolved.
Show resolved Hide resolved
raise CLIInternalError("Java Components operations are not allowed for the subscription, please use 'az feature register --namespace Microsoft.App --name JavaComponentsPreview' to register this feature.")

handle_raw_exception(e)

def update(self):
Expand Down
Loading
Loading