Skip to content

support to set cpu model with more detail #727

@yanxuean

Description

@yanxuean

@jellonek
I see that the #696 has supported to set cpu model to "host-model". I don't know the #696 has implemented it before:)
I also implemented a new version based v1.0.0, it can set more cpu features, and set host-model,pass-through,custum etc.
I think the new version is more flexible.
Please take a look if we need the new version. thanks.

some code

 func (va *VirtletAnnotations) parsePodAnnotations(ns string, podAnnotations map[string]string) error {
+       if cpuModeStr, found := podAnnotations[cpuMode]; found {
+               var cpuMode libvirtxml.DomainCPU
+               if err := yaml.Unmarshal([]byte(cpuModeStr), &cpuMode); err != nil {
+                       return err
+               }
+               va.CPUMode = &cpuMode
+       }
+
        if podAnnotations[cloudInitUserDataOverwriteKeyName] == "true" {
                va.UserDataOverwrite = true
        }

@@ -106,18 +106,19 @@ func (ds *domainSettings) createDomain(config *VMConfig) *libvirtxml.Domain {
                // The plan is to enable it via an annotation at some point.
                // It commonly requires kvm_intel module to be loaded like this:
                // modprobe kvm_intel nested=1
-               CPU: &libvirtxml.DomainCPU{
-                       Mode: "host-model",
-                       Model: &libvirtxml.DomainCPUModel{
-                               Fallback: "forbid",
-                       },
-                       Features: []libvirtxml.DomainCPUFeature{
-                               {
-                                       Policy: "require",
-                                       Name:   "avx",
-                               },
-                       },
-               },
+               CPU: config.ParsedAnnotations.CPUMode,

for pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: cirros-vm
  annotations:
    # This tells CRI Proxy that this pod belongs to Virtlet runtime
    kubernetes.io/target-runtime: virtlet.cloud
    # CirrOS doesn't load nocloud data from SCSI CD-ROM for some reason
    VirtletDiskDriver: virtio
    VirtletVCPUCount: "4"
    # for "mode": host-model, host-passthrough,custom
    # for "model": Westmere, SandyBridge
    VirtletCPUMode: |
      mode: custom
      model:
        value: Westmere
      features:
      - name: avx
        policy: disable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions