Skip to content

Commit dff1aaf

Browse files
authored
Merge pull request #177 from k8s-proxmox/fix/kvm-image-not-found
fix kvm image not found err: set os image before actual qemu creation
2 parents a05c8c4 + 8237695 commit dff1aaf

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

cloud/scheduler/framework/cycle_state.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package framework
22

3-
import (
4-
"github.com/k8s-proxmox/proxmox-go/api"
5-
"github.com/k8s-proxmox/proxmox-go/proxmox"
6-
)
7-
83
type CycleState struct {
94
completed bool
105
err error
@@ -13,9 +8,8 @@ type CycleState struct {
138
}
149

1510
type SchedulerResult struct {
16-
vmid int
17-
node string
18-
instance *proxmox.VirtualMachine
11+
vmid int
12+
node string
1913
}
2014

2115
func NewCycleState() CycleState {
@@ -46,18 +40,14 @@ func (c *CycleState) Messages() map[string]string {
4640
return c.messages
4741
}
4842

49-
func (c *CycleState) QEMU() *api.VirtualMachine {
50-
return c.result.instance.VM
51-
}
52-
5343
func (c *CycleState) UpdateState(completed bool, err error, result SchedulerResult) {
5444
c.completed = completed
5545
c.err = err
5646
c.result = result
5747
}
5848

59-
func NewSchedulerResult(vmid int, node string, instance *proxmox.VirtualMachine) SchedulerResult {
60-
return SchedulerResult{vmid: vmid, node: node, instance: instance}
49+
func NewSchedulerResult(vmid int, node string) SchedulerResult {
50+
return SchedulerResult{vmid: vmid, node: node}
6151
}
6252

6353
func (c *CycleState) Result() SchedulerResult {
@@ -71,7 +61,3 @@ func (r *SchedulerResult) Node() string {
7161
func (r *SchedulerResult) VMID() int {
7262
return r.vmid
7363
}
74-
75-
func (r *SchedulerResult) Instance() *proxmox.VirtualMachine {
76-
return r.instance
77-
}

cloud/scheduler/scheduler.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,7 @@ func (s *Scheduler) ScheduleOne(ctx context.Context) {
221221
return
222222
}
223223

224-
// actually create qemu
225-
vm, err := s.client.CreateVirtualMachine(ctx, node, vmid, *config)
226-
if err != nil {
227-
state.UpdateState(true, err, framework.SchedulerResult{})
228-
return
229-
}
230-
231-
result := framework.NewSchedulerResult(vmid, node, vm)
224+
result := framework.NewSchedulerResult(vmid, node)
232225
state.UpdateState(true, nil, result)
233226
}
234227

cloud/scheduler/scheduler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ var _ = Describe("CreateQEMU", Label("integration"), func() {
115115
})
116116
Expect(err).ToNot(HaveOccurred())
117117
Expect(result).ToNot(BeNil())
118-
Expect(result.Node()).To(Equal(result.Instance().Node))
119-
Expect(result.VMID()).To(Equal(result.Instance().VM.VMID))
118+
Expect(result.Node()).ToNot(BeNil())
119+
Expect(result.VMID()).ToNot(BeNil())
120120
})
121121
})
122122
})

cloud/services/compute/instance/image.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func (s *Service) reconcileBootDevice(ctx context.Context, vm *proxmox.VirtualMa
2222
log := log.FromContext(ctx)
2323
log.Info("reconciling boot device")
2424

25-
// os image
26-
if err := s.setCloudImage(ctx); err != nil {
27-
return err
28-
}
29-
3025
// boot disk
3126
log.Info("resizing boot disk")
3227
if err := vm.ResizeVolume(ctx, bootDvice, s.scope.GetHardware().Disk); err != nil {

cloud/services/compute/instance/qemu.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,25 @@ func (s *Service) createQEMU(ctx context.Context) (*proxmox.VirtualMachine, erro
7878
schedCtx := framework.ContextWithMap(ctx, s.scope.Annotations())
7979
result, err := s.scheduler.CreateQEMU(schedCtx, &vmoption)
8080
if err != nil {
81-
log.Error(err, "failed to create qemu instance")
81+
log.Error(err, "failed to schedule qemu instance")
8282
return nil, err
8383
}
84-
return result.Instance(), nil
84+
node, vmid := result.Node(), result.VMID()
85+
s.scope.SetNodeName(node)
86+
s.scope.SetVMID(vmid)
87+
88+
// os image
89+
if err := s.setCloudImage(ctx); err != nil {
90+
return nil, err
91+
}
92+
93+
// actually create qemu
94+
vm, err := s.client.CreateVirtualMachine(ctx, node, vmid, vmoption)
95+
if err != nil {
96+
return nil, err
97+
}
98+
99+
return vm, nil
85100
}
86101

87102
func (s *Service) generateVMOptions() api.VirtualMachineCreateOptions {

0 commit comments

Comments
 (0)