question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Microsoft.Azure.Management.ContainerInstance.Models.InstanceView.CurrentState.State is always empty

See original GitHub issue

Library name and version

Assembly Microsoft.Azure.Management.ContainerInstance, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Describe the bug

I am trying to get the state of a Azure Container Group’s container, here is my code:

` IAzure azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(azureCredential).WithSubscription(_containerOptions.AzureSubscriptionId); var response = (await client.ContainerGroups.ListByResourceGroupWithHttpMessagesAsync(_containerOptions.ResourceGroup));

        foreach (var containerGroup in response.Body.Where(cg=>cg.ProvisioningState == "Succeeded" && 
            cg.Name.StartsWith(_containerOptions.AzureContainerPrefix, StringComparison.InvariantCultureIgnoreCase)))
        {
            If (containerGroup.Containers[0].InstanceView.CurrentState.State == "something")
            {
                   do something
            }

`

Expected behavior

Microsoft.Azure.Management.ContainerInstance.Models.InstanceView.CurrentState.State should return actual state of a container, such as Running, Failed, Terminated, etc

Actual behavior

It returns empty string

Reproduction Steps

deploy a container instance, using helloworld image. use the code above to get the state of that container

Environment

I run that code in Azure function

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jaltincommented, May 22, 2023

I think I found the solution to this in another issue (https://github.com/Azure/azure-sdk-for-net/issues/35764#issuecomment-1557153832).

@gb-8, can you try this? I am just typing here in github so haven’t tested it is 100% syntactically correct, but you get the idea:

string resourceGroupName = "xxxx";
var client = new ArmClient(new AzureCliCredential());
var subscription = await client.GetSubscriptions().GetAsync("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx", CancellationToken.None);
var resourceGroup = await subscription.Value.GetResourceGroups().CreateOrUpdateAsync(
    WaitUntil.Completed,
    resourceGroupName,
    new ResourceGroupData(AzureLocation.BrazilSouth)
);
var containerGroups = resourceGroup.Value.GetContainerGroups();

var firstContainerGroup = containerGroups.First();

// Getting container group state works as expected
var containerGroupState = firstContainerGroup.Data.ProvisioningState;

// Won't work as instanceView is null
var firstContainerInstanceView = firstContainerGroup.Data.Containers[0].InstanceView;

// Get access to the container data by using GetAsync()
var firstRetreivedContainerGroup = await firstContainerGroup.GetAsync()

// This will work, you can read state from the InstanceView or do whatever else you need from it
var retrievedFirstContainerInstanceView = firstRetreivedContainerGroup.Value.Data.Containers[0].InstanceView;
var containerState = retrievedFirstContainerInstanceView.CurrentState;

The key here is to call .GetAsync() on the containerGroup to load the full data.

I hope it works for you!

0reactions
github-actions[bot]commented, May 31, 2023

Hi @lidong-zhao, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot common issues - Azure Container Instances
This article shows how to troubleshoot common issues for managing or deploying containers to Azure Container Instances.
Read more >
Azure Container Instances states
In the Azure portal, state is shown in various locations. All state values are accessible via the JSON definition of the resource.
Read more >
Azure PowerShell release notes
Learn about all of the latest updates to the Azure PowerShell modules.
Read more >
Microsoft.Azure.Management.ContainerInstance.Models ...
Explore all classes and interfaces of the Microsoft.Azure.Management.ContainerInstance.Models namespace. ... The container instance state. DnsConfiguration.
Read more >
Get started guide for developers on Azure
Get started: Create a Linux VM or Windows VM from the Azure portal. ... This state represents the current state of the VM...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found