Skip to content

Commit

Permalink
Experiment: Refactoring Azure SDK Client into Wrapper (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
logyball authored Jul 25, 2024
1 parent 0bc00ba commit 17ae8c7
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ build-binary:
build: build-binary build-image

generate-mocks:
mockery --all
mockgen -source=pkg/provider/provider.go -destination pkg/provider/mocks/provider.go
mockgen -source=pkg/azure/azureClientWrapper/azureClientWrapper.go -destination mocks/pkg/azure/azureClientWrapper/azureClientWrapper.go

test: build
go test -v ./...
Expand Down
118 changes: 118 additions & 0 deletions mocks/pkg/azure/azureClientWrapper/azureClientWrapper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions pkg/azure/aks/aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/prometheus/client_golang/prometheus"

"github.com/grafana/cloudcost-exporter/pkg/azure/azureClientWrapper"
"github.com/grafana/cloudcost-exporter/pkg/provider"

cloudcost_exporter "github.com/grafana/cloudcost-exporter"
Expand Down Expand Up @@ -92,14 +93,10 @@ type Config struct {
SubscriptionId string
}

func New(ctx context.Context, cfg *Config) (*Collector, error) {
func New(ctx context.Context, cfg *Config, azClientWrapper azureClientWrapper.AzureClient) (*Collector, error) {
logger := cfg.Logger.With("collector", "aks")
priceStore, err := NewPricingStore(ctx, logger, cfg.SubscriptionId)
if err != nil {
return nil, err
}

machineStore, err := NewMachineStore(ctx, logger, priceStore.subscriptionId, cfg.Credentials)
priceStore := NewPricingStore(ctx, logger, azClientWrapper)
machineStore, err := NewMachineStore(ctx, logger, azClientWrapper)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 17ae8c7

Please sign in to comment.