Skip to content

Commit 8696bef

Browse files
committed
Use provider-utils and removed unused functionality
Signed-off-by: Lukas Frank <lukas.frank@sap.com>
1 parent 9615ac8 commit 8696bef

34 files changed

+162
-1490
lines changed

api/api.go

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

api/apiutils.go

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
package api
55

66
import (
7-
"encoding/json"
8-
"fmt"
9-
107
"github.com/ironcore-dev/controller-utils/metautils"
118
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
9+
apiutils "github.com/ironcore-dev/provider-utils/apiutils/api"
1210
)
1311

14-
func GetObjectMetadata(o Metadata) (*irimeta.ObjectMetadata, error) {
15-
annotations, err := GetAnnotationsAnnotation(o)
12+
func GetObjectMetadata(o apiutils.Metadata) (*irimeta.ObjectMetadata, error) {
13+
annotations, err := apiutils.GetAnnotationsAnnotation(o, AnnotationsAnnotation)
1614
if err != nil {
1715
return nil, err
1816
}
1917

20-
labels, err := GetLabelsAnnotation(o)
18+
labels, err := apiutils.GetLabelsAnnotation(o, LabelsAnnotation)
2119
if err != nil {
2220
return nil, err
2321
}
@@ -37,77 +35,30 @@ func GetObjectMetadata(o Metadata) (*irimeta.ObjectMetadata, error) {
3735
}, nil
3836
}
3937

40-
func SetObjectMetadata(o Object, metadata *irimeta.ObjectMetadata) error {
41-
if err := SetAnnotationsAnnotation(o, metadata.Annotations); err != nil {
38+
func SetObjectMetadata(o apiutils.Object, metadata *irimeta.ObjectMetadata) error {
39+
if err := apiutils.SetAnnotationsAnnotation(o, AnnotationsAnnotation, metadata.Annotations); err != nil {
4240
return err
4341
}
44-
if err := SetLabelsAnnotation(o, metadata.Labels); err != nil {
42+
if err := apiutils.SetLabelsAnnotation(o, LabelsAnnotation, metadata.Labels); err != nil {
4543
return err
4644
}
4745
return nil
4846
}
4947

50-
func SetLabelsAnnotation(o Object, labels map[string]string) error {
51-
data, err := json.Marshal(labels)
52-
if err != nil {
53-
return fmt.Errorf("error marshalling labels: %w", err)
54-
}
55-
metautils.SetAnnotation(o, LabelsAnnotation, string(data))
56-
return nil
57-
}
58-
59-
func GetLabelsAnnotation(o Metadata) (map[string]string, error) {
60-
data, ok := o.GetAnnotations()[LabelsAnnotation]
61-
if !ok {
62-
return nil, fmt.Errorf("object has no labels at %s", LabelsAnnotation)
63-
}
64-
65-
var labels map[string]string
66-
if err := json.Unmarshal([]byte(data), &labels); err != nil {
67-
return nil, err
68-
}
69-
70-
return labels, nil
71-
}
72-
73-
func SetAnnotationsAnnotation(o Object, annotations map[string]string) error {
74-
data, err := json.Marshal(annotations)
75-
if err != nil {
76-
return fmt.Errorf("error marshalling annotations: %w", err)
77-
}
78-
metautils.SetAnnotation(o, AnnotationsAnnotation, string(data))
79-
80-
return nil
81-
}
82-
83-
func GetAnnotationsAnnotation(o Metadata) (map[string]string, error) {
84-
data, ok := o.GetAnnotations()[AnnotationsAnnotation]
85-
if !ok {
86-
return nil, fmt.Errorf("object has no annotations at %s", AnnotationsAnnotation)
87-
}
88-
89-
var annotations map[string]string
90-
if err := json.Unmarshal([]byte(data), &annotations); err != nil {
91-
return nil, err
92-
}
93-
94-
return annotations, nil
95-
}
96-
97-
func SetManagerLabel(o Object, manager string) {
48+
func SetManagerLabel(o apiutils.Object, manager string) {
9849
metautils.SetLabel(o, ManagerLabel, manager)
9950
}
10051

101-
func SetClassLabel(o Object, class string) {
52+
func SetClassLabel(o apiutils.Object, class string) {
10253
metautils.SetLabel(o, ClassLabel, class)
10354
}
10455

105-
func GetClassLabel(o Object) (string, bool) {
56+
func GetClassLabel(o apiutils.Object) (string, bool) {
10657
class, found := o.GetLabels()[ClassLabel]
10758
return class, found
10859
}
10960

110-
func IsManagedBy(o Object, manager string) bool {
61+
func IsManagedBy(o apiutils.Object, manager string) bool {
11162
actual, ok := o.GetLabels()[ManagerLabel]
11263
return ok && actual == manager
11364
}

api/machine.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ package api
55

66
import (
77
"time"
8+
9+
apiutils "github.com/ironcore-dev/provider-utils/apiutils/api"
810
)
911

1012
type Machine struct {
11-
Metadata `json:"metadata,omitempty"`
13+
apiutils.Metadata `json:"metadata,omitempty"`
1214

1315
Spec MachineSpec `json:"spec"`
1416
Status MachineStatus `json:"status"`

cmd/libvirt-provider/app/app.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ import (
1818

1919
"github.com/go-logr/logr"
2020
"github.com/ironcore-dev/ironcore-image/oci/remote"
21+
ocistore "github.com/ironcore-dev/ironcore-image/oci/store"
2122
"github.com/ironcore-dev/ironcore/broker/common"
2223
commongrpc "github.com/ironcore-dev/ironcore/broker/common/grpc"
2324
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
2425
"github.com/ironcore-dev/libvirt-provider/api"
2526
"github.com/ironcore-dev/libvirt-provider/internal/console"
2627
"github.com/ironcore-dev/libvirt-provider/internal/controllers"
27-
"github.com/ironcore-dev/libvirt-provider/internal/event"
28-
"github.com/ironcore-dev/libvirt-provider/internal/event/machineevent"
2928
"github.com/ironcore-dev/libvirt-provider/internal/healthcheck"
3029
"github.com/ironcore-dev/libvirt-provider/internal/host"
3130
"github.com/ironcore-dev/libvirt-provider/internal/libvirt/guest"
@@ -36,10 +35,12 @@ import (
3635
volumeplugin "github.com/ironcore-dev/libvirt-provider/internal/plugins/volume"
3736
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume/ceph"
3837
"github.com/ironcore-dev/libvirt-provider/internal/plugins/volume/emptydisk"
39-
"github.com/ironcore-dev/libvirt-provider/internal/qcow2"
4038
"github.com/ironcore-dev/libvirt-provider/internal/raw"
4139
"github.com/ironcore-dev/libvirt-provider/internal/server"
4240
"github.com/ironcore-dev/libvirt-provider/internal/strategy"
41+
"github.com/ironcore-dev/provider-utils/eventutils/event"
42+
"github.com/ironcore-dev/provider-utils/eventutils/recorder"
43+
hostutils "github.com/ironcore-dev/provider-utils/storeutils/host"
4344
"github.com/prometheus/client_golang/prometheus/promhttp"
4445
"github.com/spf13/cobra"
4546
"github.com/spf13/pflag"
@@ -79,7 +80,7 @@ type Options struct {
7980
GCVMGracefulShutdownTimeout time.Duration
8081
ResyncIntervalGarbageCollector time.Duration
8182

82-
MachineEventStore machineevent.EventStoreOptions
83+
MachineEventStore recorder.EventStoreOptions
8384

8485
VolumeCachePolicy string
8586
}
@@ -134,8 +135,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
134135
fs.StringSliceVar(&o.Libvirt.PreferredDomainTypes, "preferred-domain-types", []string{"kvm", "qemu"}, "Ordered list of preferred domain types to use.")
135136
fs.StringSliceVar(&o.Libvirt.PreferredMachineTypes, "preferred-machine-types", []string{"pc-q35"}, "Ordered list of preferred machine types to use.")
136137

137-
fs.StringVar(&o.Libvirt.Qcow2Type, "qcow2-type", qcow2.Default(), fmt.Sprintf("qcow2 implementation to use. Available: %v", qcow2.Available()))
138-
139138
fs.DurationVar(&o.GCVMGracefulShutdownTimeout, "gc-vm-graceful-shutdown-timeout", 5*time.Minute, "Duration to wait for the VM to gracefully shut down. If the VM does not shut down within this period, it will be forcibly destroyed by garbage collector.")
140139
fs.DurationVar(&o.ResyncIntervalGarbageCollector, "gc-resync-interval", 1*time.Minute, "Interval for resynchronizing the garbage collector.")
141140

@@ -227,15 +226,15 @@ func Run(ctx context.Context, opts Options) error {
227226
return err
228227
}
229228

230-
imgCache, err := oci.NewLocalCache(log, reg, providerHost.OCIStore())
229+
ociStore, err := ocistore.New(providerHost.ImagesDir())
231230
if err != nil {
232-
setupLog.Error(err, "failed to initialize oci manager")
231+
setupLog.Error(err, "error creating oci store")
233232
return err
234233
}
235234

236-
qcow2Inst, err := qcow2.Instance(opts.Libvirt.Qcow2Type)
235+
imgCache, err := oci.NewLocalCache(log, reg, ociStore)
237236
if err != nil {
238-
setupLog.Error(err, "failed to initialize qcow2 instance")
237+
setupLog.Error(err, "failed to initialize oci manager")
239238
return err
240239
}
241240

@@ -258,7 +257,7 @@ func Run(ctx context.Context, opts Options) error {
258257
volumePlugins := volumeplugin.NewPluginManager()
259258
if err := volumePlugins.InitPlugins(providerHost, []volumeplugin.Plugin{
260259
ceph.NewPlugin(),
261-
emptydisk.NewPlugin(qcow2Inst, rawInst),
260+
emptydisk.NewPlugin(rawInst),
262261
}); err != nil {
263262
setupLog.Error(err, "failed to initialize volume plugin manager")
264263
return err
@@ -281,7 +280,7 @@ func Run(ctx context.Context, opts Options) error {
281280
}
282281

283282
setupLog.Info("Configuring machine store", "Directory", providerHost.MachineStoreDir())
284-
machineStore, err := host.NewStore(host.Options[*api.Machine]{
283+
machineStore, err := hostutils.NewStore[*api.Machine](hostutils.Options[*api.Machine]{
285284
NewFunc: func() *api.Machine { return &api.Machine{} },
286285
CreateStrategy: strategy.MachineStrategy,
287286
Dir: providerHost.MachineStoreDir(),
@@ -301,19 +300,18 @@ func Run(ctx context.Context, opts Options) error {
301300
return err
302301
}
303302

304-
eventStore := machineevent.NewEventStore(log, opts.MachineEventStore)
303+
eventStore := recorder.NewEventStore(log, opts.MachineEventStore)
305304

306305
machineReconciler, err := controllers.NewMachineReconciler(
307306
log.WithName("machine-reconciler"),
308-
libvirt,
307+
providerHost,
309308
machineStore,
310309
machineEvents,
311310
eventStore,
312311
controllers.MachineReconcilerOptions{
313312
GuestCapabilities: caps,
314313
ImageCache: imgCache,
315314
Raw: rawInst,
316-
Host: providerHost,
317315
VolumePluginManager: volumePlugins,
318316
NetworkInterfacePlugin: nicPlugin,
319317
ResyncIntervalVolumeSize: opts.ResyncIntervalVolumeSize,

go.mod

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
module github.com/ironcore-dev/libvirt-provider
22

33
go 1.24
4+
45
toolchain go1.24.1
56

67
require (
78
github.com/blang/semver/v4 v4.0.0
89
github.com/ceph/go-ceph v0.32.0
910
github.com/containerd/containerd v1.7.26
10-
github.com/digitalocean/go-libvirt v0.0.0-20250226181018-4d5f24afb7c2
11+
github.com/digitalocean/go-libvirt v0.0.0-20250317183548-13bf9b43b50b
1112
github.com/go-chi/chi/v5 v5.2.1
1213
github.com/go-logr/logr v1.4.2
13-
github.com/gogo/protobuf v1.3.2
1414
github.com/google/uuid v1.6.0
1515
github.com/ironcore-dev/controller-utils v0.9.8
1616
github.com/ironcore-dev/ironcore v0.2.2
1717
github.com/ironcore-dev/ironcore-image v0.2.4
1818
github.com/ironcore-dev/ironcore-net v0.2.2
19+
github.com/ironcore-dev/provider-utils v0.0.0-20250306151636-96670e489568
1920
github.com/moby/term v0.5.2
2021
github.com/onsi/ginkgo/v2 v2.23.0
2122
github.com/onsi/gomega v1.36.2
@@ -26,10 +27,10 @@ require (
2627
github.com/spf13/pflag v1.0.6
2728
golang.org/x/sync v0.12.0
2829
google.golang.org/grpc v1.71.0
29-
k8s.io/api v0.32.2
30-
k8s.io/apimachinery v0.32.2
31-
k8s.io/client-go v0.32.2
32-
k8s.io/kubectl v0.32.2
30+
k8s.io/api v0.32.3
31+
k8s.io/apimachinery v0.32.3
32+
k8s.io/client-go v0.32.3
33+
k8s.io/kubectl v0.32.3
3334
k8s.io/utils v0.0.0-20241210054802-24370beab758
3435
libvirt.org/go/libvirtxml v1.11000.1
3536
sigs.k8s.io/controller-runtime v0.20.3
@@ -64,6 +65,7 @@ require (
6465
github.com/go-openapi/jsonreference v0.21.0 // indirect
6566
github.com/go-openapi/swag v0.23.0 // indirect
6667
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
68+
github.com/gogo/protobuf v1.3.2 // indirect
6769
github.com/golang/protobuf v1.5.4 // indirect
6870
github.com/google/btree v1.1.3 // indirect
6971
github.com/google/gnostic-models v0.6.9 // indirect
@@ -122,7 +124,7 @@ require (
122124
gotest.tools/v3 v3.5.1 // indirect
123125
k8s.io/apiextensions-apiserver v0.32.2 // indirect
124126
k8s.io/apiserver v0.32.2 // indirect
125-
k8s.io/cli-runtime v0.32.2 // indirect
127+
k8s.io/cli-runtime v0.32.3 // indirect
126128
k8s.io/klog/v2 v2.130.1 // indirect
127129
k8s.io/kube-openapi v0.0.0-20250304201544-e5f78fe3ede9 // indirect
128130
oras.land/oras-go v1.2.6 // indirect

0 commit comments

Comments
 (0)