Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.65k stars 847 forks source link

Not getting an option to mount volume for an azure container job at the time of start #22168

Open kumarmo-2 opened 11 months ago

kumarmo-2 commented 11 months ago

Bug Report

Below is how i am defining the template.

    args := getContainerArgs(processId, debug, redisUri, meta, timeout)
    envId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s", subscriptionId, resourceGroupName, containerEnvName)
    container := aca.JobExecutionContainer{
        Name:  &containerExecutionName,
        Image: &containerImage,
        Args:  args,
    }
    jobTemplate := &aca.JobExecutionTemplate{
        Containers: []*aca.JobExecutionContainer{&container},
    }

The behavior i am seeing doing this is that, my volume mount and my environment variables that i defined at the time of job creation are not present when the job is running.

Now what i believe is happening here, is basically its overriding the configuration that i created at the time of the job creation. I could have done that, but I am seeing no way to attach volumes to the container. Although i can define environment variables.

The struct JobExecutionTemplate, allows me to defined the Containers and Init Containers but not volumes. This is a deal breaker for me to use jobs.

github-actions[bot] commented 11 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @antcp @AzureAppServiceCLI.

bcspragu commented 18 hours ago

I believe this is a root cause of an issue I've been debugging as well: volume mounts don't show up (e.g. the directories don't exist in the container) when I programmatically start a Container Apps Jobs execution, but they do when I start them from the UI (Run now) or via the az CLI.

Here's an example az CLI invocation:

az containerapp job start \
    --name ... \
    --env-vars '...' \
    --command '...' \
    --image ... \
    --resource-group ... \
    --verbose

# And the output:

Request URL: 'https://management.azure.com/subscriptions/.../resourceGroups/.../providers/Microsoft.App/jobs/.../start?api-version=2024-03-01'
Request method: 'POST'
Request headers:
    ... removing irrelevant headers ...
    'Content-Type': 'application/json'
    'CommandName': 'containerapp job start'
    'ParameterSetName': '--name --env-vars --command --image --resource-group --verbose'
Request body:
{
  "containers": [
    {
      "image": "...",
      "name": "...",
      "command": [
        "..."
      ],
      "args": null,
      "env": [
        ...
      ],
      "resources": null,
      "volumeMounts": null
    }
  ],
  "initContainers": null
}

The "volumeMounts": null is the main difference versus what the Azure Go SDK would generate, and my guess is that the API backend interprets null as "use the default volume mounts for the Container Apps Job", whereas it interprets the absence of the "volumeMounts" key as "don't add any mounts". I don't know if those semantics necessarily make sense, but they're my best guess as to what is actually happening.

I'm running github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3, but even the latest v3.1.0-beta doesn't contain a volumeMounts option