Skip to content

Commit

Permalink
Merge pull request #714 from Mirantis/jell/systemuuidpoc
Browse files Browse the repository at this point in the history
Pass system uuid as domain uuid and in sysinfo
  • Loading branch information
ivan4th committed Feb 6, 2019
2 parents a653f48 + dad0dc7 commit ffad578
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/docs/reference/resources.md
Expand Up @@ -30,6 +30,18 @@ metrics about running containers and Virtlet doesn't create container per each
VM, and instead spawns VMs inside Virtlet container. This leads to all the VM, and instead spawns VMs inside Virtlet container. This leads to all the
resource usage being lumped together and ascribed to Virtlet pod. resource usage being lumped together and ascribed to Virtlet pod.


## Using fixed SMBIOS UUID
By default, VM pods use autogenerated SMBIOS UUID values. Some images may expect it to have a fixed value,
for example, due to software license requirements. In such cases, the value of SMBIOS UUID can be passed
using `VirtletSystemUUID` annotation.
For example:
```yaml
annotations:
VirtletSystemUUID: 53008994-44c0-4017-ad44-9c49758083da
```
Note: Virtlet can't handle multiple VMs with the same SMBIOS UUID on the same node. There can be multiple
VM pods with the same SMBIOS UUIDs residing on different nodes in the cluster, though.

