Skip to content

Commit

Permalink
Merge pull request kubevirt#1385 from petrkotas/virtiorng
Browse files Browse the repository at this point in the history
Virtiorng
  • Loading branch information
fabiand authored Aug 31, 2018
2 parents 4530466 + c234f3c commit 5f20dbd
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 19 deletions.
7 changes: 7 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,10 @@
"$ref": "#/definitions/v1.Interface"
}
},
"rng": {
"description": "Whether to have random number generator from host\n+optional",
"$ref": "#/definitions/v1.Rng"
},
"watchdog": {
"description": "Watchdog describes a watchdog device which can be added to the vmi.",
"$ref": "#/definitions/v1.Watchdog"
Expand Down Expand Up @@ -4292,6 +4296,9 @@
}
}
},
"v1.Rng": {
"description": "Rng represents the random device passed from host"
},
"v1.ServerAddressByClientCIDR": {
"description": "ServerAddressByClientCIDR helps the client to determine the server address that they should use, depending on the clientCIDR that they match.",
"required": [
Expand Down
1 change: 1 addition & 0 deletions manifests/generated/vm-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ spec:
required:
- name
type: array
rng: {}
watchdog:
properties:
i6300esb:
Expand Down
1 change: 1 addition & 0 deletions manifests/generated/vmi-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ spec:
required:
- name
type: array
rng: {}
watchdog:
properties:
i6300esb:
Expand Down
1 change: 1 addition & 0 deletions manifests/generated/vmipreset-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ spec:
required:
- name
type: array
rng: {}
watchdog:
properties:
i6300esb:
Expand Down
1 change: 1 addition & 0 deletions manifests/generated/vmirs-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ spec:
required:
- name
type: array
rng: {}
watchdog:
properties:
i6300esb:
Expand Down
25 changes: 25 additions & 0 deletions pkg/api/v1/deepcopy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ func (in *Devices) DeepCopyInto(out *Devices) {
**out = **in
}
}
if in.Rng != nil {
in, out := &in.Rng, &out.Rng
if *in == nil {
*out = nil
} else {
*out = new(Rng)
**out = **in
}
}
return
}

Expand Down Expand Up @@ -1212,6 +1221,22 @@ func (in *ResourceRequirements) DeepCopy() *ResourceRequirements {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Rng) DeepCopyInto(out *Rng) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rng.
func (in *Rng) DeepCopy() *Rng {
if in == nil {
return nil
}
out := new(Rng)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Timer) DeepCopyInto(out *Timer) {
*out = *in
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func SetDefaults_VirtualMachineInstance(obj *VirtualMachineInstance) {
if obj.Spec.Domain.Machine.Type == "" {
obj.Spec.Domain.Machine.Type = "q35"
}

setDefaults_DiskFromMachineType(obj)
SetDefaults_NetworkInterface(obj)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ var _ = Describe("Defaults", func() {
Expect(*timer.RTC.Enabled).To(BeTrue())
Expect(*timer.Hyperv.Enabled).To(BeTrue())
})

})

