Skip to content

fix(azure): make location optional for spot allocation#840

Open
rishupk wants to merge 1 commit into
redhat-developer:mainfrom
rishupk:fix+azure-spot-location-optional
Open

fix(azure): make location optional for spot allocation#840
rishupk wants to merge 1 commit into
redhat-developer:mainfrom
rishupk:fix+azure-spot-location-optional

Conversation

@rishupk

@rishupk rishupk commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Azure spot allocation finds its own location, so there's no reason to require one at init time. A fix in #826 (commit 7c5d50d) changed DefaultHostingPlace() to hard-error when no location env var is set — that worked fine for on-demand but also fired for spot, breaking workflows that never needed it (see #839).

This restores the original nil, nil return with an info log. The non-spot path in allocation.go already enforces location when it actually matters.

Fixes #839.

Co-Authored-By: Claude <Sonnet 4.6> noreply@anthropic.com
Signed-off-by: Rishabh Kothari rkothari@redhat.com

Comment thread pkg/provider/azure/azure.go Outdated
}
return nil, fmt.Errorf("missing default value for Azure Location, set ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION environment variable")
logging.Infof("missing default value for Azure Location, if needed it should set using ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION")
return nil, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a check in the options to see if the execution is for spot or not,

  • No spot the location is mandatory as it should be used as the target location for the on demand. So error
  • Spot it will return nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ProviderOptionalLocation() — sets locationOptional: true on the Azure struct. DefaultHostingPlace() checks that flag before reading any env vars, so spot runs never get pinned to a location from the environment. Also applied this to all Destroy functions since teardown doesn't need a location and failing there would leave resources running.

@rishupk rishupk force-pushed the fix+azure-spot-location-optional branch from 353407c to f640601 Compare June 17, 2026 10:45
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rishupk, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 11 minutes and 31 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 04ee517c-0951-409e-8c28-a79fb334297f

📥 Commits

Reviewing files that changed from the base of the PR and between f640601 and bc96857.

📒 Files selected for processing (5)
  • pkg/provider/azure/action/aks/aks.go
  • pkg/provider/azure/action/kind/kind.go
  • pkg/provider/azure/action/linux/linux.go
  • pkg/provider/azure/action/windows/windows.go
  • pkg/provider/azure/azure.go
📝 Walkthrough

Walkthrough

Adds a spot boolean field to the Azure provider struct and a new ProviderForSpot() constructor. DefaultHostingPlace() returns nil early when spot is true. The four Create functions (aks, kind, linux, windows) now conditionally pass azure.ProviderForSpot() instead of azure.Provider() to mc.Init when spot is requested.

Changes

Azure Spot Provider Selection

Layer / File(s) Summary
Azure struct spot flag, ProviderForSpot, and DefaultHostingPlace short-circuit
pkg/provider/azure/azure.go
Azure struct gains a spot bool field. ProviderForSpot() returns an instance with spot: true. DefaultHostingPlace() returns (nil, nil) immediately when a.spot is true, skipping environment variable resolution.
Conditional provider selection in Create functions
pkg/provider/azure/action/aks/aks.go, pkg/provider/azure/action/kind/kind.go, pkg/provider/azure/action/linux/linux.go, pkg/provider/azure/action/windows/windows.go
Each Create function replaces the unconditional azure.Provider() call with a conditional: azure.ProviderForSpot() is passed to mc.Init when spot args are set and enabled, otherwise azure.Provider() is used.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making location optional for Azure spot allocation, which is the core objective of the PR.
Description check ✅ Passed The description accurately explains the regression, the root cause from PR #826, and how the fix restores optional location configuration for spot allocations.
Linked Issues check ✅ Passed The code changes successfully implement the fix for issue #839 by introducing a spot flag to distinguish provider behavior and making location optional for spot allocations.
Out of Scope Changes check ✅ Passed All changes are directly related to the scope of fixing the location requirement for spot allocations. Four action files and the core Azure provider file are consistently modified.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/provider/azure/azure.go (1)

42-53: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Spot mode should short-circuit before reading location env vars.

DefaultHostingPlace() still returns an env-derived location for spot runs when ARM_LOCATION_NAME/AZURE_DEFAULTS_LOCATION is set. Since mc.Init writes targetHostingPlace whenever this return is non-nil, spot flows can get unintentionally pinned instead of letting SpotInfo choose location.

Suggested fix
 func (a *Azure) DefaultHostingPlace() (*string, error) {
+	if a.spot {
+		logging.Info("Spot allocation enabled: skipping default Azure location resolution")
+		return nil, nil
+	}
+
 	hp := os.Getenv("ARM_LOCATION_NAME")
 	if len(hp) > 0 {
 		return &hp, nil
 	}
 	hp = os.Getenv("AZURE_DEFAULTS_LOCATION")
 	if len(hp) > 0 {
 		return &hp, nil
 	}
-	if a.spot {
-		return nil, nil
-	}
 	return nil, fmt.Errorf("missing default value for Azure Location, set ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION environment variable")
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provider/azure/azure.go` around lines 42 - 53, The spot mode check in the
DefaultHostingPlace method should occur before attempting to read the
environment variables ARM_LOCATION_NAME and AZURE_DEFAULTS_LOCATION. Move the
spot mode check (if a.spot { return nil, nil }) to the beginning of the
function, before reading any environment variables, so that spot runs
short-circuit immediately without being pinned to a location derived from these
env vars.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/provider/azure/azure.go`:
- Around line 42-53: The spot mode check in the DefaultHostingPlace method
should occur before attempting to read the environment variables
ARM_LOCATION_NAME and AZURE_DEFAULTS_LOCATION. Move the spot mode check (if
a.spot { return nil, nil }) to the beginning of the function, before reading any
environment variables, so that spot runs short-circuit immediately without being
pinned to a location derived from these env vars.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: b9a359d2-c21e-4960-8f98-8ad57c839b92

📥 Commits

Reviewing files that changed from the base of the PR and between 4519410 and f640601.

📒 Files selected for processing (5)
  • pkg/provider/azure/action/aks/aks.go
  • pkg/provider/azure/action/kind/kind.go
  • pkg/provider/azure/action/linux/linux.go
  • pkg/provider/azure/action/windows/windows.go
  • pkg/provider/azure/azure.go

@rishupk rishupk force-pushed the fix+azure-spot-location-optional branch from f640601 to 44fbb3d Compare June 17, 2026 11:07
…ructor

- Add locationOptional bool to Azure struct and ProviderOptionalLocation()
  constructor; DefaultHostingPlace() short-circuits before reading env vars
  when locationOptional is true, so spot runs are never pinned to a location
- Spot Create: uses ProviderOptionalLocation() — SpotInfo picks the location
- Destroy: uses ProviderOptionalLocation() — no location needed for teardown
- On-demand Create: uses Provider() — errors if no location env is set

Fixes redhat-developer#839.

Co-Authored-By: Claude <Sonnet 4.6> <noreply@anthropic.com>
Signed-off-by: Rishabh Kothari <rkothari@redhat.com>
@rishupk rishupk force-pushed the fix+azure-spot-location-optional branch from 949eab4 to bc96857 Compare June 17, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mandatory parameter ARM_LOCATION_HOME for azure

2 participants