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

fix: Fixes issue in avm/res/container-instance/container-group when container memory is set to less than 1 GB. #3752

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
237 changes: 198 additions & 39 deletions avm/res/container-instance/container-group/README.md
AlexanderSehr marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions avm/res/container-instance/container-group/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ type containerType = {
@description('Optional. The GPU request of this container instance.')
gpu: containerGpuType?

@description('Optional. The memory request in GB of this container instance. To specify a decimal value, use the json() function.')
memoryInGB: int?
@description('Optional. The memory request in GB of this container instance.')
memoryInGB: string?
Copy link
Contributor

Choose a reason for hiding this comment

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

The resource documentation says

memoryInGB

The memory limit in GB of this container instance. To specify a decimal value, use the json() function.

int or json decimal

https://learn.microsoft.com/en-us/azure/templates/microsoft.containerinstance/containergroups?pivots=deployment-language-bicep#resourcelimits

I'm not sure whether this might lead to misunderstandings?

might be good to use type any and add the description again?

@eriqua, @AlexanderSehr what do you think?

Copy link
Contributor

@JPEasier JPEasier Nov 22, 2024

Choose a reason for hiding this comment

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

@Azure/avm-core-team I need a second pair of eyes.

}

@description('Optional. The resource limits of this container instance.')
Expand All @@ -296,8 +296,8 @@ type containerType = {
@description('Optional. The GPU limit of this container instance.')
gpu: containerGpuType?

@description('Optional. The memory limit in GB of this container instance. To specify a decimal value, use the json() function.')
memoryInGB: int?
@description('Optional. The memory limit in GB of this container instance.')
memoryInGB: string?
}?

