Skip to content

Commit 141e197

Browse files
committed
merge main
2 parents f9950e7 + a98cc8d commit 141e197

File tree

10 files changed

+76
-79
lines changed

10 files changed

+76
-79
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ for more information : https://cluster-api.sigs.k8s.io/user/quick-start.html#ini
2222
```sh
2323
# install cluster-api components
2424
export EXP_CLUSTER_RESOURCE_SET=true
25-
clusterctl init --infrastructure=proxmox:v0.3.6 --config https://raw.githubusercontent.com/k8s-proxmox/cluster-api-provider-proxmox/main/clusterctl.yaml
25+
clusterctl init --infrastructure=proxmox:v0.3.7 --config https://raw.githubusercontent.com/k8s-proxmox/cluster-api-provider-proxmox/main/clusterctl.yaml
2626
```
2727

2828
**Note:** container images are available at [ghcr.io/k8s-proxmox/cluster-api-provider-proxmox:\<tag\>](https://github.com/k8s-proxmox/cluster-api-provider-proxmox/pkgs/container/cluster-api-provider-proxmox)
@@ -37,7 +37,7 @@ export PROXMOX_PASSWORD=password
3737
export PROXMOX_USER=user@pam
3838

3939
# generate manifests (available flags: --target-namespace, --kubernetes-version, --control-plane-machine-count, --worker-machine-count)
40-
clusterctl generate cluster cappx-test --control-plane-machine-count=3 --infrastructure=proxmox:v0.3.6 --config https://raw.githubusercontent.com/k8s-proxmox/cluster-api-provider-proxmox/main/clusterctl.yaml > cappx-test.yaml
40+
clusterctl generate cluster cappx-test --control-plane-machine-count=3 --infrastructure=proxmox:v0.3.7 --config https://raw.githubusercontent.com/k8s-proxmox/cluster-api-provider-proxmox/main/clusterctl.yaml > cappx-test.yaml
4141

4242
# inspect and edit
4343
vi cappx-test.yaml

cloud/scheduler/framework/cycle_state.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ type CycleState struct {
88
}
99

1010
type SchedulerResult struct {
11-
vmid int
12-
node string
11+
vmid int
12+
node string
13+
storage string
1314
}
1415

1516
func NewCycleState() CycleState {
@@ -46,8 +47,8 @@ func (c *CycleState) UpdateState(completed bool, err error, result SchedulerResu
4647
c.result = result
4748
}
4849

49-
func NewSchedulerResult(vmid int, node string) SchedulerResult {
50-
return SchedulerResult{vmid: vmid, node: node}
50+
func NewSchedulerResult(vmid int, node string, storage string) SchedulerResult {
51+
return SchedulerResult{vmid: vmid, node: node, storage: storage}
5152
}
5253

5354
func (c *CycleState) Result() SchedulerResult {
@@ -61,3 +62,7 @@ func (r *SchedulerResult) Node() string {
6162
func (r *SchedulerResult) VMID() int {
6263
return r.vmid
6364
}
65+
66+
func (r *SchedulerResult) Storage() string {
67+
return r.storage
68+
}

cloud/scheduler/framework/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type NodeInfo struct {
5858
}
5959

6060
func GetNodeInfoList(ctx context.Context, client *proxmox.Service) ([]*NodeInfo, error) {
61-
nodes, err := client.Nodes(ctx)
61+
nodes, err := client.GetNodes(ctx)
6262
if err != nil {
6363
return nil, err
6464
}

cloud/scheduler/scheduler.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scheduler
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"time"
78

89
"github.com/go-logr/logr"
@@ -221,7 +222,15 @@ func (s *Scheduler) ScheduleOne(ctx context.Context) {
221222
return
222223
}
223224

224-
result := framework.NewSchedulerResult(vmid, node)
225+
// select vm storage to be used for vm image
226+
// must be done after node selection as some storages may not be available on some nodes
227+
storage, err := s.SelectStorage(qemuCtx, *config, node)
228+
if err != nil {
229+
state.UpdateState(true, err, framework.SchedulerResult{})
230+
return
231+
}
232+
233+
result := framework.NewSchedulerResult(vmid, node, storage)
225234
state.UpdateState(true, nil, result)
226235
}
227236

@@ -250,8 +259,8 @@ func (s *Scheduler) WaitStatus(ctx context.Context, config *api.VirtualMachineCr
250259

251260
// create new qemu with given spec and context
252261
func (s *Scheduler) CreateQEMU(ctx context.Context, config *api.VirtualMachineCreateOptions) (framework.SchedulerResult, error) {
253-
s.logger = s.logger.WithValues("qemu", config.Name)
254-
s.logger.Info("adding qemu to scheduler queue")
262+
log := s.logger.WithValues("qemu", config.Name)
263+
log.Info("adding qemu to scheduler queue")
255264
// add qemu spec into the queue
256265
s.schedulingQueue.Add(ctx, config)
257266

@@ -262,16 +271,16 @@ func (s *Scheduler) CreateQEMU(ctx context.Context, config *api.VirtualMachineCr
262271
return status.Result(), err
263272
}
264273
if status.Error() != nil {
265-
s.logger.Error(status.Error(), fmt.Sprintf("failed to create qemu: %v", status.Messages()))
274+
log.Error(status.Error(), fmt.Sprintf("failed to create qemu: %v", status.Messages()))
266275
return status.Result(), status.Error()
267276
}
268-
s.logger.Info(fmt.Sprintf("%v", status.Messages()))
277+
log.Info(fmt.Sprintf("%v", status.Messages()))
269278
return status.Result(), nil
270279
}
271280

272281
func (s *Scheduler) SelectNode(ctx context.Context, config api.VirtualMachineCreateOptions) (string, error) {
273282
s.logger.Info("finding proxmox node matching qemu")
274-
nodes, err := s.client.Nodes(ctx)
283+
nodes, err := s.client.GetNodes(ctx)
275284
if err != nil {
276285
return "", err
277286
}
@@ -316,6 +325,33 @@ func (s *Scheduler) SelectVMID(ctx context.Context, config api.VirtualMachineCre
316325
return s.RunVMIDPlugins(ctx, nil, config, nextid, *usedID)
317326
}
318327

328+
func (s *Scheduler) SelectStorage(ctx context.Context, config api.VirtualMachineCreateOptions, nodeName string) (string, error) {
329+
s.logger.Info("finding proxmox storage to be used for qemu")
330+
if config.Storage != "" {
331+
// to do: raise error if storage is not available on the node
332+
return config.Storage, nil
333+
}
334+
335+
node, err := s.client.Node(ctx, nodeName)
336+
if err != nil {
337+
return "", err
338+
}
339+
storages, err := node.GetStorages(ctx)
340+
if err != nil {
341+
return "", err
342+
}
343+
344+
// current logic is just selecting the first storage
345+
// that is active and supports "images" type of content
346+
for _, storage := range storages {
347+
if strings.Contains(storage.Content, "images") && storage.Active == 1 {
348+
return storage.Storage, nil
349+
}
350+
}
351+
352+
return "", fmt.Errorf("no storage available for VM image on node %s", nodeName)
353+
}
354+
319355
func (s *Scheduler) RunFilterPlugins(ctx context.Context, state *framework.CycleState, config api.VirtualMachineCreateOptions, nodes []*api.Node) ([]*api.Node, error) {
320356
s.logger.Info("filtering proxmox node")
321357
feasibleNodes := make([]*api.Node, 0, len(nodes))
@@ -342,7 +378,7 @@ func (s *Scheduler) RunFilterPlugins(ctx context.Context, state *framework.Cycle
342378
func (s *Scheduler) RunScorePlugins(ctx context.Context, state *framework.CycleState, config api.VirtualMachineCreateOptions, nodes []*api.Node) (framework.NodeScoreList, *framework.Status) {
343379
s.logger.Info("scoring proxmox node")
344380
status := framework.NewStatus()
345-
var scoresMap map[string](map[int]framework.NodeScore)
381+
scoresMap := make(map[string](map[int]framework.NodeScore))
346382
nodeInfos, err := framework.GetNodeInfoList(ctx, s.client)
347383
if err != nil {
348384
status.SetCode(1)

cloud/services/compute/instance/cloudinit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s *Service) deleteCloudConfig(ctx context.Context) error {
3737
path := userSnippetPath(s.scope.Name())
3838
volumeID := fmt.Sprintf("%s:%s", storageName, path)
3939

40-
node, err := s.client.Node(ctx, s.scope.NodeName())
40+
node, err := s.client.GetNode(ctx, s.scope.NodeName())
4141
if err != nil {
4242
return err
4343
}

cloud/services/compute/instance/qemu.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func (s *Service) createQEMU(ctx context.Context) (*proxmox.VirtualMachine, erro
6767
log := log.FromContext(ctx)
6868
log.Info("creating qemu")
6969

70-
if err := s.ensureStorageAvailable(ctx); err != nil {
71-
return nil, err
72-
}
73-
7470
// create qemu
7571
log.Info("making qemu spec")
7672
vmoption := s.generateVMOptions()
@@ -81,10 +77,14 @@ func (s *Service) createQEMU(ctx context.Context) (*proxmox.VirtualMachine, erro
8177
log.Error(err, "failed to schedule qemu instance")
8278
return nil, err
8379
}
84-
node, vmid := result.Node(), result.VMID()
80+
node, vmid, storage := result.Node(), result.VMID(), result.Storage()
8581
s.scope.SetNodeName(node)
8682
s.scope.SetVMID(vmid)
8783

84+
// inject storage
85+
s.injectVMOption(&vmoption, storage)
86+
s.scope.SetStorage(storage)
87+
8888
// os image
8989
if err := s.setCloudImage(ctx); err != nil {
9090
return nil, err
@@ -164,3 +164,14 @@ func boolToInt8(b bool) int8 {
164164
}
165165
return 0
166166
}
167+
168+
func (s *Service) injectVMOption(vmOption *api.VirtualMachineCreateOptions, storage string) *api.VirtualMachineCreateOptions {
169+
// storage is finalized after node scheduling so we need to inject storage name here
170+
ide2 := fmt.Sprintf("file=%s:cloudinit,media=cdrom", storage)
171+
scsi0 := fmt.Sprintf("%s:0,import-from=%s", storage, rawImageFilePath(s.scope.GetImage()))
172+
vmOption.Scsi.Scsi0 = scsi0
173+
vmOption.Ide.Ide2 = ide2
174+
vmOption.Storage = storage
175+
176+
return vmOption
177+
}

cloud/services/compute/instance/storage.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

cloud/services/compute/storage/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (s *Service) deleteStorage(ctx context.Context) error {
7676
return err
7777
}
7878

79-
nodes, err := s.client.Nodes(ctx)
79+
nodes, err := s.client.GetNodes(ctx)
8080
if err != nil {
8181
return err
8282
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.22.10
77
require (
88
github.com/go-logr/logr v1.4.2
99
github.com/imdario/mergo v0.3.13
10-
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha28
10+
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha30
1111
github.com/onsi/ginkgo/v2 v2.19.1
1212
github.com/onsi/gomega v1.34.0
1313
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
152152
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
153153
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
154154
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
155-
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha28 h1:h0PwVITcljicpXCmMcOyXeXWhkVeYBiK4F2A/Ch5dxg=
156-
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha28/go.mod h1:ZSAdc9vVAEcIhbNkZxURWTY+k59cXUy9mswp5ofMM40=
155+
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha30 h1:xwA4cEZVjaShetPErsN/z+CHUA4jE8HhIRQ9d345WsM=
156+
github.com/k8s-proxmox/proxmox-go v0.0.0-alpha30/go.mod h1:ZSAdc9vVAEcIhbNkZxURWTY+k59cXUy9mswp5ofMM40=
157157
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
158158
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
159159
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=

0 commit comments

Comments
 (0)