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

Remove last uses of old Azure SDK for Go #4425

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.20

require (
github.com/Azure/aad-pod-identity v1.8.17
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.4.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4 v4.6.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4 v4.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.2.0
Expand Down Expand Up @@ -61,6 +61,7 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/iothub/armiothub v1.3.0 h1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4.0 h1:HlZMUZW8S4P9oob1nCHxCCKrytxyLc+24nUJGssoEto=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/machinelearning/armmachinelearning v1.0.0 h1:KWvCVjnOTKCZAlqED5KPNoN9AfcK2BhUeveLdiwy33Q=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0 h1:Ds0KRF8ggpEGg4Vo42oX1cIt/IfOhHWJBikksZbVxeg=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.11.0/go.mod h1:jj6P8ybImR+5topJ+eH6fgcemSFBmU6/6bFF8KkwuDI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0 h1:z4YeiSXxnUI+PqB46Yj6MZA3nwb1CcJIkEMDrzUd8Cs=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.2.0/go.mod h1:rko9SzMxcMk0NJsNAxALEGaTYyy79bNRwxgJfrH0Spw=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4 v4.3.0 h1:bXwSugBiSbgtz7rOtbfGf+woewp4f06orW9OP5BjHLA=
Expand Down
48 changes: 22 additions & 26 deletions test/e2e/azure_clusterproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"time"

aadpodv1 "github.com/Azure/aad-pod-identity/pkg/apis/aadpodidentity/v1"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand All @@ -46,7 +46,6 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"
)
Expand All @@ -55,9 +54,9 @@ type (
AzureClusterProxy struct {
framework.ClusterProxy
}
// myEventData is used to be able to Marshal insights.EventData into JSON
// myEventData is used to be able to Marshal armmonitor.EventData into JSON
// see https://github.com/Azure/azure-sdk-for-go/issues/8224#issuecomment-614777550
myEventData insights.EventData
myEventData armmonitor.EventData
)

func NewAzureClusterProxy(name string, kubeconfigPath string, options ...framework.Option) *AzureClusterProxy {
Expand Down Expand Up @@ -224,13 +223,11 @@ func (acp *AzureClusterProxy) collectNodes(ctx context.Context, namespace string
func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace, name, aboveMachinesPath string) {
timeoutctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
settings, err := auth.GetSettingsFromEnvironment()

cred, err := azidentity.NewDefaultAzureCredential(nil)
Expect(err).NotTo(HaveOccurred())
subscriptionID := settings.GetSubscriptionID()
authorizer, err := azureutil.GetAuthorizer(settings)
activityLogsClient, err := armmonitor.NewActivityLogsClient(getSubscriptionID(Default), cred, nil)
Expect(err).NotTo(HaveOccurred())
activityLogsClient := insights.NewActivityLogsClient(subscriptionID)
activityLogsClient.Authorizer = authorizer

var groupName string
clusterClient := acp.GetClient()
Expand All @@ -255,12 +252,8 @@ func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace
start := time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339)
end := time.Now().UTC().Format(time.RFC3339)

itr, err := activityLogsClient.ListComplete(timeoutctx, fmt.Sprintf("eventTimestamp ge '%s' and eventTimestamp le '%s' and resourceGroupName eq '%s'", start, end, groupName), "")
if err != nil {
// Failing to fetch logs should not cause the test to fail
Logf("Error fetching activity logs for resource group %s: %v", groupName, err)
return
}
filter := fmt.Sprintf("eventTimestamp ge '%s' and eventTimestamp le '%s' and resourceGroupName eq '%s'", start, end, groupName)
pager := activityLogsClient.NewListPager(filter, nil)

logFile := path.Join(aboveMachinesPath, activitylog, groupName+".log")
Expect(os.MkdirAll(filepath.Dir(logFile), 0o755)).To(Succeed())
Expand All @@ -275,19 +268,22 @@ func (acp *AzureClusterProxy) collectActivityLogs(ctx context.Context, namespace
out := bufio.NewWriter(f)
defer out.Flush()

for ; itr.NotDone(); err = itr.NextWithContext(timeoutctx) {
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
Logf("Got error while iterating over activity logs for resource group %s: %v", groupName, err)
// Failing to fetch logs should not cause the test to fail
Logf("Error getting pager for activity logs in resource group %s: %v", groupName, err)
return
}
event := itr.Value()
if ptr.Deref(event.Category.Value, "") != "Policy" {
b, err := json.MarshalIndent(myEventData(event), "", " ")
if err != nil {
Logf("Got error converting activity logs data to json: %v", err)
}
if _, err = out.WriteString(string(b) + "\n"); err != nil {
Logf("Got error while writing activity logs for resource group %s: %v", groupName, err)
for _, event := range page.Value {
if ptr.Deref(event.Category.Value, "") != "Policy" {
b, err := json.MarshalIndent(myEventData(*event), "", " ")
if err != nil {
Logf("Got error converting activity logs data to json: %v", err)
}
if _, err = out.WriteString(string(b) + "\n"); err != nil {
Logf("Got error while writing activity logs for resource group %s: %v", groupName, err)
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package version
import (
"fmt"
"runtime"

azuresdkversion "github.com/Azure/azure-sdk-for-go/version"
)

var (
Expand Down Expand Up @@ -58,7 +56,7 @@ func Get() Info {
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
AzureSdkVersion: azuresdkversion.Number,
AzureSdkVersion: "SDK track2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no single version string provided any longer for the SDK (except arguably in an internal package that's not accessible). So I think all we can do is hard-code it from now on.

}
}

Expand Down