diff --git a/internal/common/check_required_specs.go b/internal/common/check_required_specs.go index 78f0b75..128c284 100644 --- a/internal/common/check_required_specs.go +++ b/internal/common/check_required_specs.go @@ -2,6 +2,7 @@ package common import ( "context" + "fmt" "strconv" "strings" @@ -31,12 +32,19 @@ func CheckIfEnoughSpecs(ctx context.Context, hostConfig apiclient.HostConfig, sp diagnostics.Append(orchestratorDiag...) return diagnostics } + + foundArchitectureResources := false for _, orchestratorResource := range orchestratorResources { if strings.EqualFold(orchestratorResource.CpuType, arch) { hardwareInfo = orchestratorResource + foundArchitectureResources = true break } } + if !foundArchitectureResources { + diagnostics.AddError("error getting hardware info", fmt.Sprintf("error getting hardware info for %s architecture", arch)) + return diagnostics + } } else { hardwareInfo, diag = apiclient.GetSystemUsage(ctx, hostConfig) if diag.HasError() { @@ -44,8 +52,13 @@ func CheckIfEnoughSpecs(ctx context.Context, hostConfig apiclient.HostConfig, sp return diagnostics } } + if hardwareInfo == nil { - diagnostics.AddError("error getting hardware info", "error getting hardware info") + if diagnostics.HasError() { + return diagnostics + } else { + diagnostics.AddError("error getting hardware info", "error getting hardware info, hardware info is nil") + } return diagnostics } diff --git a/internal/helpers/client.go b/internal/helpers/client.go index 3132f2d..ef4883a 100644 --- a/internal/helpers/client.go +++ b/internal/helpers/client.go @@ -150,6 +150,13 @@ func (c *HttpCaller) RequestDataToClient(verb HttpCallerVerb, url string, header clientResponse.ApiError = &errMsg } } + // set a clientResponse.ApiError if it is nil + if clientResponse.ApiError == nil { + clientResponse.ApiError = &clientmodels.APIErrorResponse{ + Code: int64(response.StatusCode), + } + } + if clientResponse.ApiError.Message != "" { return &clientResponse, fmt.Errorf("error on %s data from %s, err: %v message: %v", verb, url, clientResponse.ApiError.Code, clientResponse.ApiError.Message) } else { diff --git a/internal/remoteimage/resource.go b/internal/remoteimage/resource.go index 4e4569a..6b4f457 100644 --- a/internal/remoteimage/resource.go +++ b/internal/remoteimage/resource.go @@ -133,8 +133,14 @@ func (r *RemoteVmResource) Create(ctx context.Context, req resource.CreateReques // before creating, if we have enough data we will be checking if we have enough resources // in the current host + // in the current host we will skip this if the host is an orchestrator if data.Specs != nil { - if diags := common.CheckIfEnoughSpecs(ctx, hostConfig, data.Specs, data.Architecture.ValueString()); diags.HasError() { + architecture := data.Architecture.ValueString() + if architecture == "" { + architecture = catalogManifest.Architecture + } + + if diags := common.CheckIfEnoughSpecs(ctx, hostConfig, data.Specs, architecture); diags.HasError() { resp.Diagnostics.Append(diags...) return }