Skip to content

Commit

Permalink
virt-controller, template: add TSC frequency option to the node selec…
Browse files Browse the repository at this point in the history
…tor renderer

Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Aug 29, 2022
1 parent 6c5b71b commit 642dc20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 17 additions & 0 deletions pkg/virt-controller/services/nodeselectorrenderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"fmt"

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

"kubevirt.io/kubevirt/pkg/virt-controller/watch/topology"
)

type NodeSelectorRenderer struct {
cpuFeatureLabels []string
cpuModelLabel string
hasDedicatedCPU bool
hyperv bool
tscFrequency *int64
userProvidedSelectors map[string]string
vmiFeatures *v1.Features
}
Expand Down Expand Up @@ -43,12 +46,20 @@ func (nsr *NodeSelectorRenderer) Render() map[string]string {
nodeSelectors[cpuFeatureLabel] = "true"
}

if nsr.isManualTSCFrequencyRequired() {
nodeSelectors[topology.ToTSCSchedulableLabel(*nsr.tscFrequency)] = "true"
}

for k, v := range nsr.userProvidedSelectors {
nodeSelectors[k] = v
}
return nodeSelectors
}

func (nsr *NodeSelectorRenderer) isManualTSCFrequencyRequired() bool {
return nsr.tscFrequency != nil
}

func WithDedicatedCPU() NodeSelectorRendererOption {
return func(renderer *NodeSelectorRenderer) {
renderer.hasDedicatedCPU = true
Expand All @@ -75,6 +86,12 @@ func WithModelAndFeatureLabels(modelLabel string, cpuFeatureLabels ...string) No
}
}

func WithTSCTimer(tscFrequency *int64) NodeSelectorRendererOption {
return func(renderer *NodeSelectorRenderer) {
renderer.tscFrequency = tscFrequency
}
}

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")
Expand Down
12 changes: 4 additions & 8 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache"

"kubevirt.io/kubevirt/pkg/virt-controller/watch/topology"

networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"

v1 "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -416,12 +414,6 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
containers = append(containers, *kernelBootContainer)
}

if vmi.Status.TopologyHints != nil {
if vmi.Status.TopologyHints.TSCFrequency != nil {
nodeSelector[topology.ToTSCSchedulableLabel(*vmi.Status.TopologyHints.TSCFrequency)] = "true"
}
}

nodeSelectors := t.clusterConfig.GetNodeSelectors()
for k, v := range nodeSelectors {
nodeSelector[k] = v
Expand Down Expand Up @@ -563,6 +555,10 @@ func (t *templateService) newNodeSelectorRenderer(vmi *v1.VirtualMachineInstance
)
}

if vmi.Status.TopologyHints != nil && vmi.Status.TopologyHints.TSCFrequency != nil {
opts = append(opts, WithTSCTimer(vmi.Status.TopologyHints.TSCFrequency))
}

nodeSelector := NewNodeSelectorRenderer(vmi.Spec.NodeSelector, opts...)

return nodeSelector
Expand Down

0 comments on commit 642dc20

Please sign in to comment.