var _ = Describe("Function SetDefaults_NetworkInterface()", func() {
Expand Down
17 changes: 16 additions & 1 deletion pkg/api/v1/openapi_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,17 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
Format: "",
},
},
"rng": {
SchemaProps: spec.SchemaProps{
Description: "Whether to have random number generator from host",
Ref: ref("kubevirt.io/kubevirt/pkg/api/v1.Rng"),
},
},
},
},
},
Dependencies: []string{
"kubevirt.io/kubevirt/pkg/api/v1.Disk", "kubevirt.io/kubevirt/pkg/api/v1.Interface", "kubevirt.io/kubevirt/pkg/api/v1.Watchdog"},
"kubevirt.io/kubevirt/pkg/api/v1.Disk", "kubevirt.io/kubevirt/pkg/api/v1.Interface", "kubevirt.io/kubevirt/pkg/api/v1.Rng", "kubevirt.io/kubevirt/pkg/api/v1.Watchdog"},
},
"kubevirt.io/kubevirt/pkg/api/v1.Disk": {
Schema: spec.Schema{
Expand Down Expand Up @@ -1191,6 +1197,15 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
Dependencies: []string{
"k8s.io/apimachinery/pkg/api/resource.Quantity"},
},
"kubevirt.io/kubevirt/pkg/api/v1.Rng": {
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Description: "Rng represents the random device passed from host",
Properties: map[string]spec.Schema{},
},
},
Dependencies: []string{},
},
"kubevirt.io/kubevirt/pkg/api/v1.Timer": {
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/v1/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ type Devices struct {
// Wheater to attach the default graphics device or not.
// VNC will not be available if set to false. Defaults to true.
AutoattachGraphicsDevice *bool `json:"autoattachGraphicsDevice,omitempty"`
// Whether to have random number generator from host
// +optional
Rng *Rng `json:"rng,omitempty"`
}

// ---
Expand Down Expand Up @@ -780,3 +783,9 @@ type PodNetwork struct {
// Default 10.0.2.0/24 if not specified.
VMNetworkCIDR string `json:"vmNetworkCIDR,omitempty"`
}

// Rng represents the random device passed from host
// ---
// +k8s:openapi-gen=true
type Rng struct {
}
7 changes: 7 additions & 0 deletions pkg/api/v1/schema_swagger_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (Devices) SwaggerDoc() map[string]string {
"interfaces": "Interfaces describe network interfaces which are added to the vm.",
"autoattachPodInterface": "Whether to attach a pod network interface. Defaults to true.",
"autoattachGraphicsDevice": "Wheater to attach the default graphics device or not.\nVNC will not be available if set to false. Defaults to true.",
"rng": "Whether to have random number generator from host\n+optional",
}
}

Expand Down Expand Up @@ -369,3 +370,9 @@ func (PodNetwork) SwaggerDoc() map[string]string {
"vmNetworkCIDR": "CIDR for vm network.\nDefault 10.0.2.0/24 if not specified.",
}
}

