Azure / azure-libraries-for-net

Azure libraries for .Net
MIT License
377 stars 190 forks source link

azure.ContainerGroups.ListByResourceGroup is difficult to use when resources are being deleted #575

Open CoenraadS opened 5 years ago

CoenraadS commented 5 years ago

Hello

In our environment we are constantly creating and deleting containers. Sometimes we also want to list through current containers using

azure.ContainerGroups.ListByResourceGroup

However if a resource is deleted, the enumerator can no longer iterate (e.g. even doing .ToList() will throw cloud exception). The work around is to use something like:

    private static List<IContainerGroup> getContainerInstances(IAzure azure, string resouceGroup)
    {
        var brokenEnumerator = azure.ContainerGroups.ListByResourceGroup(resouceGroup).GetEnumerator();
        var containerInstances = new List<IContainerGroup>();

        while (true)
        {
            try
            {
                if (!brokenEnumerator.MoveNext())
                {
                    break;
                }
                containerInstances.Add(brokenEnumerator.Current);
            }
            catch (CloudException)
            {
                // noop
            }
        }

        return containerInstances;
    }

imo the api should always be enumerable even if the resource was deleted

praries880 commented 5 years ago

@CoenraadS What is the SDK version you are using here?

Does the enumeration always break when it gets to a deleted container?