## CPU management ## CPU management
### CPU cgroups facilities: ### CPU cgroups facilities:
1. `shares` - relative value of cpu time assigned, not recommended for using 1. `shares` - relative value of cpu time assigned, not recommended for using
Expand Down
3 changes: 3 additions & 0 deletions pkg/libvirttools/TestContainerLifecycle.out.yaml
Expand Up @@ -119,6 +119,7 @@
MetaData: null MetaData: null
RootVolumeSize: 0 RootVolumeSize: 0
SSHKeys: null SSHKeys: null
SystemUUID: null
UserData: null UserData: null
UserDataOverwrite: false UserDataOverwrite: false
UserDataScript: "" UserDataScript: ""
Expand Down Expand Up @@ -176,6 +177,7 @@
MetaData: null MetaData: null
RootVolumeSize: 0 RootVolumeSize: 0
SSHKeys: null SSHKeys: null
SystemUUID: null
UserData: null UserData: null
UserDataOverwrite: false UserDataOverwrite: false
UserDataScript: "" UserDataScript: ""
Expand Down Expand Up @@ -228,6 +230,7 @@
MetaData: null MetaData: null
RootVolumeSize: 0 RootVolumeSize: 0
SSHKeys: null SSHKeys: null
SystemUUID: null
UserData: null UserData: null
UserDataOverwrite: false UserDataOverwrite: false
UserDataScript: "" UserDataScript: ""
Expand Down
101 changes: 101 additions & 0 deletions pkg/libvirttools/TestDomainDefinitions__system_UUID.out.yaml
@@ -0,0 +1,101 @@
- name: GetImagePathDigestAndVirtualSize
value: fake/image1
- name: 'storage: CreateStoragePool'
value: |-
<pool type="dir">
<name>volumes</name>
<target>
<path>/var/lib/virtlet/volumes</path>
</target>
</pool>
- name: 'storage: volumes: CreateStorageVol'
value: |-
<volume type="file">
<name>virtlet_root_53008994-44c0-4017-ad44-9c49758083da</name>
<allocation unit="b">0</allocation>
<capacity unit="b">424242</capacity>
<target>
<format type="qcow2"></format>
</target>
<backingStore>
<path>/fake/volume/path</path>
<format type="qcow2"></format>
</backingStore>
</volume>
- name: 'domain conn: DefineDomain'
value: |-
<domain type="kvm">
<name>virtlet-53008994-44c0-container1</name>
<uuid>53008994-44c0-4017-ad44-9c49758083da</uuid>
<memory unit="MiB">1024</memory>
<vcpu>1</vcpu>
<cputune>
<shares>0</shares>
<period>0</period>
<quota>0</quota>
</cputune>
<sysinfo type="smbios">
<system>
<entry name="uuid">53008994-44c0-4017-ad44-9c49758083da</entry>
</system>
</sysinfo>
<os>
<type>hvm</type>
<boot dev="hd"></boot>
</os>
<features>
<acpi></acpi>
</features>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/vmwrapper</emulator>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"></driver>
<source file="/var/lib/virtlet/volumes/virtlet_root_53008994-44c0-4017-ad44-9c49758083da"></source>
<target dev="sda" bus="scsi"></target>
<address type="drive" controller="0" bus="0" target="0" unit="0"></address>
</disk>
<disk type="file" device="cdrom">
<driver name="qemu" type="raw"></driver>
<source file="/var/lib/virtlet/config/config-53008994-44c0-4017-ad44-9c49758083da.iso"></source>
<target dev="sdb" bus="scsi"></target>
<readonly></readonly>
<address type="drive" controller="0" bus="0" target="0" unit="1"></address>
</disk>
<controller type="scsi" index="0" model="virtio-scsi">
<address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x0"></address>
</controller>
<controller type="pci" model="pci-root"></controller>
<serial type="unix">
<source mode="connect" path="/var/lib/libvirt/streamer.sock">
<reconnect enabled="yes" timeout="1"></reconnect>
</source>
<target port="0"></target>
</serial>
<input type="tablet" bus="usb"></input>
<graphics type="vnc" port="-1"></graphics>
<video>
<model type="cirrus"></model>
</video>
</devices>
<commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0">
<env name="VIRTLET_EMULATOR" value="/usr/bin/kvm"></env>
<env name="VIRTLET_NET_KEY" value="/tmp/fakenetns"></env>
<env name="VIRTLET_CONTAINER_ID" value="53008994-44c0-4017-ad44-9c49758083da"></env>
<env name="VIRTLET_CONTAINER_LOG_PATH" value="/var/log/pods/69eec606-0493-5825-73a4-c5e0c0236155/container1_42.log"></env>
</commandline>
</domain>
- name: 'domain conn: virtlet-53008994-44c0-container1: Create'
- name: 'domain conn: virtlet-53008994-44c0-container1: iso image'
value:
meta-data: '{"instance-id":"testName_0.default","local-hostname":"testName_0"}'
network-config: |
version: 1
user-data: |
#cloud-config
- name: 'domain conn: virtlet-53008994-44c0-container1: Destroy'
- name: 'domain conn: virtlet-53008994-44c0-container1: Undefine'
- name: 'storage: volumes: RemoveVolumeByName'
value: virtlet_root_53008994-44c0-4017-ad44-9c49758083da
1 change: 1 addition & 0 deletions pkg/libvirttools/TestDomainForcedShutdown.out.yaml
Expand Up @@ -135,6 +135,7 @@
MetaData: null MetaData: null
RootVolumeSize: 0 RootVolumeSize: 0
SSHKeys: null SSHKeys: null
SystemUUID: null
UserData: null UserData: null
UserDataOverwrite: false UserDataOverwrite: false
UserDataScript: "" UserDataScript: ""
Expand Down
24 changes: 23 additions & 1 deletion pkg/libvirttools/virtualization.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"github.com/jonboulle/clockwork" "github.com/jonboulle/clockwork"
libvirtxml "github.com/libvirt/libvirt-go-xml" libvirtxml "github.com/libvirt/libvirt-go-xml"
uuid "github.com/nu7hatch/gouuid"
"k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/fields"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types" kubetypes "k8s.io/kubernetes/pkg/kubelet/types"


Expand Down Expand Up @@ -77,6 +78,7 @@ type domainSettings struct {
netFdKey string netFdKey string
enableSriov bool enableSriov bool
cpuModel string cpuModel string
systemUUID *uuid.UUID
} }


func (ds *domainSettings) createDomain(config *types.VMConfig) *libvirtxml.Domain { func (ds *domainSettings) createDomain(config *types.VMConfig) *libvirtxml.Domain {
Expand Down Expand Up @@ -181,6 +183,20 @@ func (ds *domainSettings) createDomain(config *types.VMConfig) *libvirtxml.Domai
} }
} }


if ds.systemUUID != nil {
domain.SysInfo = &libvirtxml.DomainSysInfo{
Type: "smbios",
System: &libvirtxml.DomainSysInfoSystem{
Entry: []libvirtxml.DomainSysInfoEntry{
{
Name: "uuid",
Value: ds.systemUUID.String(),
},
},
},
}
}