func (Rng) SwaggerDoc() map[string]string {
return map[string]string{
"": "Rng represents the random device passed from host",
}
}
5 changes: 4 additions & 1 deletion pkg/api/v1/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ var exampleJSON = `{
"name": "default",
{{.InterfaceConfig}}
}
]
],
"rng": {}
}
},
"volumes": [
Expand Down Expand Up @@ -262,6 +263,8 @@ var _ = Describe("Schema", func() {
},
}

exampleVMI.Spec.Domain.Devices.Rng = &Rng{}

exampleVMI.Spec.Volumes = []Volume{
{
Name: "volume0",
Expand Down
25 changes: 25 additions & 0 deletions pkg/virt-launcher/virtwrap/api/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ func Convert_v1_Watchdog_To_api_Watchdog(source *v1.Watchdog, watchdog *Watchdog
return fmt.Errorf("watchdog %s can't be mapped, no watchdog type specified", source.Name)
}

func Convert_v1_Rng_To_api_Rng(source *v1.Rng, rng *Rng, _ *ConverterContext) error {

// default rng model for KVM/QEMU virtualization
rng.Model = "virtio"

// default backend model, random
rng.Backend = &RngBackend{
Model: "random",
}

// the default source for rng is dev urandom
rng.Backend.Source = "/dev/urandom"

return nil
}

func Convert_v1_Clock_To_api_Clock(source *v1.Clock, clock *Clock, c *ConverterContext) error {
if source.UTC != nil {
clock.Offset = "utc"
Expand Down Expand Up @@ -435,6 +451,15 @@ func Convert_v1_VirtualMachine_To_api_Domain(vmi *v1.VirtualMachineInstance, dom
domain.Spec.Devices.Watchdog = newWatchdog
}

if vmi.Spec.Domain.Devices.Rng != nil {
newRng := &Rng{}
err := Convert_v1_Rng_To_api_Rng(vmi.Spec.Domain.Devices.Rng, newRng, c)
if err != nil {
return err
}
domain.Spec.Devices.Rng = newRng
}

if vmi.Spec.Domain.Clock != nil {
clock := vmi.Spec.Domain.Clock
newClock := &Clock{}
Expand Down
15 changes: 15 additions & 0 deletions pkg/virt-launcher/virtwrap/api/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ var _ = Describe("Converter", func() {
<watchdog model="i6300esb" action="poweroff">
<alias name="ua-mywatchdog"></alias>
</watchdog>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
<clock offset="utc" adjustment="reset">
<timer name="rtc" tickpolicy="catchup" present="yes" track="guest"></timer>
Expand Down Expand Up @@ -443,6 +446,7 @@ var _ = Describe("Converter", func() {

It("should be converted to a libvirt Domain with vmi defaults set", func() {
v1.SetObjectDefaults_VirtualMachineInstance(vmi)
vmi.Spec.Domain.Devices.Rng = &v1.Rng{}
Expect(vmiToDomainXML(vmi, c)).To(Equal(convertedDomain))
})

Expand Down Expand Up @@ -593,6 +597,17 @@ var _ = Describe("Converter", func() {
Expect(domainSpec.Memory.Unit).To(Equal("B"))
})

It("should not add RNG when not present", func() {
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expect(domainSpec.Devices.Rng).To(BeNil())
})

It("should add RNG when present", func() {
vmi.Spec.Domain.Devices.Rng = &v1.Rng{}
domainSpec := vmiToDomainXMLToDomainSpec(vmi, c)
Expect(domainSpec.Devices.Rng).ToNot(BeNil())
})

})
Context("Network convert", func() {
var vmi *v1.VirtualMachineInstance
Expand Down
74 changes: 62 additions & 12 deletions pkg/virt-launcher/virtwrap/api/deepcopy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,15 @@ func (in *Devices) DeepCopyInto(out *Devices) {
(*in).DeepCopyInto(*out)
}
}
if in.Rng != nil {
in, out := &in.Rng, &out.Rng
if *in == nil {
*out = nil
} else {
*out = new(Rng)
(*in).DeepCopyInto(*out)
}
}
return
}

Expand Down Expand Up @@ -1668,49 +1677,90 @@ func (in *OSType) DeepCopy() *OSType {
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RandomGenerator) DeepCopyInto(out *RandomGenerator) {
func (in *ReadOnly) DeepCopyInto(out *ReadOnly) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RandomGenerator.
func (in *RandomGenerator) DeepCopy() *RandomGenerator {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReadOnly.
func (in *ReadOnly) DeepCopy() *ReadOnly {
if in == nil {
return nil
}
out := new(RandomGenerator)
out := new(ReadOnly)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ReadOnly) DeepCopyInto(out *ReadOnly) {
func (in *Resource) DeepCopyInto(out *Resource) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReadOnly.
func (in *ReadOnly) DeepCopy() *ReadOnly {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resource.
func (in *Resource) DeepCopy() *Resource {
if in == nil {
return nil
}
out := new(ReadOnly)
out := new(Resource)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Resource) DeepCopyInto(out *Resource) {
func (in *Rng) DeepCopyInto(out *Rng) {
*out = *in
if in.Backend != nil {
in, out := &in.Backend, &out.Backend
if *in == nil {
*out = nil
} else {
*out = new(RngBackend)
**out = **in
}
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resource.
func (in *Resource) DeepCopy() *Resource {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rng.
func (in *Rng) DeepCopy() *Rng {
if in == nil {
return nil
}
out := new(Resource)
out := new(Rng)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RngBackend) DeepCopyInto(out *RngBackend) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RngBackend.
func (in *RngBackend) DeepCopy() *RngBackend {
if in == nil {
return nil
}
out := new(RngBackend)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *RngRate) DeepCopyInto(out *RngRate) {
*out = *in
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RngRate.
func (in *RngRate) DeepCopy() *RngRate {
if in == nil {
return nil
}
out := new(RngRate)
in.DeepCopyInto(out)
return out
}
Expand Down
Loading

0 comments on commit 5f20dbd

Please sign in to comment.