Repository navigation
fix(azure): make ondemand pricing OS-aware for Windows nodes - #3820
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Windows-aware Azure pricing support by including OS in pricing keys and extracting separate Windows/Linux retail and spot prices from Azure Retail Prices API responses.
Changes:
- Generate distinct pricing keys for Windows nodes/meters (
,windowssuffix) inazureKey.Features()andconvertMeterToPricings()` - Extend Azure retail/spot price extraction to return separate Windows and Linux values and update retail price selection accordingly
- Update and add tests covering Windows key feature generation and Windows pricing extraction behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/cloud/azure/provider.go | Adds OS-aware pricing key construction and separates Windows vs Linux retail/spot price extraction + selection. |
| pkg/cloud/azure/provider_test.go | Updates pricing conversion expectations and adds tests for OS key formatting and Windows/Linux price extraction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@babbageclunk or @r2k1 would you be willing to review this change for OC? |
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
72a5ee6 to
73a134b
Compare
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
pkg/cloud/azure/provider.go:465
- Windows detection is implemented twice (in
azureKey.Features()and again inNodePricing). This duplication makes it easier for the two paths to drift (e.g., supported label keys, normalization rules). Consider centralizing OS detection (e.g., a helper onazureKeyor using the features string as the single source of truth) so there’s only one place to update the OS classification logic.
func (k *azureKey) Features() string {
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
Fixes opencost#3532 Signed-off-by: Varshith <[email protected]>
|



Fixes #3532
Description
Azure node pricing was OS-blind: azureKey.Features() produced a key of region,instance,ondemand with no OS component, the RateCard parser silently dropped all Windows VM meters, and the retail-price fallback filtered Windows products out entirely. Windows nodes always received Linux pricing.
This change makes all three layers OS-aware:
azureKey.Features() now appends
,windowsto the lookup key when the node carries kubernetes.io/os: windows (or deprecated beta.kubernetes.io/os label).convertMeterToPricings no longer drops Windows subcategory meters; stores them under region,instance,ondemand,windows keys instead.
extractAzureVMRetailAndSpotPrices now returns Linux and Windows retail/spot prices as separate values; getRetailPrice selects correct pair based on a new isWindows bool parameter.
NodePricing detects the OS label, builds OS-qualified lookup keys for spot nodes as well (region,instance,spot,windows), and passes isWindows to getRetailPrice.
Linux nodes and nodes with no OS label are unaffected, key format unchanged.
Related Issues
Fixes #3532
User Impact
Windows nodes on AKS (or any Azure Kubernetes cluster) will now receive Windows VM pricing rather than Linux pricing. No impact on Linux nodes.
Testing
New unit test TestAzureKeyFeaturesOS covers all label combinations (both OS label keys, Linux, no label, case-insensitive). Existing TestConvertMeterToPricings/windows updated to assert a Windows-keyed pricing entry is returned. Test_extractAzureVMRetailAndSpotPrices updated to assert both Linux and Windows prices are captured in the same API response.
=== RUN TestConvertMeterToPricings
=== RUN TestConvertMeterToPricings/windows
=== RUN TestConvertMeterToPricings/storage
{"level":"debug","time":"2026-05-27T14:21:30-05:00","message":"Adding PV.Key: useast,premium_ssd, Cost: 0.085616"}
=== RUN TestConvertMeterToPricings/virtual_machines
--- PASS: TestConvertMeterToPricings (0.00s)
--- PASS: TestConvertMeterToPricings/windows (0.00s)
--- PASS: TestConvertMeterToPricings/storage (0.00s)
--- PASS: TestConvertMeterToPricings/virtual_machines (0.00s)
=== RUN TestAzureKeyFeaturesOS
=== RUN TestAzureKeyFeaturesOS/windows_node_via_kubernetes.io/os
=== RUN TestAzureKeyFeaturesOS/windows_node_via_beta.kubernetes.io/os
=== RUN TestAzureKeyFeaturesOS/linux_node
=== RUN TestAzureKeyFeaturesOS/no_OS_label_defaults_to_linux_key
=== RUN TestAzureKeyFeaturesOS/windows_case-insensitive
--- PASS: TestAzureKeyFeaturesOS (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_node_via_kubernetes.io/os (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_node_via_beta.kubernetes.io/os (0.00s)
--- PASS: TestAzureKeyFeaturesOS/linux_node (0.00s)
--- PASS: TestAzureKeyFeaturesOS/no_OS_label_defaults_to_linux_key (0.00s)
--- PASS: TestAzureKeyFeaturesOS/windows_case-insensitive (0.00s)
=== RUN Test_extractAzureVMRetailAndSpotPrices
=== RUN Test_extractAzureVMRetailAndSpotPrices/valid_response_with_retail_and_spot_prices
=== RUN Test_extractAzureVMRetailAndSpotPrices/only_retail_price_available
=== RUN Test_extractAzureVMRetailAndSpotPrices/only_spot_price_available
=== RUN Test_extractAzureVMRetailAndSpotPrices/returns_separate_Windows_and_Linux_prices
=== RUN Test_extractAzureVMRetailAndSpotPrices/filters_out_low_priority_instances
=== RUN Test_extractAzureVMRetailAndSpotPrices/empty_items_array
=== RUN Test_extractAzureVMRetailAndSpotPrices/invalid_JSON
--- PASS: Test_extractAzureVMRetailAndSpotPrices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/valid_response_with_retail_and_spot_prices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/only_retail_price_available (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/only_spot_price_available (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/returns_separate_Windows_and_Linux_prices (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/filters_out_low_priority_instances (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/empty_items_array (0.00s)
--- PASS: Test_extractAzureVMRetailAndSpotPrices/invalid_JSON (0.00s)
PASS
ok github.com/opencost/opencost/pkg/cloud/azure 0.137s