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] az containerapp up: support create or update containerapp on connected env #7004

Merged
merged 14 commits into from
Nov 28, 2023
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release History
===============
upcoming
++++++
'az containerapp up': support to create or update a containerapp on connected environment as well as any associated resources (extension on connected cluster, custom location) with --custom-location or --connected-cluster-id

0.3.44
++++++
Expand Down
7 changes: 7 additions & 0 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,10 @@ def k8s_extension_client_factory(cli_ctx, subscription_id=None):

r = get_mgmt_service_client(cli_ctx, SourceControlConfigurationClient, subscription_id=subscription_id)
return r.extensions


def connected_k8s_client_factory(cli_ctx, subscription_id=None):
from azext_containerapp.vendored_sdks.hybridkubernetes import ConnectedKubernetesClient
Copy link
Contributor Author

@Greedygre Greedygre Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ConnectedKubernetesClient need to import pkg 'azure-mgmt-hybridkubernetes==1.1.0', according to previous communication with @zhoxing-ms , it is recommended to use vendored sdk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 options to choose from after entering core:
If the code depend on is not much, we can consider continuing to vendor the small amount of code we need.
If the code depend on is a lot, and we want to update the code with the package in the future, we can consider adding the dependency of azure-mgmt-hybridkubernetes==1.1.0 in Core.


r = get_mgmt_service_client(cli_ctx, ConnectedKubernetesClient, subscription_id=subscription_id)
return r.connected_cluster
5 changes: 5 additions & 0 deletions src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
MANAGED_ENVIRONMENT_RESOURCE_TYPE = "managedEnvironments"
CONNECTED_ENVIRONMENT_RESOURCE_TYPE = "connectedEnvironments"
CUSTOM_LOCATION_RESOURCE_TYPE = "customLocations"
CONNECTED_CLUSTER_TYPE = "connectedClusters"

MAXIMUM_SECRET_LENGTH = 20
MAXIMUM_CONTAINER_APP_NAME_LENGTH = 32
Expand Down Expand Up @@ -41,6 +42,7 @@
CONTAINER_APPS_RP = "Microsoft.App"
SERVICE_LINKER_RP = "Microsoft.ServiceLinker"
EXTENDED_LOCATION_RP = "Microsoft.ExtendedLocation"
KUBERNETES_CONFIGURATION_RP = "Microsoft.KubernetesConfiguration"
CONTAINER_APP_EXTENSION_TYPE = "microsoft.app.environment"

MANAGED_CERTIFICATE_RT = "managedCertificates"
Expand Down Expand Up @@ -113,3 +115,6 @@
HELLO_WORLD_IMAGE = "mcr.microsoft.com/k8se/quickstart:latest"

LOGS_STRING = '[{"category":"ContainerAppConsoleLogs","categoryGroup":null,"enabled":true,"retentionPolicy":{"days":0,"enabled":false}},{"category":"ContainerAppSystemLogs","categoryGroup":null,"enabled":true,"retentionPolicy":{"days":0,"enabled":false}}]' # pylint: disable=line-too-long

DEFAULT_CONNECTED_CLUSTER_EXTENSION_NAME = "containerapp-ext"
DEFAULT_CONNECTED_CLUSTER_EXTENSION_NAMESPACE = "containerapp-ns"
6 changes: 6 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
- name: Create a container app from an image in a registry with ingress enabled and a specified environment
text: |
az containerapp up -n MyContainerapp --image myregistry.azurecr.io/myImage:myTag --ingress external --target-port 80 --environment MyEnv
- name: Create a container app from an image in a registry on a Connected cluster
text: |
az containerapp up -n MyContainerapp --image myregistry.azurecr.io/myImage:myTag --connected-cluster-id MyConnectedClusterResourceId
- name: Create a container app from an image in a registry on a connected environment
text: |
az containerapp up -n MyContainerapp --image myregistry.azurecr.io/myImage:myTag --environment MyConnectedEnvironmentId
"""

helps['containerapp show-custom-domain-verification-id'] = """
Expand Down
5 changes: 4 additions & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .action import AddCustomizedKeys
from ._validators import (validate_env_name_or_id,
validate_custom_location_name_or_id)
validate_custom_location_name_or_id, validate_env_name_or_id_for_up)
from ._constants import MAXIMUM_CONTAINER_APP_NAME_LENGTH, MAXIMUM_APP_RESILIENCY_NAME_LENGTH, MAXIMUM_COMPONENT_RESILIENCY_NAME_LENGTH


Expand Down Expand Up @@ -144,7 +144,10 @@ def load_arguments(self, _):
c.argument('pubsub', help="The pubsub component and dev service to create.")

with self.argument_context('containerapp up') as c:
c.argument('environment', validator=validate_env_name_or_id_for_up, options_list=['--environment'], help="Name or resource ID of the container app's managed environment or connected environment.")
c.argument('artifact', help="Local path to the application artifact for building the container image. See the supported artifacts here: https://aka.ms/SourceToCloudSupportedArtifacts.", is_preview=True)
c.argument('custom_location_id', options_list=['--custom-location'], help="Resource ID of custom location. List using 'az customlocation list'.", is_preview=True)
c.argument('connected_cluster_id', help="Resource ID of connected cluster. List using 'az connectedk8s list'.", configured_default='connected_cluster_id', is_preview=True)

with self.argument_context('containerapp up', arg_group='Github Repo') as c:
c.argument('repo', help='Create an app via Github Actions. In the format: https://github.com/<owner>/<repository-name> or <owner>/<repository-name>')
Expand Down
Loading