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

Containerapps 4/11 Release [ Supporting MSI for ACA & some bug fixes] #4660

Merged
merged 9 commits into from
Apr 12, 2022
71 changes: 61 additions & 10 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
--image nginx --environment MyContainerappEnv \\
--cpu 0.5 --memory 1.0Gi \\
--min-replicas 4 --max-replicas 8
- name: Create a container app with secrets and environment variables.
text: |
az containerapp create -n MyContainerapp -g MyResourceGroup \\
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
--image my-app:v1.0 --environment MyContainerappEnv \\
--secrets mysecret=secretvalue1 anothersecret="secret value 2" \\
--env-vars GREETING="Hello, world" SECRETENV=secretref:anothersecret
- name: Create a container app using a YAML configuration. Example YAML configuration - https://aka.ms/azure-container-apps-yaml
text: |
az containerapp create -n MyContainerapp -g MyResourceGroup \\
Expand Down Expand Up @@ -162,6 +156,14 @@

"""

helps['containerapp revision copy'] = """
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
type: command
short-summary: Create a revision based on a previous revision.
examples:
- name: Create a revision based on a previous revision.
text: |
az containerapp revision copy -n MyContainerapp -g MyResourceGroup --cpu 0.75 --memory 1.5Gi
"""

# Environment Commands
helps['containerapp env'] = """
Expand All @@ -176,13 +178,13 @@
- name: Create an environment with an auto-generated Log Analytics workspace.
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--location "Canada Central"
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
--location eastus2
- name: Create an environment with an existing Log Analytics workspace.
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--logs-workspace-id myLogsWorkspaceID \\
--logs-workspace-key myLogsWorkspaceKey \\
--location "Canada Central"
--location eastus2
"""


Expand Down Expand Up @@ -256,6 +258,55 @@
az containerapp env dapr-component remove -g MyResourceGroup --dapr-component-name MyDaprComponentName --name MyEnvironment
"""

# Identity Commands
helps['containerapp identity'] = """
type: group
short-summary: Commands to manage managed identities.
"""

helps['containerapp identity assign'] = """
type: command
short-summary: Assign managed identity to a container app.
long-summary: Managed identities can be user-assigned or system-assigned.
examples:
- name: Assign system identity.
text: |
az containerapp identity assign -n myContainerapp -g MyResourceGroup --system-assigned
- name: Assign user identity.
text: |
az containerapp identity assign -n myContainerapp -g MyResourceGroup --user-assigned myAssignedId
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
- name: Assign system and user identity.
text: |
az containerapp identity assign -n myContainerapp -g MyResourceGroup --system-assigned --user-assigned myAssignedId
"""

helps['containerapp identity remove'] = """
type: command
short-summary: Remove a managed identity from a container app.
examples:
- name: Remove system identity.
text: |
az containerapp identity remove -n myContainerapp -g MyResourceGroup --system-assigned
- name: Remove system and user identity.
text: |
az containerapp identity remove -n myContainerapp -g MyResourceGroup --system-assigned --user-assigned myAssignedId
- name: Remove all user identities.
text: |
az containerapp identity remove -n myContainerapp -g MyResourceGroup --user-assigned
- name: Remove system identity and all user identities.
text: |
az containerapp identity remove -n myContainerapp -g MyResourceGroup --system-assigned --user-assigned
"""

helps['containerapp identity show'] = """
type: command
short-summary: Show managed identities of a container app.
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
examples:
- name: Show managed identities.
text: |
az containerapp identity show -n myContainerapp -g MyResourceGroup
"""

# Ingress Commands
helps['containerapp ingress'] = """
type: group
Expand Down Expand Up @@ -470,7 +521,7 @@

helps['containerapp dapr enable'] = """
type: command
short-summary: Enable Dapr for a container app.
short-summary: Enable Dapr for a container app. Updates existing values.
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
examples:
- name: Enable Dapr for a container app.
text: |
Expand All @@ -479,7 +530,7 @@