@description('Optional. The security context of the container instance.')
Expand Down
23 changes: 8 additions & 15 deletions avm/res/container-instance/container-group/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.23.60470",
"templateHash": "14261370383859328082"
"version": "0.31.34.60546",
"templateHash": "7330506581124658680"
},
"name": "Container Instances Container Groups",
"description": "This module deploys a Container Instance Container Group.",
Expand Down Expand Up @@ -165,10 +165,10 @@
}
},
"memoryInGB": {
"type": "int",
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. The memory request in GB of this container instance. To specify a decimal value, use the json() function."
"description": "Optional. The memory request in GB of this container instance."
}
}
},
Expand All @@ -193,10 +193,10 @@
}
},
"memoryInGB": {
"type": "int",
"type": "string",
"nullable": true,
"metadata": {
"description": "Optional. The memory limit in GB of this container instance. To specify a decimal value, use the json() function."
"description": "Optional. The memory limit in GB of this container instance."
}
}
},
Expand Down Expand Up @@ -628,10 +628,7 @@
"apiVersion": "2023-02-01",
"subscriptionId": "[split(coalesce(tryGet(parameters('customerManagedKey'), 'keyVaultResourceId'), '//'), '/')[2]]",
"resourceGroup": "[split(coalesce(tryGet(parameters('customerManagedKey'), 'keyVaultResourceId'), '////'), '/')[4]]",
"name": "[format('{0}/{1}', last(split(coalesce(tryGet(parameters('customerManagedKey'), 'keyVaultResourceId'), 'dummyVault'), '/')), coalesce(tryGet(parameters('customerManagedKey'), 'keyName'), 'dummyKey'))]",
"dependsOn": [
"cMKKeyVault"
]
"name": "[format('{0}/{1}', last(split(coalesce(tryGet(parameters('customerManagedKey'), 'keyVaultResourceId'), 'dummyVault'), '/')), coalesce(tryGet(parameters('customerManagedKey'), 'keyName'), 'dummyKey'))]"
},
"avmTelemetry": {
"condition": "[parameters('enableTelemetry')]",
Expand Down Expand Up @@ -678,11 +675,7 @@
"location": "[parameters('location')]",
"identity": "[variables('identity')]",
"tags": "[parameters('tags')]",
"properties": "[union(createObject('containers', parameters('containers'), 'encryptionProperties', if(not(empty(parameters('customerManagedKey'))), createObject('identity', if(not(empty(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), ''))), extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), '//'), '/')[2], split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), '////'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', last(split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), 'dummyMsi'), '/'))), null()), 'keyName', parameters('customerManagedKey').keyName, 'keyVersion', if(not(empty(coalesce(tryGet(parameters('customerManagedKey'), 'keyVersion'), ''))), parameters('customerManagedKey').keyVersion, last(split(reference('cMKKeyVault::cMKKey').keyUriWithVersion, '/'))), 'vaultBaseUrl', reference('cMKKeyVault').vaultUri), null()), 'imageRegistryCredentials', parameters('imageRegistryCredentials'), 'initContainers', parameters('initContainers'), 'restartPolicy', parameters('restartPolicy'), 'osType', parameters('osType'), 'ipAddress', createObject('type', parameters('ipAddressType'), 'autoGeneratedDomainNameLabelScope', if(not(empty(parameters('dnsNameServers'))), parameters('autoGeneratedDomainNameLabelScope'), null()), 'dnsNameLabel', parameters('dnsNameLabel'), 'ports', parameters('ipAddressPorts')), 'sku', parameters('sku'), 'subnetIds', if(not(empty(parameters('subnetId'))), createArray(createObject('id', parameters('subnetId'))), null()), 'volumes', parameters('volumes')), if(not(empty(parameters('dnsNameServers'))), createObject('dnsConfig', createObject('nameServers', parameters('dnsNameServers'), 'searchDomains', parameters('dnsSearchDomains'))), createObject()))]",
"dependsOn": [
"cMKKeyVault",
"cMKUserAssignedIdentity"
]
"properties": "[union(createObject('containers', parameters('containers'), 'encryptionProperties', if(not(empty(parameters('customerManagedKey'))), createObject('identity', if(not(empty(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), ''))), extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), '//'), '/')[2], split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), '////'), '/')[4]), 'Microsoft.ManagedIdentity/userAssignedIdentities', last(split(coalesce(tryGet(parameters('customerManagedKey'), 'userAssignedIdentityResourceId'), 'dummyMsi'), '/'))), null()), 'keyName', parameters('customerManagedKey').keyName, 'keyVersion', if(not(empty(coalesce(tryGet(parameters('customerManagedKey'), 'keyVersion'), ''))), parameters('customerManagedKey').keyVersion, last(split(reference('cMKKeyVault::cMKKey').keyUriWithVersion, '/'))), 'vaultBaseUrl', reference('cMKKeyVault').vaultUri), null()), 'imageRegistryCredentials', parameters('imageRegistryCredentials'), 'initContainers', parameters('initContainers'), 'restartPolicy', parameters('restartPolicy'), 'osType', parameters('osType'), 'ipAddress', createObject('type', parameters('ipAddressType'), 'autoGeneratedDomainNameLabelScope', if(not(empty(parameters('dnsNameServers'))), parameters('autoGeneratedDomainNameLabelScope'), null()), 'dnsNameLabel', parameters('dnsNameLabel'), 'ports', parameters('ipAddressPorts')), 'sku', parameters('sku'), 'subnetIds', if(not(empty(parameters('subnetId'))), createArray(createObject('id', parameters('subnetId'))), null()), 'volumes', parameters('volumes')), if(not(empty(parameters('dnsNameServers'))), createObject('dnsConfig', createObject('nameServers', parameters('dnsNameServers'), 'searchDomains', parameters('dnsSearchDomains'))), createObject()))]"
},
"containergroup_lock": {
"condition": "[and(not(empty(coalesce(parameters('lock'), createObject()))), not(equals(tryGet(parameters('lock'), 'kind'), 'None')))]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand All @@ -101,7 +101,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
targetScope = 'subscription'

metadata name = 'Using only defaults and low memory containers'
metadata description = 'This instance deploys the module with the minimum set of required parameters and with low memory.'

// ========== //
// Parameters //
// ========== //

@description('Optional. The name of the resource group to deploy for testing purposes.')
@maxLength(90)
param resourceGroupName string = 'dep-${namePrefix}-containerinstance.containergroups-${serviceShort}-rg'

@description('Optional. The location to deploy resources to.')
param resourceLocation string = deployment().location

@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.')
param serviceShort string = 'ciclow'

@description('Optional. A token to inject into the name of each resource.')
param namePrefix string = '#_namePrefix_#'

// ============ //
// Dependencies //
// ============ //

// General resources
// =================
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: resourceGroupName
location: resourceLocation
}

// ============== //
// Test Execution //
// ============== //

@batchSize(1)
module testDeployment '../../../main.bicep' = [
for iteration in ['init', 'idem']: {
scope: resourceGroup
name: '${uniqueString(deployment().name, resourceLocation)}-test-${serviceShort}-${iteration}'
params: {
location: resourceLocation
name: '${namePrefix}${serviceShort}001'
containers: [
{
name: '${namePrefix}-az-aci-x-001'
properties: {
image: 'mcr.microsoft.com/azuredocs/aci-helloworld'
ports: [
{
port: 443
protocol: 'Tcp'
}
]
resources: {
requests: {
cpu: 2
memoryInGB: '0.5'
}
}
}
}
]
ipAddressPorts: [
{
protocol: 'Tcp'
port: 443
}
]
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
limits: {
cpu: 4
memoryInGB: '4'
}
}
}
Expand All @@ -105,7 +109,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 4
memoryInGB: '4'
}
}
}
Expand All @@ -97,7 +97,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand All @@ -96,7 +96,7 @@ module testDeployment '../../../main.bicep' = [
resources: {
requests: {
cpu: 2
memoryInGB: 2
memoryInGB: '2'
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-instance/container-group/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"
]
}
}