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

Bugfixes Anthony Found #24

Merged
merged 10 commits into from
Mar 14, 2022
6 changes: 6 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Release History
===============

0.1.2
++++++
* Various fixes for bugs found
* Dapr subgroup
* Managed Identity

0.1.1
++++++
* Various fixes for az containerapp create, update
Expand Down
22 changes: 3 additions & 19 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def update(cls, cmd, resource_group_name, name, container_app_envelope, no_wait=
return r.json()

@classmethod
def delete(cls, cmd, resource_group_name, name, no_wait=False):
def delete(cls, cmd, resource_group_name, name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = NEW_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
Expand All @@ -142,24 +142,8 @@ def delete(cls, cmd, resource_group_name, name, no_wait=False):

r = send_raw_request(cmd.cli_ctx, "DELETE", request_url)

if no_wait:
return # API doesn't return JSON (it returns no content)
elif r.status_code in [200, 201, 202, 204]:
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

if r.status_code == 202:
from azure.cli.core.azclierror import ResourceNotFoundError
try:
poll(cmd, request_url, "cancelled")
except ResourceNotFoundError:
pass
logger.warning('Containerapp successfully deleted')
if r.status_code == 202:
logger.warning('Containerapp successfully deleted')
return

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
# Dapr Commands
helps['containerapp dapr'] = """
type: group
short-summary: Commands to manage Containerapp dapr.
short-summary: Commands to manage dapr.
"""

helps['containerapp dapr enable'] = """
Expand Down
3 changes: 1 addition & 2 deletions src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
"targetPort": None,
"transport": None, # 'auto', 'http', 'http2'
"traffic": None, # TrafficWeight
"customDomains": None, # [CustomDomain]
"allowInsecure": None # Boolean
"customDomains": None # [CustomDomain]
}

RegistryCredentials = {
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def load_arguments(self, _):
# Container
with self.argument_context('containerapp', arg_group='Container (Creates new revision)') as c:
c.argument('image', type=str, options_list=['--image', '-i'], help="Container image, e.g. publisher/image-name:tag.")
c.argument('image_name', type=str, options_list=['--image-name'], help="Name of the container.")
c.argument('container_name', type=str, options_list=['--container-name'], help="Name of the container.")
c.argument('cpu', type=float, validator=validate_cpu, options_list=['--cpu'], help="Required CPU in cores, e.g. 0.5")
c.argument('memory', type=str, validator=validate_memory, options_list=['--memory'], help="Required memory, e.g. 1.0Gi")
c.argument('env_vars', nargs='*', options_list=['--env-vars'], help="A list of environment variable(s) for the container. Space-separated values in 'key=value' format. Empty string to clear existing values")
Expand Down Expand Up @@ -86,7 +86,7 @@ def load_arguments(self, _):
c.argument('logs_key', type=str, options_list=['--logs-workspace-key'], help='Log Analytics workspace key to configure your Log Analytics workspace. You can use \"az monitor log-analytics workspace get-shared-keys\" to retrieve the key.')

with self.argument_context('containerapp env', arg_group='Dapr') as c:
c.argument('instrumentation_key', options_list=['--instrumentation-key'], help='Azure Monitor instrumentation key used by Dapr to export Service to Service communication telemetry')
c.argument('instrumentation_key', options_list=['--dapr-instrumentation-key'], help='Azure Monitor instrumentation key used by Dapr to export Service to Service communication telemetry')

with self.argument_context('containerapp env', arg_group='Virtual Network') as c:
c.argument('infrastructure_subnet_resource_id', type=str, options_list=['--infrastructure-subnet-resource-id'], help='Resource ID of a subnet for infrastructure components. This subnet must be in the same VNET as the subnet defined in appSubnetResourceId.')
Expand Down
14 changes: 12 additions & 2 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def _is_valid_weight(weight):
return False


def _update_traffic_Weights(containerapp_def, list_weights):
def _update_traffic_weights(containerapp_def, list_weights):
if "traffic" not in containerapp_def["properties"]["configuration"]["ingress"] or list_weights and len(list_weights):
containerapp_def["properties"]["configuration"]["ingress"]["traffic"] = []

Expand Down Expand Up @@ -493,7 +493,7 @@ def _get_app_from_revision(revision):
def _infer_acr_credentials(cmd, registry_server):
# If registry is Azure Container Registry, we can try inferring credentials
if '.azurecr.io' not in registry_server:
raise RequiredArgumentMissingError('Registry url is required if using Azure Container Registry, otherwise Registry username and password are required.')
raise RequiredArgumentMissingError('Registry username and password are required if not using Azure Container Registry.')
logger.warning('No credential was provided to access Azure Container Registry. Trying to look up credentials...')
parsed = urlparse(registry_server)
registry_name = (parsed.netloc if parsed.scheme else parsed.path).split('.')[0]
Expand All @@ -503,3 +503,13 @@ def _infer_acr_credentials(cmd, registry_server):
return (registry_user, registry_pass)
except Exception as ex:
raise RequiredArgumentMissingError('Failed to retrieve credentials for container registry {}. Please provide the registry username and password'.format(registry_name))


def _registry_exists(containerapp_def, registry_server):
exists = False
if "properties" in containerapp_def and "configuration" in containerapp_def["properties"] and "registries" in containerapp_def["properties"]["configuration"]:
for registry in containerapp_def["properties"]["configuration"]["registries"]:
if "server" in registry and registry["server"] and registry["server"].lower() == registry_server.lower():
exists = True
break
return exists
12 changes: 7 additions & 5 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ def transform_containerapp_list_output(apps):

def transform_revision_output(rev):
props = ['name', 'replicas', 'active', 'createdTime']
result = {k: rev[k] for k in rev if k in props}
result = {k: rev['properties'][k] for k in rev['properties'] if k in props}

if 'latestRevisionFqdn' in rev['template']:
result['fqdn'] = rev['template']['latestRevisionFqdn']
if 'name' in rev:
result['name'] = rev['name']

if 'fqdn' in rev['properties']['template']:
result['fqdn'] = rev['properties']['template']['fqdn']

return result

Expand All @@ -44,9 +47,8 @@ def load_command_table(self, _):
g.custom_command('show', 'show_containerapp', table_transformer=transform_containerapp_output)
g.custom_command('list', 'list_containerapp', table_transformer=transform_containerapp_list_output)
g.custom_command('create', 'create_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('scale', 'scale_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('update', 'update_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_containerapp', exception_handler=ex_handler_factory())


with self.command_group('containerapp env') as g:
Expand Down
Loading