Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix kvm image not found err: set os image before actual qemu creation #177

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions cloud/scheduler/framework/cycle_state.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package framework

import (
"github.com/k8s-proxmox/proxmox-go/api"
"github.com/k8s-proxmox/proxmox-go/proxmox"
)

type CycleState struct {
completed bool
err error
Expand All @@ -13,9 +8,8 @@ type CycleState struct {
}

type SchedulerResult struct {
vmid int
node string
instance *proxmox.VirtualMachine
vmid int
node string
}

func NewCycleState() CycleState {
Expand Down Expand Up @@ -46,18 +40,14 @@ func (c *CycleState) Messages() map[string]string {
return c.messages
}

func (c *CycleState) QEMU() *api.VirtualMachine {
return c.result.instance.VM
}

func (c *CycleState) UpdateState(completed bool, err error, result SchedulerResult) {
c.completed = completed
c.err = err
c.result = result
}

func NewSchedulerResult(vmid int, node string, instance *proxmox.VirtualMachine) SchedulerResult {
return SchedulerResult{vmid: vmid, node: node, instance: instance}
func NewSchedulerResult(vmid int, node string) SchedulerResult {
return SchedulerResult{vmid: vmid, node: node}
}

func (c *CycleState) Result() SchedulerResult {
Expand All @@ -71,7 +61,3 @@ func (r *SchedulerResult) Node() string {
func (r *SchedulerResult) VMID() int {
return r.vmid
}

func (r *SchedulerResult) Instance() *proxmox.VirtualMachine {
return r.instance
}
9 changes: 1 addition & 8 deletions cloud/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ func (s *Scheduler) ScheduleOne(ctx context.Context) {
return
}

// actually create qemu
vm, err := s.client.CreateVirtualMachine(ctx, node, vmid, *config)
if err != nil {
state.UpdateState(true, err, framework.SchedulerResult{})
return
}

result := framework.NewSchedulerResult(vmid, node, vm)
result := framework.NewSchedulerResult(vmid, node)
state.UpdateState(true, nil, result)
}

Expand Down
4 changes: 2 additions & 2 deletions cloud/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ var _ = Describe("CreateQEMU", Label("integration"), func() {
})
Expect(err).ToNot(HaveOccurred())
Expect(result).ToNot(BeNil())
Expect(result.Node()).To(Equal(result.Instance().Node))
Expect(result.VMID()).To(Equal(result.Instance().VM.VMID))
Expect(result.Node()).ToNot(BeNil())
Expect(result.VMID()).ToNot(BeNil())
})
})
})
5 changes: 0 additions & 5 deletions cloud/services/compute/instance/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func (s *Service) reconcileBootDevice(ctx context.Context, vm *proxmox.VirtualMa
log := log.FromContext(ctx)
log.Info("reconciling boot device")

// os image
if err := s.setCloudImage(ctx); err != nil {
return err
}

// boot disk
log.Info("resizing boot disk")
if err := vm.ResizeVolume(ctx, bootDvice, s.scope.GetHardware().Disk); err != nil {
Expand Down
19 changes: 17 additions & 2 deletions cloud/services/compute/instance/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,25 @@ func (s *Service) createQEMU(ctx context.Context) (*proxmox.VirtualMachine, erro
schedCtx := framework.ContextWithMap(ctx, s.scope.Annotations())
result, err := s.scheduler.CreateQEMU(schedCtx, &vmoption)
if err != nil {
log.Error(err, "failed to create qemu instance")
log.Error(err, "failed to schedule qemu instance")
return nil, err
}
return result.Instance(), nil
node, vmid := result.Node(), result.VMID()
s.scope.SetNodeName(node)
s.scope.SetVMID(vmid)

// os image
if err := s.setCloudImage(ctx); err != nil {
return nil, err
}

// actually create qemu
vm, err := s.client.CreateVirtualMachine(ctx, node, vmid, vmoption)
if err != nil {
return nil, err
}

return vm, nil
}

func (s *Service) generateVMOptions() api.VirtualMachineCreateOptions {
Expand Down
Loading