Skip to content

Commit c4a3dac

Browse files
committed
LocalDisk
Signed-off-by: Lukas Frank <[email protected]>
1 parent 82ae468 commit c4a3dac

18 files changed

+337
-252
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
2+
IMG ?= libvirt-provider:latest
33

44
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
55
ENVTEST_K8S_VERSION = 1.28

api/machine.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
apiutils "github.com/ironcore-dev/provider-utils/apiutils/api"
10+
"k8s.io/utils/ptr"
1011
)
1112

1213
type Machine struct {
@@ -22,8 +23,7 @@ type MachineSpec struct {
2223
Cpu int64 `json:"cpu"`
2324
MemoryBytes int64 `json:"memoryBytes"`
2425

25-
Image *string `json:"image"`
26-
Ignition []byte `json:"ignition"`
26+
Ignition []byte `json:"ignition"`
2727

2828
Volumes []*VolumeSpec `json:"volumes"`
2929
NetworkInterfaces []*NetworkInterfaceSpec `json:"networkInterfaces"`
@@ -68,7 +68,7 @@ const (
6868
type VolumeSpec struct {
6969
Name string `json:"name"`
7070
Device string `json:"device"`
71-
EmptyDisk *EmptyDiskSpec `json:"emptyDisk,omitempty"`
71+
LocalDisk *LocalDiskSpec `json:"localDisk,omitempty"`
7272
Connection *VolumeConnection `json:"cephDisk,omitempty"`
7373
}
7474

@@ -79,8 +79,9 @@ type VolumeStatus struct {
7979
Size int64 `json:"size,omitempty"`
8080
}
8181

82-
type EmptyDiskSpec struct {
83-
Size int64 `json:"size"`
82+
type LocalDiskSpec struct {
83+
Size int64 `json:"size"`
84+
Image *string `json:"image"`
8485
}
8586

8687
type VolumeConnection struct {
@@ -122,3 +123,25 @@ const (
122123
type GuestAgentStatus struct {
123124
Addr string `json:"addr,omitempty"`
124125
}
126+
127+
func HasBootImage(machine *Machine) *string {
128+
for _, volume := range machine.Spec.Volumes {
129+
if volume.LocalDisk == nil {
130+
continue
131+
}
132+
133+
if volume.LocalDisk.Image != nil {
134+
return volume.LocalDisk.Image
135+
}
136+
}
137+
return nil
138+
}
139+
140+
func IsImageReferenced(machine *Machine, image string) bool {
141+
bootImage := HasBootImage(machine)
142+
if bootImage == nil {
143+
return false
144+
}
145+
146+
return ptr.Deref(bootImage, "") == image
147+
}

cmd/libvirt-provider/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/ironcore-dev/libvirt-provider/internal/networkinterfaceplugin"
3434
volumeplugin "github.com/ironcore-dev/libvirt-provider/internal/plugins/volume"
3535
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume/ceph"
36-
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume/emptydisk"
36+
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume/localdisk"
3737
"github.com/ironcore-dev/libvirt-provider/internal/raw"
3838
"github.com/ironcore-dev/libvirt-provider/internal/server"
3939
"github.com/ironcore-dev/libvirt-provider/internal/strategy"
@@ -265,7 +265,7 @@ func Run(ctx context.Context, opts Options) error {
265265
volumePlugins := volumeplugin.NewPluginManager()
266266
if err := volumePlugins.InitPlugins(providerHost, []volumeplugin.Plugin{
267267
ceph.NewPlugin(),
268-
emptydisk.NewPlugin(rawInst),
268+
localdisk.NewPlugin(rawInst, imgCache),
269269
}); err != nil {
270270
setupLog.Error(err, "failed to initialize volume plugin manager")
271271
return err

go.mod

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/ironcore-dev/libvirt-provider
22

3-
go 1.24.0
4-
5-
toolchain go1.24.1
3+
go 1.24.1
64

75
require (
86
github.com/blang/semver/v4 v4.0.0
@@ -11,7 +9,7 @@ require (
119
github.com/go-logr/logr v1.4.3
1210
github.com/google/uuid v1.6.0
1311
github.com/ironcore-dev/controller-utils v0.10.0
14-
github.com/ironcore-dev/ironcore v0.2.4
12+
github.com/ironcore-dev/ironcore v0.2.5-0.20251024123813-eecafba97af9
1513
github.com/ironcore-dev/ironcore-image v0.2.5
1614
github.com/ironcore-dev/ironcore-net v0.2.4
1715
github.com/ironcore-dev/provider-utils v0.0.0-20251010114402-394db8015df4
@@ -24,13 +22,13 @@ require (
2422
github.com/spf13/pflag v1.0.10
2523
golang.org/x/sync v0.17.0
2624
google.golang.org/grpc v1.76.0
27-
k8s.io/api v0.33.4
28-
k8s.io/apimachinery v0.33.4
29-
k8s.io/client-go v0.33.4
30-
k8s.io/kubectl v0.33.3
25+
k8s.io/api v0.34.1
26+
k8s.io/apimachinery v0.34.1
27+
k8s.io/client-go v0.34.1
28+
k8s.io/kubectl v0.34.1
3129
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
3230
libvirt.org/go/libvirtxml v1.11008.0
33-
sigs.k8s.io/controller-runtime v0.21.0
31+
sigs.k8s.io/controller-runtime v0.22.3
3432
)
3533

3634
require (
@@ -57,7 +55,7 @@ require (
5755
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
5856
github.com/felixge/httpsnoop v1.0.4 // indirect
5957
github.com/fsnotify/fsnotify v1.9.0 // indirect
60-
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
58+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
6159
github.com/go-logr/stdr v1.2.2 // indirect
6260
github.com/go-logr/zapr v1.3.0 // indirect
6361
github.com/go-ole/go-ole v1.3.0 // indirect
@@ -67,7 +65,7 @@ require (
6765
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
6866
github.com/gogo/protobuf v1.3.2 // indirect
6967
github.com/google/btree v1.1.3 // indirect
70-
github.com/google/gnostic-models v0.6.9 // indirect
68+
github.com/google/gnostic-models v0.7.0 // indirect
7169
github.com/google/go-cmp v0.7.0 // indirect
7270
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
7371
github.com/gorilla/mux v1.8.1 // indirect
@@ -83,12 +81,13 @@ require (
8381
github.com/moby/locker v1.0.1 // indirect
8482
github.com/moby/spdystream v0.5.0 // indirect
8583
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
86-
github.com/modern-go/reflect2 v1.0.2 // indirect
84+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
8785
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8886
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
8987
github.com/opencontainers/go-digest v1.0.0 // indirect
9088
github.com/opencontainers/image-spec v1.1.1 // indirect
9189
github.com/pkg/errors v0.9.1 // indirect
90+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
9291
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
9392
github.com/prometheus/client_model v0.6.2 // indirect
9493
github.com/prometheus/common v0.66.1 // indirect
@@ -113,25 +112,25 @@ require (
113112
golang.org/x/mod v0.27.0 // indirect
114113
golang.org/x/net v0.43.0 // indirect
115114
golang.org/x/oauth2 v0.30.0 // indirect
116-
golang.org/x/sys v0.35.0 // indirect
115+
golang.org/x/sys v0.37.0 // indirect
117116
golang.org/x/term v0.34.0 // indirect
118117
golang.org/x/text v0.28.0 // indirect
119118
golang.org/x/time v0.12.0 // indirect
120119
golang.org/x/tools v0.36.0 // indirect
121120
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
122121
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
123-
google.golang.org/protobuf v1.36.8 // indirect
122+
google.golang.org/protobuf v1.36.10 // indirect
124123
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
125124
gopkg.in/inf.v0 v0.9.1 // indirect
126125
gopkg.in/yaml.v3 v3.0.1 // indirect
127-
k8s.io/apiextensions-apiserver v0.33.3 // indirect
128-
k8s.io/apiserver v0.33.3 // indirect
129-
k8s.io/cli-runtime v0.33.3 // indirect
126+
k8s.io/apiextensions-apiserver v0.34.1 // indirect
127+
k8s.io/apiserver v0.34.1 // indirect
128+
k8s.io/cli-runtime v0.34.1 // indirect
130129
k8s.io/klog/v2 v2.130.1 // indirect
131-
k8s.io/kube-openapi v0.0.0-20250610211856-8b98d1ed966a // indirect
130+
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
132131
oras.land/oras-go v1.2.6 // indirect
133132
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
134133
sigs.k8s.io/randfill v1.0.0 // indirect
135-
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
134+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
136135
sigs.k8s.io/yaml v1.6.0 // indirect
137136
)

0 commit comments

Comments
 (0)