Azure / azure-libraries-for-net

Azure libraries for .Net
MIT License
380 stars 192 forks source link

[BUG]Cannot retrieve InstanceView of Azure Container Instance #657

Open kurtzeborn opened 5 years ago

kurtzeborn commented 5 years ago

@yuriwoof commented on Sun May 05 2019

Describe the bug Customer can get "instanceView" of ACI about 5 months ago but they cannot retrieve them without changing package version. On the other hands, they can get that property using Azure CLI and Azure portal.

Exception or Stack Trace None of the exceptions occurs.

To Reproduce

  1. Install relating packages.

Below command get the latest package but other versions get the same result.

dotnet add package Microsoft.Azure.Management.ContainerInstance.Fluent
dotnet add package Microsoft.Azure.Management.ResourceManager.Fluent --version 1.21.0
dotnet add package Microsoft.Azure.Services.AppAuthentication --version 1.0.3
  1. Run code
dotnet run

Code Snippet

using System.Linq;
using Microsoft.Azure.Management.ContainerInstance.Fluent;
using Microsoft.Azure.Management.ContainerInstance.Fluent.Models;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Rest;
using System.Threading.Tasks;
using System;

namespace aciApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string tenantId = "<Tenant Id>";
            string subscriptionId = "<Subscription Id>";
            string resourceGroupName = "<Resource Group Name";

            var azureServiceTokenProvider = new AzureServiceTokenProvider(); // via MSI
            var armToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/", tenantId).ConfigureAwait(false);
            var graphToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://graph.windows.net/", tenantId).ConfigureAwait(false);
            var credentials = new AzureCredentials(
                    new TokenCredentials(armToken),
                    new TokenCredentials(graphToken),
                    tenantId,
                    AzureEnvironment.AzureGlobalCloud)
                .WithDefaultSubscription(subscriptionId);

            var restClient = RestClient.Configure()
                .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .WithCredentials(credentials)
                .Build();

            var containerInstanceClient = new ContainerInstanceManagementClient(restClient)
            {
                SubscriptionId = restClient.Credentials.DefaultSubscriptionId
            };
            var instances = await containerInstanceClient.ContainerGroups.ListByResourceGroupAsync(resourceGroupName);

            foreach (var i in instances)
            {

                Console.WriteLine("*****");
                //List<Container> cointainers = i.Containers as List<Container>;
                Console.WriteLine(i.Containers.Count.ToString());
                Console.WriteLine(i.Containers.FirstOrDefault()?.Name);
                Console.WriteLine(i.Containers.FirstOrDefault()?.InstanceView?.CurrentState?.State);
                Console.WriteLine(i.Containers.FirstOrDefault()?.InstanceView?.CurrentState?.DetailStatus);
                Console.WriteLine("*****");
            }
        }
    }
}

The output is following.

*****
1
test1

*****

Expected behavior

The expected output is here.

*****
1
test1
Terminated
Completed
*****

Thought Azure CLI can get those properties.

$ az container show --name test1 --resource-group <Resource Group Name>
{
  "containers": [
    {
      "command": null,
      "environmentVariables": [],
      "image": "mcr.microsoft.com/azuredocs/aci-wordcount:latest",
      "instanceView": {
        "currentState": {
          "detailStatus": "Completed",
          "exitCode": 0,
          "finishTime": "2019-04-28T07:09:26+00:00",
          "startTime": "2019-04-28T07:09:23+00:00",
          "state": "Terminated"
        },

Screenshots N/A

Setup (please complete the following information):

$ dotnet --list-sdks
2.2.203 [/usr/share/dotnet/sdk]

csproj file
...
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Management.ContainerInstance.Fluent" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.0.3" />
    <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.1" />
    <PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.20" />
    <PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.3.7" />
  </ItemGroup>

Additional context N/A

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report


@kurtzeborn commented on Mon May 06 2019

Thank you for opening this issue! We are routing it to the appropriate team for follow up.

kurtzeborn commented 5 years ago

Moving this to the correct repo for fluent APIs...

yuriwoof commented 5 years ago

@kurtzeborn Thank you for acknowledging and routing!

nickzhums commented 4 years ago

@yuriwoof Hi Yuri are you still experiencing the problem?