Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions internal/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"github.com/cobaltcore-dev/kvm-node-agent/internal/libvirt/dominfo"
)

const supportedYes = "yes"

type LibVirt struct {
virt *libvirt.Libvirt
client client.Client
Expand Down Expand Up @@ -372,7 +374,7 @@ func (l *LibVirt) addDomainCapabilities(old v1.Hypervisor) (v1.Hypervisor, error
// - <mode name="example3" supported="yes"></mode> becomes "mode/example3"
newHv.Status.DomainCapabilities.SupportedCpuModes = []string{}
for _, cpuMode := range domCapabilities.CPU.Modes {
if cpuMode.Supported != "yes" {
if cpuMode.Supported != supportedYes {
continue
}
newHv.Status.DomainCapabilities.SupportedCpuModes = append(
Expand All @@ -396,7 +398,7 @@ func (l *LibVirt) addDomainCapabilities(old v1.Hypervisor) (v1.Hypervisor, error
// - <video supported="yes"></video> becomes "video".
newHv.Status.DomainCapabilities.SupportedDevices = []string{}
for _, device := range domCapabilities.Devices.Devices {
if device.Supported != "yes" {
if device.Supported != supportedYes {
continue
}
newHv.Status.DomainCapabilities.SupportedDevices = append(
Expand All @@ -416,7 +418,7 @@ func (l *LibVirt) addDomainCapabilities(old v1.Hypervisor) (v1.Hypervisor, error
// Convert the supported features into a flat list.
newHv.Status.DomainCapabilities.SupportedFeatures = []string{}
for _, feature := range domCapabilities.Features.Features {
if feature.Supported == "yes" {
if feature.Supported == supportedYes {
newHv.Status.DomainCapabilities.SupportedFeatures = append(
newHv.Status.DomainCapabilities.SupportedFeatures,
feature.XMLName.Local,
Expand Down
15 changes: 11 additions & 4 deletions internal/libvirt/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
)

const (
UnitKiB = "KiB"
UnitMiB = "MiB"
UnitGiB = "GiB"
UnitTiB = "TiB"
)

type UUID [16]byte

func (uuid UUID) String() string {
Expand Down Expand Up @@ -59,13 +66,13 @@ func MemoryToResource(value int64, unit string) (resource.Quantity, error) {
var quantity *resource.Quantity
// Check the unit
switch unit {
case "KiB":
case UnitKiB:
quantity = resource.NewQuantity(value*1024, resource.BinarySI)
case "MiB":
case UnitMiB:
quantity = resource.NewQuantity(value*1024*1024, resource.BinarySI)
case "GiB":
case UnitGiB:
quantity = resource.NewQuantity(value*1024*1024*1024, resource.BinarySI)
case "TiB":
case UnitTiB:
quantity = resource.NewQuantity(value*1024*1024*1024*1024, resource.BinarySI)
}
if quantity == nil {
Expand Down
Loading