Skip to content

Commit 7c5d50d

Browse files
rishupkclaude
authored andcommitted
fix(azure): align non-spot location handling with AWS pattern
- Fix DefaultHostingPlace() to return an error when neither ARM_LOCATION_NAME nor AZURE_DEFAULTS_LOCATION is set, matching AWS behavior (fail at mc.Init() rather than later) - Fix allocation.go non-spot path to fall back to mCtx.TargetHostingPlace() when args.Location is empty, so ARM_LOCATION_NAME is respected - Return a clear error if no compute sizes match the resolved location - Remove dead commented Location line from rhel-ai action Co-Authored-By: Claude <Sonnet 4.6> <noreply@anthropic.com> Signed-off-by: Rishabh Kothari <rkothari@redhat.com>
1 parent 47ddfb2 commit 7c5d50d

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

pkg/provider/azure/action/rhel-ai/rhelai.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ func Create(mCtxArgs *maptContext.ContextArgs, args *apiRHELAI.RHELAIArgs) (err
4242
}
4343
azureLinuxRequest :=
4444
&azureLinux.LinuxArgs{
45-
Prefix: args.Prefix,
46-
// Location: args.Location,
45+
Prefix: args.Prefix,
4746
ComputeRequest: args.ComputeRequest,
4847
Spot: args.Spot,
4948
ImageRef: &data.ImageReference{

pkg/provider/azure/azure.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ func (a *Azure) DefaultHostingPlace() (*string, error) {
4242
if len(hp) > 0 {
4343
return &hp, nil
4444
}
45-
logging.Infof("missing default value for Azure Location, if needed it should set using ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION")
46-
return nil, nil
45+
return nil, fmt.Errorf("missing default value for Azure Location, set ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION environment variable")
4746
}
4847

4948
// Envs required for auth with go sdk

pkg/provider/azure/modules/allocation/allocation.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package allocation
22

33
import (
4+
"fmt"
5+
46
mc "github.com/redhat-developer/mapt/pkg/manager/context"
57
cr "github.com/redhat-developer/mapt/pkg/provider/api/compute-request"
68
spotTypes "github.com/redhat-developer/mapt/pkg/provider/api/spot"
@@ -55,15 +57,26 @@ func Allocation(mCtx *mc.Context, args *AllocationArgs) (*AllocationResult, erro
5557
}, nil
5658

5759
} else {
60+
location := args.Location
61+
if location == nil || *location == "" {
62+
hp := mCtx.TargetHostingPlace()
63+
if hp == "" {
64+
return nil, fmt.Errorf("location is required for non-spot allocation: set ARM_LOCATION_NAME or AZURE_DEFAULTS_LOCATION environment variable")
65+
}
66+
location = &hp
67+
}
5868
// Filter for current location the computesizes
5969
supportedComputeSizes, err := data.FilterComputeSizesByLocation(
60-
mCtx.Context(), args.Location, computeSizes)
70+
mCtx.Context(), location, computeSizes)
6171
if err != nil {
6272
return nil, err
6373
}
74+
if len(supportedComputeSizes) == 0 {
75+
return nil, fmt.Errorf("no compute sizes available for location %q", *location)
76+
}
6477
return &AllocationResult{
6578
ImageRef: args.ImageRef,
66-
Location: args.Location,
79+
Location: location,
6780
ComputeSizes: supportedComputeSizes,
6881
}, nil
6982

0 commit comments

Comments
 (0)