Azure/azure-sdk-for-go

Empty LoadBalancer FrontendIPConfiguration for Private and Public Addresses

dnaeon opened this issue · 4 comments

Bug Report

Trying to get the FrontendIPConfiguration for Load Balancers returns empty results for private and public IP addresses.

Sample Go code to reproduce the issue.

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	armnetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
)

func printErr(err error) {
	fmt.Println(err)
	os.Exit(1)
}

func main() {
	clientID := "my-app-uuid"      
	tenantID := "my-tenant-uuid"  
	subscriptionID := "my-subscription-uuid"
	resourceGroup := "my-resource-group-name"

	tokenFile := "kube-token.txt"
	opts := &azidentity.WorkloadIdentityCredentialOptions{
		AdditionallyAllowedTenants: []string{},
		ClientID:                   clientID,
		TenantID:                   tenantID,
		TokenFilePath:              tokenFile,
	}

	creds, err := azidentity.NewWorkloadIdentityCredential(opts)
	if err != nil {
		printErr(err)
	}

	ctx := context.Background()
	printLoadBalancers(ctx, creds, subscriptionID, resourceGroup)
}

func printLoadBalancers(ctx context.Context, creds azcore.TokenCredential, subscriptionID string, resourceGroup string) {
	factory, err := armnetwork.NewClientFactory(subscriptionID, creds, &arm.ClientOptions{})
	if err != nil {
		printErr(err)
	}

	client := factory.NewLoadBalancersClient()
	pager := client.NewListPager(resourceGroup, &armnetwork.LoadBalancersClientListOptions{})
	for pager.More() {
		page, err := pager.NextPage(ctx)
		if err != nil {
			printErr(err)
		}

		for _, item := range page.Value {
			fmt.Printf("ID: %s\n", *item.ID)
			fmt.Printf("\tLocation: %s\n", *item.Location)
			fmt.Printf("\tName: %s\n", *item.Name)
			fmt.Printf("\tEtag: %s\n", *item.Etag)
			fmt.Printf("\tType: %s\n", *item.Type)
			fmt.Printf("\tSKU Name: %s\n", *item.SKU.Name)
			fmt.Printf("\tSKU Tier: %s\n\n", *item.SKU.Tier)

			for _, frontend := range item.Properties.FrontendIPConfigurations {
				if frontend.Properties != nil {
					fmt.Printf("\t\tName: %s\n", *frontend.Name)
					fmt.Printf("\t\tPrivate IP: %v\n", frontend.Properties.PrivateIPAddress)
					fmt.Printf("\t\tPublic IP: %v\n", frontend.Properties.PublicIPAddress.Properties)
				}
			}
		}
	}
}

Running this code gives results like this where the PrivateIP and PublicIP are nil.

...
...

                Name: name-1
                Private IP: <nil>
                Public IP: <nil>
                Name: name-2
                Private IP: <nil>
                Public IP: <nil>
                Name: name-3
                Private IP: <nil>
                Public IP: <nil>
                Name: name-4
                Private IP: <nil>
                Public IP: <nil>

I get the same empty results even when using armnetwork.LoadBalancerFrontendIPConfigurationsClient and querying a specific Load Balancer in order to get its FrontendIPConfiguration.

Thanks,
Marin

@dnaeon, have you tried to call the REST API directly to list all the load balancer and check the result?
I am trying to understand whether this is a service side issue or client SDK issue. thanks

Hey @lirenhe ,

Using az network lb list returns the LBs with correct info. I haven't tried calling the REST API directly. This one appears to be an issue with the Go SDK.

Thanks!

@dnaeon cli has different logic to sdk. if the rest response does not contain the value you needed, sdk will not do any additional call to get that like cli.