Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get cloud config for go track2 sdk from resource manager endpoint #20959

Open
MartinForReal opened this issue Jun 5, 2023 · 2 comments
Open
Assignees
Labels
ARM - Core customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Milestone

Comments

@MartinForReal
Copy link
Contributor

MartinForReal commented Jun 5, 2023

Feature Request

In track2 go sdk, clould config can be fetched from resource manager endpoint.

https://github.com/Azure/go-autorest/blob/c2958ac74c65c138045daa60f149c5f9d949d743/autorest/azure/metadata_environment.go#L96-L141

I'm wondering if there is any utility available in track2 go sdk with which we can easily fetch cloud config from resource manager endpoint. Thanks!

Background: https://github.com/kubernetes-sigs/cloud-provider-azure/ is migrating sdk from track1 to track2.
cloud provider will accept a param which holds value of resource endpoint url.

https://github.com/kubernetes-sigs/cloud-provider-azure/blob/11f66ee392b34fe8958756188e5782ce6d448f91/pkg/provider/config/azure_auth.go#L76

If the param is set, the cloud provider will fetch endpoint info from arm resource which is serving at resource endpoint url.

https://github.com/kubernetes-sigs/cloud-provider-azure/blob/11f66ee392b34fe8958756188e5782ce6d448f91/pkg/provider/config/azure_auth.go#L268-L274

This feature is feasible when the application is running in air-gap environment and azurestack environment.

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 5, 2023
@tadelesh
Copy link
Member

tadelesh commented Jun 5, 2023

This is a request from AKS team. @chlowell do we have similar utils in track2? The return from /metadata/endpoints seems useful for hybrid cloud environment.

@github-actions github-actions bot removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jun 5, 2023
@chlowell
Copy link
Contributor

chlowell commented Jun 5, 2023

Track 2 doesn't have a helper like that. I don't see a reason not to add one. In the meantime, you can copy values from EnvironmentFromURL into a track 2 cloud.Configuration (see this doc for more about the API). Or, here's a sketch of a wholly track 2 solution:

import (
	"encoding/json"
	"io"
	"net/http"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
)

res, err := http.Get("https://management.azure.com/metadata/endpoints?api-version=2019-05-01")
if err != nil {
	// TODO
}
body, err := io.ReadAll(res.Body)
if err != nil {
	// TODO
}
md := []struct{
	Authentication struct{
		Audiences []string
		LoginEndpoint string
	}
	Name, ResourceManager string
}{}
err = json.Unmarshal(body, &md)
if err != nil {
	// TODO
}
c := cloud.Configuration{
	ActiveDirectoryAuthorityHost: md[0].Authentication.LoginEndpoint,
	Services: map[cloud.ServiceName]cloud.ServiceConfiguration{
		cloud.ResourceManager: {
			Audience: md[0].Authentication.Audiences[0],
			Endpoint: md[0].ResourceManager,
		},
	},
}
client, err := armsubscriptions.NewClient(
	// TODO: credential,
	&arm.ClientOptions{ClientOptions: policy.ClientOptions{Cloud: c}},
)

@chlowell chlowell added feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 5, 2023
@chlowell chlowell added this to the Backlog milestone Jun 5, 2023
@github-actions github-actions bot added the needs-team-attention This issue needs attention from Azure service team or SDK team label Jun 5, 2023
@chlowell chlowell removed the needs-team-attention This issue needs attention from Azure service team or SDK team label Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM - Core customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved.
Projects
None yet
Development

No branches or pull requests

3 participants