Azure / acr

Azure Container Registry samples, troubleshooting tips and references
https://aka.ms/acr
Other
162 stars 106 forks source link

It is not possible to use custom agent pools with Bicep #694

Closed antsok closed 5 months ago

antsok commented 1 year ago

Describe the bug Azure gives an error when deploying taskRun with Bicep, despite that bicep documentation for taskRun states that it is possible to specify agent pool. See https://learn.microsoft.com/en-us/azure/templates/microsoft.containerregistry/registries/taskruns?pivots=deployment-language-bicep#resource-format

At the same time, CLI does allow to specify agent pool.

To Reproduce Steps to reproduce the behavior:

task.bicep

param acrName string
param name string
param location string = resourceGroup().location

@description('The URL(absolute or relative) of the source context for the task step.')
param dockerContextPath string = ''
@description('The Docker file path relative to the source context.')
param dockerFilePath string = 'Dockerfile'
@description('The fully qualified image names including the repository and tag.')
param dockerImageName string = ''

param doTaskRun bool = false

param forceUpdateTag string = utcNow('yyyyMMddHHmmss')

resource acr 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' existing = {
  name: acrName
}

resource acrTask 'Microsoft.ContainerRegistry/registries/tasks@2019-06-01-preview' = {
  name: name
  location: location
  parent: acr
  properties: {
    status: 'Enabled'
    agentPoolName: 'defaultPool'
    agentConfiguration: {
      cpu: 2
    }
    platform: {
      os: 'Linux'
      architecture: 'amd64'
    }
    step : {
      contextPath: dockerContextPath
      dockerFilePath: dockerFilePath
      type: 'Docker'
      imageNames: [
        dockerImageName
      ]
      isPushEnabled: true
    }
  }
}

resource acrTaskRun 'Microsoft.ContainerRegistry/registries/taskRuns@2019-06-01-preview' = if(doTaskRun) {
  name: name
  parent: acr
  location: location
  properties: {
    forceUpdateTag: forceUpdateTag
    runRequest:{
      isArchiveEnabled: true
      type: 'TaskRunRequest'
      taskId: acrTask.id
      agentPoolName: 'defaultPool'
    }
  }
}

output id string = acrTask.id
output imageNames object = acrTask.properties.step.imageNames

main.bicep

module acrDockerBuildTask '../../modules/task.bicep' = {
  scope: myResourceGroup
  name: '${deployment().name}-acr-task'
  params: {
    acrName: acr.outputs.name
    name: 'build-aznamingtool'
    location: location
    dockerContextPath: 'https://github.com/microsoft/CloudAdoptionFramework.git#master:ready/AzNamingTool'
    dockerFilePath: 'Dockerfile'
    dockerImageName: 'aznamingtool:latest'
    doTaskRun: true
  }
}

Error:

{
    "status": "Failed",
    "error": {
        "code": "DeploymentFailed",
        "target": "/subscriptions/[...]/resourceGroups/[...]/providers/Microsoft.Resources/deployments/[...]-acr-task",
        "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
        "details": [
            {
                "code": "TaskRunInvalidAgentPoolName",
                "target": "request",
                "message": "You can not set the agent pool name in the task run request. Please set the name on the task."
            }
        ]
    }
}

If I leave out this parameter and configure agentPool only on task level then taskRun deploys successfully. However when taskrun is executing it is not using the custom agent pool defined for task.

Expected behavior I would expect the behavior of Azure RM to match the documentation, so that agent pool parameter is accepted. I would also expect that task runs to respect the agent pool configured on the task.

Any relevant environment information

Additional context Add any other context about the problem here.

If any information is a concern to post here, you can create a support ticket or send an email to acrsup@microsoft.com.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

antsok commented 8 months ago

Is this repo being watched by the ACR team?

northtyphoon commented 8 months ago

You already specify agentPoolName to defaultPool when you create task resource. You don't need to pass it again in acrTaskRun request as the error pointed it out.

You can try remove agentPoolName from acrTaskRun and see if it works.

resource acrTaskRun 'Microsoft.ContainerRegistry/registries/taskRuns@2019-06-01-preview' = if(doTaskRun) {
  name: name
  parent: acr
  location: location
  properties: {
    forceUpdateTag: forceUpdateTag
    runRequest:{
      isArchiveEnabled: true
      type: 'TaskRunRequest'
      taskId: acrTask.id
    }
  }
}
yuehaoliang commented 8 months ago

The agent pool configuration is defined at the task level, and once a task has been designated to run on a specific agent pool, it should not be re-specified for individual task runs.

@antsok I've noticed you mentioned "However when taskrun is executing it is not using the custom agent pool defined for task". Are you certain about that? To verify, you can use the "az acr task show-run" command and examine whether the agent pool name for the task run is null. Additionally, providing us with the registry name and task run ID will enable us to investigate whether the task run indeed executed on your designated custom agent pool.

antsok commented 8 months ago

The agent pool configuration is defined at the task level, and once a task has been designated to run on a specific agent pool, it should not be re-specified for individual task runs.

This explanation needs to find its way in removing the agentPool property from the taskRun resource

@antsok I've noticed you mentioned "However when taskrun is executing it is not using the custom agent pool defined for task". Are you certain about that? To verify, you can use the "az acr task show-run" command and examine whether the agent pool name for the task run is null. Additionally, providing us with the registry name and task run ID will enable us to investigate whether the task run indeed executed on your designated custom agent pool.

The problem was reported 6 months ago. I no loger have those resources deployed, and logs are not retained for that long.

yuehaoliang commented 8 months ago

This explanation needs to find its way in removing the agentPool property from the taskRun resource

For a quick Run (without the creation of a Task resource), the agentPoolName property is necessary to specify where it should be run.

Likewise, when using Azure CLI, you can request a quick Run on an Agentpool by "az acr build --agent-pool", or you can create a Task configured with an Agentpool by "az acr task create --agent-pool" and subsequently execute this Task by "az acr task run". However, "az acr task run --agent-pool" will result in an error "You cannot set the agent pool name in the task run request. Please set the name on the task".

I understand your point, and I agree that the Bicep templates can be misleading. It should be documented that if the Agentpool is configured for a Task resource, the agentPoolName property should be removed for a Run resource. Thank you for your suggestion; we will assess how to enhance the user experience in this regard.

antsok commented 8 months ago

Thank you for agreeing to consider updating the documentation. It would help avoid the confusion indeed.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 5 months ago

This issue was closed because it has been stalled for 30 days with no activity.