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

[appservice-kube] az functionapp create: Make --storage-account optional for Kubernetes function apps #4678

Merged
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
14 changes: 9 additions & 5 deletions src/appservice-kube/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
Release History
===============

0.1.7
++++++
* Allow creating Azure Arc-hosted Function Apps without storage accounts

0.1.6
++++++
* Fix TypeError on 'az webapp create'
++++++
* Fix TypeError on 'az webapp create'

0.1.5
++++++
* SSL bind bug fix
* Fix compatibility issue with CLI version 2.34.1
++++++
* SSL bind bug fix
* Fix compatibility issue with CLI version 2.34.1

0.1.4
++++++
Expand Down
2 changes: 1 addition & 1 deletion src/appservice-kube/azext_appservice_kube/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def load_arguments(self, _):
c.argument('new_app_name', options_list=['--name', '-n'], help='name of the new function app')
c.argument('custom_location', help="Name or ID of the custom location. Use an ID for a custom location in a different resource group from the app")
c.argument('storage_account', options_list=['--storage-account', '-s'],
help='Provide a string value of a Storage Account in the provided Resource Group. Or Resource ID of a Storage Account in a different Resource Group')
help='Provide a string value of a Storage Account in the provided Resource Group. Or Resource ID of a Storage Account in a different Resource Group. Required for non-kubernetes function apps')
c.argument('consumption_plan_location', options_list=['--consumption-plan-location', '-c'],
help="Geographic location where Function App will be hosted. Use `az functionapp list-consumption-locations` to view available locations.")
c.argument('functions_version', help='The functions app version. Use "az functionapp list-runtimes" to check compatibility with runtimes and runtime versions', arg_type=get_enum_type(FUNCTIONS_VERSIONS))
Expand Down
24 changes: 16 additions & 8 deletions src/appservice-kube/azext_appservice_kube/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ def _is_function_kube(custom_location, plan_info, SkuDescription):
isinstance(plan_info.sku, SkuDescription) and plan_info.sku.name.upper() == KUBE_DEFAULT_SKU))


def create_functionapp(cmd, resource_group_name, name, storage_account, plan=None,
def create_functionapp(cmd, resource_group_name, name, storage_account=None, plan=None,
os_type=None, functions_version=None, runtime=None, runtime_version=None,
consumption_plan_location=None, app_insights=None, app_insights_key=None,
disable_app_insights=None, deployment_source_url=None,
Expand Down Expand Up @@ -1101,6 +1101,8 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
raise ArgumentUsageError('Must specify --runtime to use --runtime-version')

is_kube = _is_function_kube(custom_location, plan_info, SkuDescription)
if not storage_account and not is_kube:
raise ValidationError("--storage-account required for non-kubernetes function apps")

runtime_helper = _FunctionAppStackRuntimeHelper(cmd, linux=is_linux, windows=(not is_linux))
matched_runtime = runtime_helper.resolve("dotnet" if not runtime else runtime,
Expand All @@ -1116,7 +1118,9 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
site_config_dict = matched_runtime.site_config_dict
app_settings_dict = matched_runtime.app_settings_dict

con_string = _validate_and_get_connection_string(cmd.cli_ctx, resource_group_name, storage_account)
con_string = None
if storage_account:
con_string = _validate_and_get_connection_string(cmd.cli_ctx, resource_group_name, storage_account)

if is_kube:
functionapp_def.enable_additional_properties_sending()
Expand Down Expand Up @@ -1194,16 +1198,18 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non

site_config.app_settings.append(NameValuePair(name='FUNCTIONS_EXTENSION_VERSION',
value=_get_extension_version_functionapp(functions_version)))
site_config.app_settings.append(NameValuePair(name='AzureWebJobsStorage', value=con_string))
if con_string:
site_config.app_settings.append(NameValuePair(name='AzureWebJobsStorage', value=con_string))

# If plan is not consumption or elastic premium, we need to set always on
if consumption_plan_location is None and not is_plan_elastic_premium(cmd, plan_info):
site_config.always_on = True

# If plan is elastic premium or consumption, we need these app settings
if is_plan_elastic_premium(cmd, plan_info) or consumption_plan_location is not None:
site_config.app_settings.append(NameValuePair(name='WEBSITE_CONTENTAZUREFILECONNECTIONSTRING',
value=con_string))
if con_string:
site_config.app_settings.append(NameValuePair(name='WEBSITE_CONTENTAZUREFILECONNECTIONSTRING',
value=con_string))
site_config.app_settings.append(NameValuePair(name='WEBSITE_CONTENTSHARE', value=_get_content_share_name(name)))

create_app_insights = False
Expand All @@ -1217,7 +1223,8 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
value=instrumentation_key))
elif disable_app_insights or not matched_runtime.app_insights:
# set up dashboard if no app insights
site_config.app_settings.append(NameValuePair(name='AzureWebJobsDashboard', value=con_string))
if con_string:
site_config.app_settings.append(NameValuePair(name='AzureWebJobsDashboard', value=con_string))
elif not disable_app_insights and matched_runtime.app_insights:
create_app_insights = True

Expand All @@ -1238,8 +1245,9 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
except Exception: # pylint: disable=broad-except
logger.warning('Error while trying to create and configure an Application Insights for the Function App. '
'Please use the Azure Portal to create and configure the Application Insights, if needed.')
update_app_settings(cmd, functionapp.resource_group, functionapp.name,
['AzureWebJobsDashboard={}'.format(con_string)])
if con_string:
update_app_settings(cmd, functionapp.resource_group, functionapp.name,
['AzureWebJobsDashboard={}'.format(con_string)])

if deployment_container_image_name:
update_container_settings_functionapp(cmd, resource_group_name, name, docker_registry_server_url,
Expand Down
Loading