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

Add support for creation/deletion of kafka #6345

Merged
merged 1 commit into from
Jun 15, 2023
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: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Upcoming
++++++
* 'az containerapp job execution show/list': improve table output format
* 'az containerapp create/update': --yaml support properties for api-version 2023-04-01-preview (e.g. subPath, mountOptions)
* 'az containerapp service': add support for creation and deletion of kafka

0.3.33
++++++
Expand Down
6 changes: 6 additions & 0 deletions src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
MANAGED_CERTIFICATE_RT = "managedCertificates"
PRIVATE_CERTIFICATE_RT = "certificates"

DEV_SERVICE_LIST = ["kafka", "postgres", "redis"]

DEV_KAFKA_IMAGE = 'kafka'
DEV_KAFKA_SERVICE_TYPE = 'kafka'
DEV_KAFKA_CONTAINER_NAME = 'kafka'

DEV_POSTGRES_IMAGE = 'postgres'
DEV_POSTGRES_SERVICE_TYPE = 'postgres'
DEV_POSTGRES_CONTAINER_NAME = 'postgres'
Expand Down
15 changes: 15 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@
short-summary: Commands to manage the postgres service for the Container Apps environment.
"""

helps['containerapp service kafka'] = """
type: group
short-summary: Commands to manage the kafka service for the Container Apps environment.
"""

helps['containerapp service redis create'] = """
type: command
short-summary: Command to create the redis service.
Expand All @@ -407,6 +412,11 @@
short-summary: Command to create the postgres service.
"""

helps['containerapp service kafka create'] = """
type: command
short-summary: Command to create the kafka service.
"""

helps['containerapp service redis delete'] = """
type: command
short-summary: Command to delete the redis service.
Expand All @@ -417,6 +427,11 @@
short-summary: Command to delete the postgres service.
"""

helps['containerapp service kafka delete'] = """
type: command
short-summary: Command to delete the kafka service.
"""

helps['containerapp env update'] = """
type: command
short-summary: Update a Container Apps environment.
Expand Down
7 changes: 4 additions & 3 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from ._client_factory import handle_raw_exception, providers_client_factory, cf_resource_groups, log_analytics_client_factory, log_analytics_shared_key_client_factory
from ._constants import (MAXIMUM_CONTAINER_APP_NAME_LENGTH, SHORT_POLLING_INTERVAL_SECS, LONG_POLLING_INTERVAL_SECS,
LOG_ANALYTICS_RP, CONTAINER_APPS_RP, CHECK_CERTIFICATE_NAME_AVAILABILITY_TYPE, ACR_IMAGE_SUFFIX,
LOGS_STRING, PENDING_STATUS, SUCCEEDED_STATUS, UPDATING_STATUS)
LOGS_STRING, PENDING_STATUS, SUCCEEDED_STATUS, UPDATING_STATUS, DEV_SERVICE_LIST)
from ._models import (ContainerAppCustomDomainEnvelope as ContainerAppCustomDomainEnvelopeModel,
ManagedCertificateEnvelop as ManagedCertificateEnvelopModel,
ServiceConnector as ServiceConnectorModel)
Expand Down Expand Up @@ -452,8 +452,9 @@ def process_service(cmd, resource_list, service_name, arg_dict, subscription_id,
if not containerapp_def:
raise ResourceNotFoundError(f"The service '{service_name}' does not exist")

configuration = containerapp_def["properties"]["configuration"]["service"]
if configuration is None or configuration["type"] not in ["redis", "postgres"]:
service_type = safe_get(containerapp_def, "properties", "configuration", "service", "type")

if service_type is None or service_type not in DEV_SERVICE_LIST:
raise ResourceNotFoundError(f"The service '{service_name}' does not exist")

service_bindings_def_list.append({
Expand Down
4 changes: 4 additions & 0 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def load_command_table(self, _):
g.custom_command('create', 'create_postgres_service', supports_no_wait=True)
g.custom_command('delete', 'delete_postgres_service', confirmation=True, supports_no_wait=True)

with self.command_group('containerapp service kafka') as g:
g.custom_command('create', 'create_kafka_service', supports_no_wait=True)
g.custom_command('delete', 'delete_kafka_service', confirmation=True, supports_no_wait=True)

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())
Expand Down
16 changes: 14 additions & 2 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
GOOGLE_SECRET_SETTING_NAME, TWITTER_SECRET_SETTING_NAME, APPLE_SECRET_SETTING_NAME, CONTAINER_APPS_RP,
NAME_INVALID, NAME_ALREADY_EXISTS, ACR_IMAGE_SUFFIX, HELLO_WORLD_IMAGE, LOG_TYPE_SYSTEM, LOG_TYPE_CONSOLE,
MANAGED_CERTIFICATE_RT, PRIVATE_CERTIFICATE_RT, PENDING_STATUS, SUCCEEDED_STATUS, DEV_POSTGRES_IMAGE, DEV_POSTGRES_SERVICE_TYPE,
DEV_POSTGRES_CONTAINER_NAME, DEV_REDIS_IMAGE, DEV_REDIS_SERVICE_TYPE, DEV_REDIS_CONTAINER_NAME)
DEV_POSTGRES_CONTAINER_NAME, DEV_REDIS_IMAGE, DEV_REDIS_SERVICE_TYPE, DEV_REDIS_CONTAINER_NAME, DEV_KAFKA_CONTAINER_NAME,
DEV_KAFKA_IMAGE, DEV_KAFKA_SERVICE_TYPE, DEV_SERVICE_LIST)

logger = get_logger(__name__)

Expand Down Expand Up @@ -178,7 +179,7 @@ def list_all_services(cmd, environment_name, resource_group_name):

for service in services:
service_type = safe_get(service, "properties", "configuration", "service", "type", default="")
if service_type in ["redis", "postgres"]:
if service_type in DEV_SERVICE_LIST:
dev_service_list.append(service)

return dev_service_list
Expand Down Expand Up @@ -206,6 +207,17 @@ def delete_postgres_service(cmd, service_name, resource_group_name, no_wait=Fals
return DevServiceUtils.delete_service(cmd, service_name, resource_group_name, no_wait, DEV_POSTGRES_SERVICE_TYPE)


def create_kafka_service(cmd, service_name, environment_name, resource_group_name, no_wait=False,
disable_warnings=True):
return DevServiceUtils.create_service(cmd, service_name, environment_name, resource_group_name, no_wait,
disable_warnings, DEV_KAFKA_IMAGE, DEV_KAFKA_SERVICE_TYPE,
DEV_KAFKA_CONTAINER_NAME)


def delete_kafka_service(cmd, service_name, resource_group_name, no_wait=False):
return DevServiceUtils.delete_service(cmd, service_name, resource_group_name, no_wait, DEV_KAFKA_SERVICE_TYPE)


def update_containerapp_yaml(cmd, name, resource_group_name, file_name, from_revision=None, no_wait=False):
yaml_containerapp = process_loaded_yaml(load_yaml_file(file_name))
if type(yaml_containerapp) != dict: # pylint: disable=unidiomatic-typecheck
Expand Down
Loading