if ds.enableSriov { if ds.enableSriov {
domain.QEMUCommandline.Envs = append(domain.QEMUCommandline.Envs, domain.QEMUCommandline.Envs = append(domain.QEMUCommandline.Envs,
libvirtxml.DomainQEMUCommandlineEnv{Name: "VMWRAPPER_KEEP_PRIVS", Value: "1"}) libvirtxml.DomainQEMUCommandlineEnv{Name: "VMWRAPPER_KEEP_PRIVS", Value: "1"})
Expand Down Expand Up @@ -305,7 +321,12 @@ func (v *VirtualizationTool) CreateContainer(config *types.VMConfig, netFdKey st
return "", err return "", err
} }


domainUUID := utils.NewUUID5(ContainerNsUUID, config.PodSandboxID) var domainUUID string
if config.ParsedAnnotations.SystemUUID != nil {
domainUUID = config.ParsedAnnotations.SystemUUID.String()
} else {
domainUUID = utils.NewUUID5(ContainerNsUUID, config.PodSandboxID)
}
// FIXME: this field should be moved to VMStatus struct (to be added) // FIXME: this field should be moved to VMStatus struct (to be added)
config.DomainUUID = domainUUID config.DomainUUID = domainUUID
cpuModel := v.config.CPUModel cpuModel := v.config.CPUModel
Expand All @@ -331,6 +352,7 @@ func (v *VirtualizationTool) CreateContainer(config *types.VMConfig, netFdKey st
memoryUnit: "b", memoryUnit: "b",
useKvm: !v.config.DisableKVM, useKvm: !v.config.DisableKVM,
cpuModel: cpuModel, cpuModel: cpuModel,
systemUUID: config.ParsedAnnotations.SystemUUID,
} }
if settings.memory == 0 { if settings.memory == 0 {
settings.memory = defaultMemory settings.memory = defaultMemory
Expand Down
6 changes: 6 additions & 0 deletions pkg/libvirttools/virtualization_test.go
Expand Up @@ -351,6 +351,12 @@ func TestDomainDefinitions(t *testing.T) {
{ {
name: "plain domain", name: "plain domain",
}, },
{
name: "system UUID",
annotations: map[string]string{
"VirtletSystemUUID": "53008994-44c0-4017-ad44-9c49758083da",
},
},
{ {
name: "raw devices", name: "raw devices",
flexVolumes: map[string]map[string]interface{}{ flexVolumes: map[string]map[string]interface{}{
Expand Down
12 changes: 12 additions & 0 deletions pkg/metadata/types/annotations.go
Expand Up @@ -24,6 +24,7 @@ import (


"github.com/ghodss/yaml" "github.com/ghodss/yaml"
libvirtxml "github.com/libvirt/libvirt-go-xml" libvirtxml "github.com/libvirt/libvirt-go-xml"
uuid "github.com/nu7hatch/gouuid"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"


"github.com/Mirantis/virtlet/pkg/utils" "github.com/Mirantis/virtlet/pkg/utils"
Expand All @@ -43,6 +44,7 @@ const (
libvirtCPUSetting = "VirtletLibvirtCPUSetting" libvirtCPUSetting = "VirtletLibvirtCPUSetting"
sshKeysKeyName = "VirtletSSHKeys" sshKeysKeyName = "VirtletSSHKeys"
chown9pfsMountsKeyName = "VirtletChown9pfsMounts" chown9pfsMountsKeyName = "VirtletChown9pfsMounts"
systemUUIDKeyName = "VirtletSystemUUID"
// CloudInitUserDataSourceKeyName is the name of user data source key in the pod annotations. // CloudInitUserDataSourceKeyName is the name of user data source key in the pod annotations.
CloudInitUserDataSourceKeyName = "VirtletCloudInitUserDataSource" CloudInitUserDataSourceKeyName = "VirtletCloudInitUserDataSource"
// SSHKeySourceKeyName is the name of ssh key source key in the pod annotations. // SSHKeySourceKeyName is the name of ssh key source key in the pod annotations.
Expand Down Expand Up @@ -114,6 +116,9 @@ type VirtletAnnotations struct {
// InjectedFiles specifies the files to be injected into VM's // InjectedFiles specifies the files to be injected into VM's
// rootfs before booting the VM. // rootfs before booting the VM.
InjectedFiles map[string][]byte InjectedFiles map[string][]byte
// SystemUUID specifies fixed SMBIOS UUID to be used for the domain.
// If not set, the SMBIOS UUID will be automatically generated from the Pod ID.
SystemUUID *uuid.UUID
} }


// ExternalDataLoader is used to load extra pod data from // ExternalDataLoader is used to load extra pod data from
Expand Down Expand Up @@ -306,5 +311,12 @@ func (va *VirtletAnnotations) parsePodAnnotations(ns string, podAnnotations map[
va.VirtletChown9pfsMounts = true va.VirtletChown9pfsMounts = true
} }


if systemUUIDStr, found := podAnnotations[systemUUIDKeyName]; found {
var err error
if va.SystemUUID, err = uuid.ParseHex(systemUUIDStr); err != nil {
return fmt.Errorf("failed to parse %q as a UUID: %v", systemUUIDStr, err)
}
}

return nil return nil
} }
19 changes: 19 additions & 0 deletions pkg/metadata/types/annotations_test.go
Expand Up @@ -19,9 +19,12 @@ package types
import ( import (
"reflect" "reflect"
"testing" "testing"

uuid "github.com/nu7hatch/gouuid"
) )


func TestVirtletAnnotations(t *testing.T) { func TestVirtletAnnotations(t *testing.T) {

for _, testCase := range []struct { for _, testCase := range []struct {
name string name string
annotations map[string]string annotations map[string]string
Expand Down Expand Up @@ -144,6 +147,22 @@ func TestVirtletAnnotations(t *testing.T) {
CDImageType: "nocloud", CDImageType: "nocloud",
}, },
}, },
{
name: "system UUID",
annotations: map[string]string{
"VirtletSystemUUID": "53008994-44c0-4017-ad44-9c49758083da",
},
va: &VirtletAnnotations{
VCPUCount: 1,
SystemUUID: &uuid.UUID{
0x53, 0, 0x89, 0x94,
0x44, 0xc0, 0x40, 0x17, 0xad, 0x44,
0x9c, 0x49, 0x75, 0x80, 0x83, 0xda,
},
DiskDriver: "scsi",
CDImageType: "nocloud",
},
},
// bad metadata items follow // bad metadata items follow
{ {
name: "bad vcpu count", name: "bad vcpu count",
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/framework/vm_interface.go
Expand Up @@ -72,6 +72,8 @@ type VMOptions struct {
PVCs []PVCSpec PVCs []PVCSpec
// ConfigMap or Secret to inject into the rootfs // ConfigMap or Secret to inject into the rootfs
InjectFilesToRootfsFrom string InjectFilesToRootfsFrom string
// SystemUUID to set
SystemUUID string
} }


func newVMInterface(controller *Controller, name string) *VMInterface { func newVMInterface(controller *Controller, name string) *VMInterface {
Expand Down Expand Up @@ -215,6 +217,9 @@ func (vmi *VMInterface) buildVMPod(options VMOptions) *v1.Pod {
if options.InjectFilesToRootfsFrom != "" { if options.InjectFilesToRootfsFrom != "" {
annotations["VirtletFilesFromDataSource"] = options.InjectFilesToRootfsFrom annotations["VirtletFilesFromDataSource"] = options.InjectFilesToRootfsFrom
} }
if options.SystemUUID != "" {
annotations["VirtletSystemUUID"] = options.SystemUUID
}


limits := v1.ResourceList{} limits := v1.ResourceList{}
for k, v := range options.Limits { for k, v := range options.Limits {
Expand Down
52 changes: 52 additions & 0 deletions tests/e2e/systemuuid_test.go
@@ -0,0 +1,52 @@
/*
Copyright 2019 Mirantis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"time"

. "github.com/onsi/gomega"

"github.com/Mirantis/virtlet/tests/e2e/framework"
. "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext"
)

var _ = Describe("SystemUUID passing", func() {
var (
vm *framework.VMInterface
ssh framework.Executor
)

BeforeAll(func() {
vm = controller.VM("uuid")
Expect(vm.CreateAndWait(VMOptions{
SystemUUID: "53008994-44c0-4017-ad44-9c49758083da",
}.ApplyDefaults(), time.Minute*5, nil)).To(Succeed())
do(vm.Pod())
})

AfterAll(func() {
deleteVM(vm)
})

scheduleWaitSSH(&vm, &ssh)

It("Should have the specified SMBIOS UUID set [Conformance]", func() {
uuid := do(framework.RunSimple(ssh, "sudo", "cat", "/sys/class/dmi/id/product_uuid")).(string)
Expect(uuid).To(Equal("53008994-44C0-4017-AD44-9C49758083DA"))
})
})

0 comments on commit ffad578

Please sign in to comment.