Skip to content

Commit

Permalink
Merge pull request kubevirt#2701 from alonSadan/change_template_to_ma…
Browse files Browse the repository at this point in the history
…squerade

add masquerade binding method to templates
  • Loading branch information
kubevirt-bot authored Sep 25, 2019
2 parents 8d892d9 + f3e4f92 commit 82381b0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
6 changes: 6 additions & 0 deletions examples/vm-template-fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ objects:
- disk:
bus: virtio
name: cloudinitdisk
interfaces:
- masquerade: {}
name: default
rng: {}
machine:
type: ""
resources:
requests:
memory: ${MEMORY}
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 0
volumes:
- containerDisk:
Expand Down
6 changes: 6 additions & 0 deletions examples/vm-template-rhel7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ objects:
- disk:
bus: virtio
name: disk0
interfaces:
- masquerade: {}
name: default
machine:
type: ""
resources:
requests:
memory: ${MEMORY}
networks:
- name: default
pod: {}
terminationGracePeriodSeconds: 0
volumes:
- name: disk0
Expand Down
51 changes: 44 additions & 7 deletions tools/vms-generator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
)

const windowsFirmware = "5d307ca9-b3ef-428c-8861-06e72d69f223"
const defaultInterfaceName = "default"

var DockerPrefix = "registry:5000/kubevirt"
var DockerTag = "devel"
Expand Down Expand Up @@ -123,6 +124,22 @@ func getBaseVMI(name string) *v1.VirtualMachineInstance {
func initFedora(spec *v1.VirtualMachineInstanceSpec) *v1.VirtualMachineInstanceSpec {
addContainerDisk(spec, fmt.Sprintf("%s/%s:%s", DockerPrefix, imageFedora, DockerTag), busVirtio)
addRNG(spec) // without RNG, newer fedora images may hang waiting for entropy sources

return spec
}

func setDefaultNetworkAndInterface(spec *v1.VirtualMachineInstanceSpec, bindingMethod v1.InterfaceBindingMethod, networkSource v1.NetworkSource) *v1.VirtualMachineInstanceSpec {
spec.Domain.Devices.Interfaces = []v1.Interface{
v1.Interface{
Name: defaultInterfaceName,
InterfaceBindingMethod: bindingMethod},
}
spec.Networks = []v1.Network{
v1.Network{
Name: defaultInterfaceName,
NetworkSource: networkSource},
}

return spec
}

Expand Down Expand Up @@ -352,7 +369,6 @@ func GetVMIMasquerade() *v1.VirtualMachineInstance {
vm := getBaseVMI(VmiMasquerade)
vm.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1024M")
vm.Spec.Networks = []v1.Network{v1.Network{Name: "testmasquerade", NetworkSource: v1.NetworkSource{Pod: &v1.PodNetwork{}}}}

initFedora(&vm.Spec)
addNoCloudDiskWitUserData(&vm.Spec, "#!/bin/bash\necho \"fedora\" |passwd fedora --stdin\nyum install -y nginx\nsystemctl enable nginx\nsystemctl start nginx")

Expand Down Expand Up @@ -560,8 +576,16 @@ func GetVMCirros() *v1.VirtualMachine {

func GetTemplateFedora() *Template {
vm := getBaseVM("", map[string]string{"kubevirt-vm": "vm-${NAME}", "kubevirt.io/os": "fedora27"})
initFedora(&vm.Spec.Template.Spec)
addNoCloudDiskWitUserData(&vm.Spec.Template.Spec, "#cloud-config\npassword: fedora\nchpasswd: { expire: False }")
spec := &vm.Spec.Template.Spec
initFedora(spec)
addNoCloudDiskWitUserData(spec, "#cloud-config\npassword: fedora\nchpasswd: { expire: False }")

setDefaultNetworkAndInterface(spec, v1.InterfaceBindingMethod{
Masquerade: &v1.InterfaceMasquerade{},
},
v1.NetworkSource{
Pod: &v1.PodNetwork{},
})

template := getBaseTemplate(vm, "4096Mi", "4")
template.ObjectMeta = metav1.ObjectMeta{
Expand All @@ -581,18 +605,31 @@ func GetTemplateFedora() *Template {

func GetTemplateRHEL7() *Template {
vm := getBaseVM("", map[string]string{"kubevirt-vm": "vm-${NAME}", "kubevirt.io/os": "rhel-7.4"})
addPVCDisk(&vm.Spec.Template.Spec, "linux-vm-pvc-${NAME}", busVirtio, "disk0")

spec := &vm.Spec.Template.Spec
setDefaultNetworkAndInterface(spec, v1.InterfaceBindingMethod{
Masquerade: &v1.InterfaceMasquerade{},
},
v1.NetworkSource{
Pod: &v1.PodNetwork{},
})

addPVCDisk(spec, "linux-vm-pvc-${NAME}", busVirtio, "disk0")
pvc := getPVCForTemplate("linux-vm-pvc-${NAME}")
template := newTemplateForRHEL7VM(vm)
template.Objects = append(template.Objects, pvc)

return template
}

func GetTestTemplateRHEL7() *Template {
vm := getBaseVM("", map[string]string{"kubevirt-vm": "vm-${NAME}", "kubevirt.io/os": "rhel-7.4"})
addEphemeralPVCDisk(&vm.Spec.Template.Spec, "disk-rhel", busSata, "pvcdisk")
spec := &vm.Spec.Template.Spec
addEphemeralPVCDisk(spec, "disk-rhel", busSata, "pvcdisk")
setDefaultNetworkAndInterface(spec, v1.InterfaceBindingMethod{
Masquerade: &v1.InterfaceMasquerade{},
},
v1.NetworkSource{
Pod: &v1.PodNetwork{},
})

return newTemplateForRHEL7VM(vm)
}
Expand Down

0 comments on commit 82381b0

Please sign in to comment.