Skip to content

Commit

Permalink
feat: Container App added Sticky Session Afinity options (#1936)
Browse files Browse the repository at this point in the history
## Description
Added the option to enable session affinity on the container app

<!--
>Thank you for your contribution !
> Please include a summary of the change and which issue is fixed.
> Please also include the context.
> List any dependencies that are required for this change.

Fixes #123
Fixes #456
Closes #123
Closes #456
-->

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.app.container-app](https://github.com/MichielVanHerreweghe/bicep-registry-modules/actions/workflows/avm.res.app.container-app.yml/badge.svg?branch=users%2Fmichielvanherreweghe%2Fcontainer-app-ingress-affinity)](https://github.com/MichielVanHerreweghe/bicep-registry-modules/actions/workflows/avm.res.app.container-app.yml)
|

## Type of Change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utlities (Non-module effecting
changes)
- [x] Azure Verified Module updates:
- [ ] Bugfix containing backwards compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [x] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [x] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [x] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->

---------

Co-authored-by: Zach Trocinski <[email protected]>
  • Loading branch information
MichielVanHerreweghe and oZakari authored May 21, 2024
1 parent 5cd8124 commit 07699bd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
16 changes: 16 additions & 0 deletions avm/res/app/container-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ module containerApp 'br/public:avm/res/app/container-app:<version>' = {
| [`scaleMinReplicas`](#parameter-scaleminreplicas) | int | Minimum number of container replicas. Defaults to 3 if not set. |
| [`scaleRules`](#parameter-scalerules) | array | Scaling rules. |
| [`secrets`](#parameter-secrets) | secureObject | The secrets of the Container App. |
| [`stickySessionsAffinity`](#parameter-stickysessionsaffinity) | string | Bool indicating if the Container App should enable session affinity. |
| [`tags`](#parameter-tags) | object | Tags of the resource. |
| [`trafficLabel`](#parameter-trafficlabel) | string | Associates a traffic label with a revision. Label name should be consist of lower case alphanumeric characters or dashes. |
| [`trafficLatestRevision`](#parameter-trafficlatestrevision) | bool | Indicates that the traffic weight belongs to a latest stable revision. |
Expand Down Expand Up @@ -834,6 +835,21 @@ The secrets of the Container App.
- Type: secureObject
- Default: `{}`

### Parameter: `stickySessionsAffinity`

Bool indicating if the Container App should enable session affinity.

- Required: No
- Type: string
- Default: `'none'`
- Allowed:
```Bicep
[
'none'
'sticky'
]
```

### Parameter: `tags`

Tags of the resource.
Expand Down
56 changes: 32 additions & 24 deletions avm/res/app/container-app/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ param location string = resourceGroup().location
@description('Optional. Bool indicating if the App exposes an external HTTP endpoint.')
param ingressExternal bool = true

@allowed([
'none'
'sticky'
])
@description('Optional. Bool indicating if the Container App should enable session affinity.')
param stickySessionsAffinity string = 'none'

@allowed([
'auto'
'http'
Expand Down Expand Up @@ -144,24 +151,23 @@ var builtInRoleNames = {
)
}

resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' =
if (enableTelemetry) {
name: '46d3xbcp.res.app-containerapp.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' = if (enableTelemetry) {
name: '46d3xbcp.res.app-containerapp.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}

resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
name: name
Expand All @@ -180,6 +186,9 @@ resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
external: ingressExternal
ipSecurityRestrictions: !empty(ipSecurityRestrictions) ? ipSecurityRestrictions : null
targetPort: ingressTargetPort
stickySessions: {
affinity: stickySessionsAffinity
}
traffic: [
{
label: trafficLabel
Expand Down Expand Up @@ -209,17 +218,16 @@ resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
}
}

resource containerApp_lock 'Microsoft.Authorization/locks@2020-05-01' =
if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: containerApp
resource containerApp_lock 'Microsoft.Authorization/locks@2020-05-01' = if (!empty(lock ?? {}) && lock.?kind != 'None') {
name: lock.?name ?? 'lock-${name}'
properties: {
level: lock.?kind ?? ''
notes: lock.?kind == 'CanNotDelete'
? 'Cannot delete resource or child resources.'
: 'Cannot delete or modify the resource or child resources.'
}
scope: containerApp
}

resource containerApp_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [
for (roleAssignment, index) in (roleAssignments ?? []): {
Expand Down
18 changes: 16 additions & 2 deletions avm/res/app/container-app/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.26.170.59819",
"templateHash": "11829581770848647649"
"version": "0.27.1.19265",
"templateHash": "6545722573689550634"
},
"name": "Container Apps",
"description": "This module deploys a Container App.",
Expand Down Expand Up @@ -149,6 +149,17 @@
"description": "Optional. Bool indicating if the App exposes an external HTTP endpoint."
}
},
"stickySessionsAffinity": {
"type": "string",
"defaultValue": "none",
"allowedValues": [
"none",
"sticky"
],
"metadata": {
"description": "Optional. Bool indicating if the Container App should enable session affinity."
}
},
"ingressTransport": {
"type": "string",
"defaultValue": "auto",
Expand Down Expand Up @@ -411,6 +422,9 @@
"external": "[parameters('ingressExternal')]",
"ipSecurityRestrictions": "[if(not(empty(parameters('ipSecurityRestrictions'))), parameters('ipSecurityRestrictions'), null())]",
"targetPort": "[parameters('ingressTargetPort')]",
"stickySessions": {
"affinity": "[parameters('stickySessionsAffinity')]"
},
"traffic": [
{
"label": "[parameters('trafficLabel')]",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/app/container-app/version.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.2",
"version": "0.3",
"pathFilters": [
"./main.json"
]
}
}

0 comments on commit 07699bd

Please sign in to comment.