Skip to content

Commit

Permalink
added some more check errors (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjlapao authored Oct 14, 2024
1 parent bac7696 commit f1ae3da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion internal/common/check_required_specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -31,21 +32,33 @@ 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() {
diagnostics.Append(diag...)
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
}

Expand Down
7 changes: 7 additions & 0 deletions internal/helpers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion internal/remoteimage/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f1ae3da

Please sign in to comment.