Skip to content

Commit d0207f5

Browse files
authored
fix: bug with pricing provider not being launched (#1137)
1 parent 38ea60b commit d0207f5

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

pkg/auth/environment.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ func EnvironmentFromName(cloudName string) (*Environment, error) {
130130
}, nil
131131
}
132132

133+
// IsPublic returns if the specified configuration is public.
134+
// This takes the track2 format rather than being a method on Environment because
135+
// usage in api/sdk contexts use the track2 format and may not have access to the
136+
// auth.Environment struct.
137+
func IsPublic(env cloud.Configuration) bool {
138+
endpointA := strings.TrimRight(env.Services[cloud.ResourceManager].Endpoint, "/")
139+
endpointB := strings.TrimRight(cloud.AzurePublic.Services[cloud.ResourceManager].Endpoint, "/")
140+
return strings.EqualFold(endpointA, endpointB) // Shouldn't differ by case but let's be safe
141+
}
142+
133143
// ResolveCloudEnvironment resolves the cloud environment using the following precedence:
134144
// 1. File-based environment (AZURE_ENVIRONMENT_FILEPATH)
135145
// 2. Known cloud names (ARM_CLOUD)

pkg/providers/pricing/client/pricingapi.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727

2828
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
29+
"github.com/Azure/karpenter-provider-azure/pkg/auth"
2930
)
3031

3132
const (
@@ -48,7 +49,7 @@ func New(cloud cloud.Configuration) PricingAPI {
4849
func (papi *pricingAPI) GetProductsPricePages(_ context.Context, filters []*Filter, pageHandler func(output *ProductsPricePage)) error {
4950
nextURL := pricingURL
5051

51-
if papi.cloud.Services[cloud.ResourceManager].Endpoint != cloud.AzurePublic.Services[cloud.ResourceManager].Endpoint {
52+
if !auth.IsPublic(papi.cloud) {
5253
// If the cloud is not Azure Public, the pricing API isn't supported and we return an error
5354
return fmt.Errorf("pricing API is not supported in non-public clouds")
5455
}

pkg/providers/pricing/pricing.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ func NewProvider(
9494
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithName("pricing").WithValues("region", region))
9595

9696
// Only poll in public cloud. Other clouds aren't supported currently
97-
if env.Cloud.Services[cloud.ResourceManager].Endpoint == cloud.AzurePublic.Services[cloud.ResourceManager].Endpoint {
97+
if auth.IsPublic(env.Cloud) {
9898
go func() {
99+
log.FromContext(ctx).V(0).Info("starting pricing update loop")
99100
// perform an initial price update at startup
100101
p.updatePricing(ctx)
101102

pkg/providers/pricing/suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func TestAzure(t *testing.T) {
4949

5050
var _ = BeforeSuite(func() {
5151
fakePricingAPI = &fake.PricingAPI{}
52-
env = &auth.Environment{
53-
Cloud: cloud.AzurePublic,
54-
}
52+
var err error
53+
env, err = auth.EnvironmentFromName("AzurePublicCloud")
54+
Expect(err).ToNot(HaveOccurred())
5555
})
5656

5757
var _ = BeforeEach(func() {

0 commit comments

Comments
 (0)