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

azure: Upgrade dependencies for armcontainerservice #48

Merged
merged 1 commit into from
Sep 29, 2023
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 .github/workflows/kubectl-aks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Azure Kubernetes Service kubectl plugin CI
env:
GO_VERSION: 1.17 # TODO: Update
GO_VERSION: 1.18
AZURE_PREFIX: kubectl-aks-ci
concurrency:
# Only one workflow can run at a time unless
Expand Down Expand Up @@ -242,6 +242,7 @@ jobs:
run: |
export AZURE_RESOURCE_GROUP=${{ env.AZURE_PREFIX }}-rg
export AZURE_CLUSTER_NAME=${{ env.AZURE_PREFIX }}-${{ matrix.arch }}-cluster
export AZURE_SUBSCRIPTION_ID=${{ secrets.AZURE_AKS_SUBSCRIPTION_ID }}
make integration-test -o kubectl-aks

release:
Expand Down
9 changes: 5 additions & 4 deletions cmd/utils/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"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/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
Expand Down Expand Up @@ -68,7 +69,7 @@ func newCachedInteractiveBrowserCredential() (*cachedInteractiveBrowserCredentia

client, err := public.New(developerSignOnClientID,
public.WithCache(&tokenCache{file: file}),
public.WithAuthority(runtime.JoinPaths(string(azidentity.AzurePublicCloud), organizationsTenantID)),
public.WithAuthority(runtime.JoinPaths(cloud.AzurePublic.ActiveDirectoryAuthorityHost, organizationsTenantID)),
)
if err != nil {
return nil, fmt.Errorf("creating public client: %w", err)
Expand All @@ -78,7 +79,7 @@ func newCachedInteractiveBrowserCredential() (*cachedInteractiveBrowserCredentia
}

// GetToken implements the azcore.TokenCredential interface on cachedInteractiveBrowserCredential.
func (c *cachedInteractiveBrowserCredential) GetToken(ctx context.Context, options policy.TokenRequestOptions) (*azcore.AccessToken, error) {
func (c *cachedInteractiveBrowserCredential) GetToken(ctx context.Context, options policy.TokenRequestOptions) (azcore.AccessToken, error) {
// TODO: may be this can be improved with https://github.com/Azure/kubectl-aks/issues/11
var account public.Account
if len(c.client.Accounts()) > 0 {
Expand All @@ -88,10 +89,10 @@ func (c *cachedInteractiveBrowserCredential) GetToken(ctx context.Context, optio
if err != nil {
result, err = c.client.AcquireTokenInteractive(ctx, options.Scopes)
if err != nil {
return nil, fmt.Errorf("acquiring interactive token: %w", err)
return azcore.AccessToken{}, fmt.Errorf("acquiring interactive token: %w", err)
}
}
return &azcore.AccessToken{Token: result.AccessToken, ExpiresOn: result.ExpiresOn}, nil
return azcore.AccessToken{Token: result.AccessToken, ExpiresOn: result.ExpiresOn}, nil
}

// tokenCache implements basic file based cache.ExportReplace to be used with the public.Client.
Expand Down
53 changes: 34 additions & 19 deletions cmd/utils/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice"
"github.com/Azure/go-autorest/autorest/to"
Expand Down Expand Up @@ -135,26 +136,36 @@ func VirtualMachineScaleSetVMsViaAzureAPI(subID, rg, clusterName string) (map[st
}

ctx := context.Background()
aksClient := armcontainerservice.NewManagedClustersClient(subID, creds, nil)
aksClient, err := armcontainerservice.NewManagedClustersClient(subID, creds, nil)
if err != nil {
return nil, fmt.Errorf("creating AKS client: %w", err)
}
cluster, err := aksClient.Get(ctx, rg, clusterName, nil)
if err != nil {
return nil, fmt.Errorf("getting cluster: %w", err)
}
var nodePools []string
vmssClient := armcompute.NewVirtualMachineScaleSetsClient(subID, creds, nil)
nodePoolPager := vmssClient.List(to.String(cluster.Properties.NodeResourceGroup), nil)
for nodePoolPager.NextPage(ctx) {
for _, np := range nodePoolPager.PageResponse().Value {
vmssClient, err := armcompute.NewVirtualMachineScaleSetsClient(subID, creds, nil)
if err != nil {
return nil, fmt.Errorf("creating VMSS client: %w", err)
}
nodePoolPager := vmssClient.NewListPager(to.String(cluster.Properties.NodeResourceGroup), nil)
for nodePoolPager.More() {
nextResult, err := nodePoolPager.NextPage(ctx)
if err != nil {
return nil, fmt.Errorf("getting next page of node pools: %w", err)
}
for _, np := range nextResult.Value {
nodePools = append(nodePools, to.String(np.Name))
}
}
if err = nodePoolPager.Err(); err != nil {
return nil, fmt.Errorf("getting node pools: %w", err)
}
vmssVMs := make(map[string]*VirtualMachineScaleSetVM)
vmClient := armcompute.NewVirtualMachineScaleSetVMsClient(subID, creds, nil)
vmClient, err := armcompute.NewVirtualMachineScaleSetVMsClient(subID, creds, nil)
if err != nil {
return nil, fmt.Errorf("creating VMSS VMs client: %w", err)
}
for _, np := range nodePools {
instances, err := instancesForNodePool(vmClient, np, to.String(cluster.Properties.NodeResourceGroup))
instances, err := instancesForNodePool(ctx, vmClient, np, to.String(cluster.Properties.NodeResourceGroup))
if err != nil {
return nil, fmt.Errorf("getting instances for node pool %q: %w", np, err)
}
Expand All @@ -171,14 +182,15 @@ func VirtualMachineScaleSetVMsViaAzureAPI(subID, rg, clusterName string) (map[st
return vmssVMs, nil
}

func instancesForNodePool(vmClient *armcompute.VirtualMachineScaleSetVMsClient, pool, resourceGroup string) ([]*armcompute.VirtualMachineScaleSetVM, error) {
func instancesForNodePool(ctx context.Context, vmClient *armcompute.VirtualMachineScaleSetVMsClient, pool, resourceGroup string) ([]*armcompute.VirtualMachineScaleSetVM, error) {
var instances []*armcompute.VirtualMachineScaleSetVM
pager := vmClient.List(resourceGroup, pool, nil)
for pager.NextPage(context.Background()) {
instances = append(instances, pager.PageResponse().Value...)
}
if err := pager.Err(); err != nil {
return nil, err
pager := vmClient.NewListPager(resourceGroup, pool, nil)
for pager.More() {
nextPage, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
instances = append(instances, nextPage.Value...)
}
return instances, nil
}
Expand Down Expand Up @@ -213,7 +225,10 @@ func RunCommand(
timeout = to.IntPtr(DefaultRunCommandTimeoutInSeconds)
}

client := armcompute.NewVirtualMachineScaleSetVMsClient(vm.SubscriptionID, cred, nil)
client, err := armcompute.NewVirtualMachineScaleSetVMsClient(vm.SubscriptionID, cred, nil)
if err != nil {
return nil, fmt.Errorf("creating VMSS VMs client: %w", err)
}

// By default, the Azure API limits the output to the last 4,096 bytes. See
// https://learn.microsoft.com/en-us/azure/virtual-machines/linux/run-command#restrictions.
Expand Down Expand Up @@ -249,7 +264,7 @@ func RunCommand(
return nil, fmt.Errorf("begin running command: %w", err)
}

res, err := poller.PollUntilDone(ctx, pollingFreq)
res, err := poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{Frequency: pollingFreq})
if err != nil {
return nil, fmt.Errorf("polling command response: %w", err)
}
Expand Down
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/Azure/kubectl-aks

go 1.17
go 1.18

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.13.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v0.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v0.3.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice v1.0.0
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0
github.com/briandowns/spinner v1.23.0
Expand All @@ -20,8 +20,7 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go v61.1.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
Expand Down
Loading
Loading