Skip to content

Commit

Permalink
Hotfix reverse proxy nil
Browse files Browse the repository at this point in the history
- Fixed an issue where if it failed to create a reverse proxy host it would break and return nil
- Fixed some issues on delete/create remote images
  • Loading branch information
cjlapao committed Nov 20, 2024
1 parent bdbcf46 commit 52d9ed3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/helpers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (c *HttpCaller) RequestDataToClient(verb HttpCallerVerb, url string, header
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-No-Cache", "true")
if headers != nil && len(*headers) > 0 {
for k, v := range *headers {
req.Header.Set(k, v)
Expand Down
21 changes: 10 additions & 11 deletions internal/remoteimage/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@ func (r *RemoteVmResource) Update(ctx context.Context, req resource.UpdateReques
resp.Diagnostics.Append(diag...)
return
}
apiclient.DeleteVm(ctx, hostConfig, data.ID.ValueString())
}
return
}
Expand Down Expand Up @@ -864,6 +863,16 @@ func (r *RemoteVmResource) Delete(ctx context.Context, req resource.DeleteReques
_ = common.RunPostProcessorScript(ctx, hostConfig, vm, data.OnDestroyScript)
}

if len(data.ReverseProxyHosts) > 0 {
rpHostConfig := hostConfig
rpHostConfig.HostId = vm.HostId
rpHostsCopy := reverseproxy.CopyReverseProxyHosts(data.ReverseProxyHosts)
if diag := reverseproxy.Delete(ctx, rpHostConfig, rpHostsCopy); diag.HasError() {
resp.Diagnostics.Append(diag...)
return
}
}

// Stopping the machine
if _, stopDiag := common.EnsureMachineStopped(ctx, hostConfig, vm); stopDiag.HasError() {
resp.Diagnostics.Append(stopDiag...)
Expand Down Expand Up @@ -897,16 +906,6 @@ func (r *RemoteVmResource) Delete(ctx context.Context, req resource.DeleteReques
time.Sleep(10 * time.Second)
}

if len(data.ReverseProxyHosts) > 0 {
rpHostConfig := hostConfig
rpHostConfig.HostId = vm.HostId
rpHostsCopy := reverseproxy.CopyReverseProxyHosts(data.ReverseProxyHosts)
if diag := reverseproxy.Delete(ctx, rpHostConfig, rpHostsCopy); diag.HasError() {
resp.Diagnostics.Append(diag...)
return
}
}

resp.Diagnostics.Append(req.State.Set(ctx, &data)...)

if resp.Diagnostics.HasError() {
Expand Down
5 changes: 5 additions & 0 deletions internal/schemas/reverseproxy/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ func updateHost(ctx context.Context, config apiclient.HostConfig, currentHost Re
if createDiag.HasError() {
diagnostic = append(diagnostic, createDiag...)
}
if r == nil {
errDiag := diag.NewErrorDiagnostic("Failed to create reverse proxy host", "The reverse proxy response was nil")
diagnostic = append(diagnostic, errDiag)
return requestHost, diagnostic
}

requestHost.ID = types.StringValue(r.ID)
return requestHost, diagnostic
Expand Down

0 comments on commit 52d9ed3

Please sign in to comment.