Skip to content

Commit

Permalink
virt-controller, template: move CPU labels / feature extraction funcs…
Browse files Browse the repository at this point in the history
… to the renderer

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Aug 29, 2022
1 parent a1bd111 commit 50e37e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
27 changes: 26 additions & 1 deletion pkg/virt-controller/services/nodeselectorrenderer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package services

import v1 "kubevirt.io/api/core/v1"
import (
"fmt"

v1 "kubevirt.io/api/core/v1"
)

type NodeSelectorRenderer struct {
hasDedicatedCPU bool
Expand Down Expand Up @@ -42,3 +46,24 @@ func copySelectors(src map[string]string, dst map[string]string) {
dst[k] = v
}
}

func CPUModelLabelFromCPUModel(vmi *v1.VirtualMachineInstance) (label string, err error) {
if vmi.Spec.Domain.CPU == nil || vmi.Spec.Domain.CPU.Model == "" {
err = fmt.Errorf("Cannot create CPU Model label, vmi spec is mising CPU model")
return
}
label = NFD_CPU_MODEL_PREFIX + vmi.Spec.Domain.CPU.Model
return
}

func CPUFeatureLabelsFromCPUFeatures(vmi *v1.VirtualMachineInstance) []string {
var labels []string
if vmi.Spec.Domain.CPU != nil && vmi.Spec.Domain.CPU.Features != nil {
for _, feature := range vmi.Spec.Domain.CPU.Features {
if feature.Policy == "" || feature.Policy == "require" {
labels = append(labels, NFD_CPU_FEATURE_PREFIX+feature.Name)
}
}
}
return labels
}
21 changes: 0 additions & 21 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,6 @@ func getHypervNodeSelectors(vmi *v1.VirtualMachineInstance) map[string]string {
return nodeSelectors
}

func CPUModelLabelFromCPUModel(vmi *v1.VirtualMachineInstance) (label string, err error) {
if vmi.Spec.Domain.CPU == nil || vmi.Spec.Domain.CPU.Model == "" {
err = fmt.Errorf("Cannot create CPU Model label, vmi spec is mising CPU model")
return
}
label = NFD_CPU_MODEL_PREFIX + vmi.Spec.Domain.CPU.Model
return
}

func CPUFeatureLabelsFromCPUFeatures(vmi *v1.VirtualMachineInstance) []string {
var labels []string
if vmi.Spec.Domain.CPU != nil && vmi.Spec.Domain.CPU.Features != nil {
for _, feature := range vmi.Spec.Domain.CPU.Features {
if feature.Policy == "" || feature.Policy == "require" {
labels = append(labels, NFD_CPU_FEATURE_PREFIX+feature.Name)
}
}
}
return labels
}

func SetNodeAffinityForForbiddenFeaturePolicy(vmi *v1.VirtualMachineInstance, pod *k8sv1.Pod) {

if vmi.Spec.Domain.CPU == nil || vmi.Spec.Domain.CPU.Features == nil {
Expand Down

0 comments on commit 50e37e6

Please sign in to comment.