Skip to content

Commit fb1105d

Browse files
authored
fix(vm): allow clone to pass with warnings (#1317)
Signed-off-by: Pavel Boldyrev <[email protected]>
1 parent 3f97a7b commit fb1105d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

proxmox/nodes/tasks/tasks.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"errors"
1212
"fmt"
1313
"net/http"
14+
"strings"
1415
"time"
1516

1617
"github.com/avast/retry-go/v4"
@@ -86,10 +87,36 @@ func (c *Client) DeleteTask(ctx context.Context, upid string) error {
8687
return nil
8788
}
8889

90+
type taskWaitOptions struct {
91+
ignoreWarnings bool
92+
}
93+
94+
// TaskWaitOption is an option for waiting for a task to complete.
95+
type TaskWaitOption interface {
96+
apply(opts *taskWaitOptions)
97+
}
98+
99+
type withIgnoreWarnings struct{}
100+
101+
// WithIgnoreWarnings is an option to ignore warnings when waiting for a task to complete.
102+
func WithIgnoreWarnings() TaskWaitOption {
103+
return withIgnoreWarnings{}
104+
}
105+
106+
func (w withIgnoreWarnings) apply(opts *taskWaitOptions) {
107+
opts.ignoreWarnings = true
108+
}
109+
89110
// WaitForTask waits for a specific task to complete.
90-
func (c *Client) WaitForTask(ctx context.Context, upid string) error {
111+
func (c *Client) WaitForTask(ctx context.Context, upid string, opts ...TaskWaitOption) error {
91112
errStillRunning := errors.New("still running")
92113

114+
options := &taskWaitOptions{}
115+
116+
for _, opt := range opts {
117+
opt.apply(options)
118+
}
119+
93120
status, err := retry.DoWithData(
94121
func() (*GetTaskStatusResponseData, error) {
95122
status, err := c.GetTaskStatus(ctx, upid)
@@ -132,6 +159,11 @@ func (c *Client) WaitForTask(ctx context.Context, upid string) error {
132159
}
133160

134161
if status.ExitCode != "OK" {
162+
if options.ignoreWarnings &&
163+
strings.HasPrefix(status.Status, "WARNINGS: ") && !strings.Contains(status.Status, "ERROR") {
164+
return nil
165+
}
166+
135167
return fmt.Errorf("task %q failed to complete with exit code: %s", upid, status.ExitCode)
136168
}
137169

proxmox/nodes/vms/vms.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/hashicorp/terraform-plugin-log/tflog"
2222

2323
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
24+
"github.com/bpg/terraform-provider-proxmox/proxmox/nodes/tasks"
2425
)
2526

2627
// CloneVM clones a virtual machine.
@@ -44,7 +45,8 @@ func (c *Client) CloneVM(ctx context.Context, retries int, d *CloneRequestBody)
4445
return api.ErrNoDataObjectInResponse
4546
}
4647

47-
return c.Tasks().WaitForTask(ctx, *resBody.Data)
48+
// ignoring warnings as per https://www.mail-archive.com/[email protected]/msg17724.html
49+
return c.Tasks().WaitForTask(ctx, *resBody.Data, tasks.WithIgnoreWarnings())
4850
}, retry.Attempts(uint(retries)), retry.Delay(10*time.Second))
4951
if err != nil {
5052
return fmt.Errorf("error waiting for VM clone: %w", err)

0 commit comments

Comments
 (0)