@@ -22,6 +22,7 @@ import (
2222 "errors"
2323 "fmt"
2424 "os"
25+ "strings"
2526 "time"
2627
2728 "k8s.io/apimachinery/pkg/api/meta"
@@ -43,13 +44,13 @@ import (
4344// HypervisorReconciler reconciles a Hypervisor object
4445type HypervisorReconciler struct {
4546 client.Client
46- Scheme * runtime.Scheme
47- libvirt libvirt.Interface
48- systemd systemd.Interface
49- libvirtVersion string
50- OperatingSystemVersion string
51- evacuateOnReboot bool
52- migrationJobs map [string ]context.Context
47+ Scheme * runtime.Scheme
48+ libvirt libvirt.Interface
49+ systemd systemd.Interface
50+ libvirtVersion string
51+ osDescriptor * systemd. Descriptor
52+ evacuateOnReboot bool
53+ migrationJobs map [string ]context.Context
5354}
5455
5556const (
@@ -227,16 +228,32 @@ func (r *HypervisorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
227228 Message : fmt .Sprintf ("%s: %s, %s" , unit .Name , unit .ActiveState , unit .LoadState ),
228229 })
229230 }
230- }
231231
232- if hypervisor .Status .Version != r .OperatingSystemVersion {
233- hypervisor .Status .Version = r .OperatingSystemVersion
232+ if r .osDescriptor != nil && hypervisor .Status .OperatingSystem .Version == "" {
233+ for _ , line := range r .osDescriptor .OperatingSystemReleaseData {
234+ switch strings .Split (line , "=" )[0 ] {
235+ case "PRETTY_NAME" :
236+ hypervisor .Status .OperatingSystem .PrettyVersion = strings .Split (line , "=" )[1 ]
237+ case "GARDENLINUX_VERSION" :
238+ hypervisor .Status .OperatingSystem .Version = strings .Split (line , "=" )[1 ]
239+ }
240+ }
241+ hypervisor .Status .OperatingSystem .KernelVersion = r .osDescriptor .KernelVersion
242+ hypervisor .Status .OperatingSystem .KernelRelease = r .osDescriptor .KernelRelease
243+ hypervisor .Status .OperatingSystem .KernelName = r .osDescriptor .KernelName
244+ hypervisor .Status .OperatingSystem .HardwareVendor = r .osDescriptor .HardwareVendor
245+ hypervisor .Status .OperatingSystem .HardwareModel = r .osDescriptor .HardwareModel
246+ hypervisor .Status .OperatingSystem .HardwareSerial = r .osDescriptor .HardwareSerial
247+ hypervisor .Status .OperatingSystem .FirmwareVersion = r .osDescriptor .FirmwareVersion
248+ hypervisor .Status .OperatingSystem .FirmwareVendor = r .osDescriptor .FirmwareVendor
249+ hypervisor .Status .OperatingSystem .FirmwareDate = metav1 .NewTime (time .UnixMicro (r .osDescriptor .FirmwareDate ))
250+ }
234251 }
235252
236253 // Reconcile operating system update
237254 if hypervisor .Spec .OperatingSystemVersion != "" &&
238255 // only update if the version is different to current running version
239- hypervisor .Spec .OperatingSystemVersion != hypervisor .Status .Version &&
256+ hypervisor .Spec .OperatingSystemVersion != hypervisor .Status .OperatingSystem . Version &&
240257 // only update if the version is different to the installed version
241258 hypervisor .Spec .OperatingSystemVersion != hypervisor .Status .Update .Installed {
242259
@@ -322,7 +339,6 @@ func (r *HypervisorReconciler) Reconcile(ctx context.Context, req ctrl.Request)
322339func (r * HypervisorReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
323340 ctx := context .Background ()
324341 emulate := os .Getenv ("EMULATE" )
325- r .OperatingSystemVersion = sys .GetOSVersion (ctx )
326342 r .migrationJobs = make (map [string ]context.Context )
327343
328344 var err error
@@ -337,6 +353,11 @@ func (r *HypervisorReconciler) SetupWithManager(mgr ctrl.Manager) error {
337353 }
338354 }
339355
356+ r .osDescriptor , err = r .systemd .Describe (ctx )
357+ if err != nil {
358+ return fmt .Errorf ("unable to get systemd hostname describe(): %w" , err )
359+ }
360+
340361 return ctrl .NewControllerManagedBy (mgr ).
341362 For (& kvmv1alpha1.Hypervisor {}).
342363 Complete (r )
0 commit comments