Skip to content

Commit

Permalink
Merge pull request #177 from k8s-proxmox/fix/kvm-image-not-found
Browse files Browse the repository at this point in the history
fix kvm image not found err: set os image before actual qemu creation
  • Loading branch information
sp-yduck authored Apr 25, 2024
2 parents a05c8c4 + 8237695 commit dff1aaf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
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

0 comments on commit dff1aaf

Please sign in to comment.