helps['containerapp dapr disable'] = """
type: command
short-summary: Disable Dapr for a container app.
short-summary: Disable Dapr for a container app. Removes existing values.
examples:
- name: Disable Dapr for a container app.
text: |
Expand Down
22 changes: 15 additions & 7 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def load_arguments(self, _):
with self.argument_context('containerapp', arg_group='Container') as c:
c.argument('image', type=str, options_list=['--image', '-i'], help="Container image, e.g. publisher/image-name:tag.")
c.argument('container_name', type=str, help="Name of the container.")
c.argument('cpu', type=float, validator=validate_cpu, help="Required CPU in cores, e.g. 0.5")
c.argument('memory', type=str, validator=validate_memory, help="Required memory, e.g. 1.0Gi")
c.argument('cpu', type=float, validator=validate_cpu, help="Required CPU in cores from 0.25 - 2.0, e.g. 0.5")
c.argument('memory', type=str, validator=validate_memory, help="Required memory from 0.5 - 4.0 ending with \"Gi\", e.g. 1.0Gi")
c.argument('env_vars', nargs='*', help="A list of environment variable(s) for the container. Space-separated values in 'key=value' format. Empty string to clear existing values. Prefix value with 'secretref:' to reference a secret.")
c.argument('startup_command', nargs='*', options_list=['--command'], help="A list of supported commands on the container that will executed during startup. Space-separated values e.g. \"/bin/queue\" \"mycommand\". Empty string to clear existing values")
c.argument('args', nargs='*', help="A list of container startup command argument(s). Space-separated values e.g. \"-c\" \"mycommand\". Empty string to clear existing values")
Expand Down Expand Up @@ -77,6 +77,10 @@ def load_arguments(self, _):
with self.argument_context('containerapp create') as c:
c.argument('traffic_weights', nargs='*', options_list=['--traffic-weight'], help="A list of revision weight(s) for the container app. Space-separated values in 'revision_name=weight' format. For latest revision, use 'latest=weight'")

with self.argument_context('containerapp create', arg_group='Identity') as c:
c.argument('user_assigned', nargs='+', help="Space-separated user identities to be assigned.")
c.argument('system_assigned', help="Boolean indicating whether to assign system-assigned identity.")

with self.argument_context('containerapp scale') as c:
c.argument('min_replicas', type=int, help="The minimum number of replicas.")
c.argument('max_replicas', type=int, help="The maximum number of replicas.")
Expand Down Expand Up @@ -112,6 +116,13 @@ def load_arguments(self, _):
with self.argument_context('containerapp env show') as c:
c.argument('name', name_type, help='Name of the Container Apps Environment.')

with self.argument_context('containerapp identity') as c:
c.argument('user_assigned', nargs='+', help="Space-separated user identities.")
c.argument('system_assigned', help="Boolean indicating whether to assign system-assigned identity.")

with self.argument_context('containerapp identity remove') as c:
c.argument('user_assigned', nargs='*', help="Space-separated user identities. If no user identities are specified, all user identities will be removed.")

with self.argument_context('containerapp github-action add') as c:
c.argument('repo_url', help='The GitHub repository to which the workflow file will be added. In the format: https://github.com/<owner>/<repository-name>')
c.argument('token', help='A Personal Access Token with write access to the specified repository. For more information: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line')
Expand Down Expand Up @@ -144,14 +155,11 @@ def load_arguments(self, _):
with self.argument_context('containerapp ingress traffic') as c:
c.argument('traffic_weights', nargs='*', options_list=['--traffic-weight'], help="A list of revision weight(s) for the container app. Space-separated values in 'revision_name=weight' format. For latest revision, use 'latest=weight'")

with self.argument_context('containerapp secret set') as c:
with self.argument_context('containerapp secret') as c:
calvinsID marked this conversation as resolved.
Show resolved Hide resolved
c.argument('secrets', nargs='+', options_list=['--secrets', '-s'], help="A list of secret(s) for the container app. Space-separated values in 'key=value' format.")

with self.argument_context('containerapp secret show') as c:
c.argument('secret_name', help="The name of the secret to show.")

with self.argument_context('containerapp secret remove') as c:
c.argument('secret_names', nargs='+', help="A list of secret(s) for the container app. Space-separated secret values names.")
c.argument('show_values', help='Show the secret values.')

with self.argument_context('containerapp env dapr-component') as c:
c.argument('dapr_app_id', help="The Dapr app ID.")
Expand Down
11 changes: 6 additions & 5 deletions src/containerapp/azext_containerapp/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def _is_number(s):


def validate_memory(namespace):
memory = namespace.memory

if memory is not None:
if namespace.memory is not None:
valid = False

if memory.endswith("Gi"):
valid = _is_number(memory[:-2])
if not namespace.memory.endswith("Gi"):
namespace.memory = namespace.memory.rstrip()
namespace.memory += "Gi"

valid = _is_number(namespace.memory[:-2])

if not valid:
raise ValidationError("Usage error: --memory must be a number ending with \"Gi\"")
Expand Down
5 changes: 5 additions & 0 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def load_command_table(self, _):
g.custom_command('set', 'create_or_update_dapr_component')
g.custom_command('remove', 'remove_dapr_component')

with self.command_group('containerapp identity') as g:
g.custom_command('assign', 'assign_managed_identity', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('remove', 'remove_managed_identity', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_managed_identity')

with self.command_group('containerapp github-action') as g:
g.custom_command('add', 'create_or_update_github_action', exception_handler=ex_handler_factory())
g.custom_show_command('show', 'show_github_action', exception_handler=ex_handler_factory())
Expand Down
Loading