Skip to content

Commit

Permalink
Merge pull request #4000 from mboersma/sdk-v2-async-cleanup
Browse files Browse the repository at this point in the history
Rename "asyncpoller" package to "async"
  • Loading branch information
k8s-ci-robot authored Sep 14, 2023
2 parents 09c96a7 + e5e60ff commit f261d6e
Show file tree
Hide file tree
Showing 53 changed files with 456 additions and 1,734 deletions.
6 changes: 3 additions & 3 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ type AgentPoolScope interface {
// Service provides operations on Azure resources.
type Service struct {
scope AgentPoolScope
asyncpoller.Reconciler
async.Reconciler
}

// New creates a new service.
Expand All @@ -63,7 +63,7 @@ func New(scope AgentPoolScope) (*Service, error) {
}
return &Service{
scope: scope,
Reconciler: asyncpoller.New[armcontainerservice.AgentPoolsClientCreateOrUpdateResponse,
Reconciler: async.New[armcontainerservice.AgentPoolsClientCreateOrUpdateResponse,
armcontainerservice.AgentPoolsClientDeleteResponse](scope, client, client),
}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions azure/services/agentpools/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
"sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (ac *azureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureCallTimeout)
defer cancel()

pollOpts := &runtime.PollUntilDoneOptions{Frequency: asyncpoller.DefaultPollerFrequency}
pollOpts := &runtime.PollUntilDoneOptions{Frequency: async.DefaultPollerFrequency}
resp, err := poller.PollUntilDone(ctx, pollOpts)
if err != nil {
// If an error occurs, return the poller.
Expand Down Expand Up @@ -118,7 +118,7 @@ func (ac *azureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecG
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureCallTimeout)
defer cancel()

pollOpts := &runtime.PollUntilDoneOptions{Frequency: asyncpoller.DefaultPollerFrequency}
pollOpts := &runtime.PollUntilDoneOptions{Frequency: async.DefaultPollerFrequency}
_, err = poller.PollUntilDone(ctx, pollOpts)
if err != nil {
// If an error occurs, return the poller.
Expand Down
255 changes: 105 additions & 150 deletions azure/services/async/async.go

Large diffs are not rendered by default.

574 changes: 179 additions & 395 deletions azure/services/async/async_test.go

Large diffs are not rendered by default.

32 changes: 11 additions & 21 deletions azure/services/async/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Kubernetes Authors.
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,25 +19,17 @@ package async
import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
azureautorest "github.com/Azure/go-autorest/autorest/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure"
)

// FutureScope is a scope that can perform store futures and conditions in Status.
// FutureScope stores and retrieves Futures and Conditions.
type FutureScope interface {
azure.AsyncStatusUpdater
}

// FutureHandler is a client that can check on the progress of a future.
type FutureHandler interface {
// IsDone returns true if the operation is complete.
IsDone(ctx context.Context, future azureautorest.FutureAPI) (isDone bool, err error)
// Result returns the result of the operation.
Result(ctx context.Context, future azureautorest.FutureAPI, futureType string) (result interface{}, err error)
}

// Getter is an interface that can get a resource.
// Getter gets a resource.
type Getter interface {
Get(ctx context.Context, spec azure.ResourceSpecGetter) (result interface{}, err error)
}
Expand All @@ -47,20 +39,18 @@ type TagsGetter interface {
GetAtScope(ctx context.Context, scope string) (result armresources.TagsResource, err error)
}

// Creator is a client that can create or update a resource asynchronously.
type Creator interface {
FutureHandler
// Creator creates or updates a resource asynchronously.
type Creator[T any] interface {
Getter
CreateOrUpdateAsync(ctx context.Context, spec azure.ResourceSpecGetter, parameters interface{}) (result interface{}, future azureautorest.FutureAPI, err error)
CreateOrUpdateAsync(ctx context.Context, spec azure.ResourceSpecGetter, resumeToken string, parameters interface{}) (result interface{}, poller *runtime.Poller[T], err error)
}

// Deleter is a client that can delete a resource asynchronously.
type Deleter interface {
FutureHandler
DeleteAsync(ctx context.Context, spec azure.ResourceSpecGetter) (future azureautorest.FutureAPI, err error)
// Deleter deletes a resource asynchronously.
type Deleter[T any] interface {
DeleteAsync(ctx context.Context, spec azure.ResourceSpecGetter, resumeToken string) (poller *runtime.Poller[T], err error)
}

// Reconciler is a generic interface used to perform asynchronous reconciliation of Azure resources.
// Reconciler reconciles a resource.
type Reconciler interface {
CreateOrUpdateResource(ctx context.Context, spec azure.ResourceSpecGetter, serviceName string) (result interface{}, err error)
DeleteResource(ctx context.Context, spec azure.ResourceSpecGetter, serviceName string) (err error)
Expand Down
Loading

0 comments on commit f261d6e

Please sign in to comment.