Skip to content

Commit

Permalink
hooks: mount shared directory to main container and hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
phoracek committed Jul 2, 2018
1 parent 79c1582 commit bb5d086
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/hooks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

const HookSidecarListAnnotationName = "hookSidecars"
const HookSocketsSharedDirectory = "/var/run/kubevirt-hooks"

type HookSidecarList []HookSidecar

Expand Down
19 changes: 19 additions & 0 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (
}
}

if len(requestedHookSidecarList) != 0 {
volumes = append(volumes, k8sv1.Volume{
Name: "hooks",
VolumeSource: k8sv1.VolumeSource{
EmptyDir: &k8sv1.EmptyDirVolumeSource{},
},
})
volumesMounts = append(volumesMounts, k8sv1.VolumeMount{
Name: "hooks",
MountPath: hooks.HookSocketsSharedDirectory,
})
}

command := []string{"/usr/share/kubevirt/virt-launcher/entrypoint.sh",
"--qemu-timeout", "5m",
"--name", domain,
Expand Down Expand Up @@ -321,6 +334,12 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (
Name: "hook-sidecar-" + requestedHookSidecar.Image,
Image: requestedHookSidecar.Image,
ImagePullPolicy: requestedHookSidecar.ImagePullPolicy,
VolumeMounts: []k8sv1.VolumeMount{
k8sv1.VolumeMount{
Name: "hooks",
MountPath: hooks.HookSocketsSharedDirectory,
},
},
})
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/virt-controller/services/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var _ = Describe("Template", func() {
pod, err := svc.RenderLaunchManifest(&v1.VirtualMachineInstance{ObjectMeta: metav1.ObjectMeta{Name: "testvmi", Namespace: "testns", UID: "1234", Annotations: annotations}, Spec: v1.VirtualMachineInstanceSpec{Domain: v1.DomainSpec{}}})
Expect(err).ToNot(HaveOccurred())

Expect(len(pod.Spec.Containers)).To(Equal(2))
Expect(pod.Spec.Containers[0].Image).To(Equal("kubevirt/virt-launcher"))
Expect(pod.ObjectMeta.Labels).To(Equal(map[string]string{
v1.AppLabel: "virt-launcher",
Expand Down Expand Up @@ -100,6 +101,7 @@ var _ = Describe("Template", func() {
pod, err := svc.RenderLaunchManifest(&vmi)
Expect(err).ToNot(HaveOccurred())

Expect(len(pod.Spec.Containers)).To(Equal(2))
Expect(pod.Spec.Containers[0].Image).To(Equal("kubevirt/virt-launcher"))
Expect(pod.ObjectMeta.Labels).To(Equal(map[string]string{
v1.AppLabel: "virt-launcher",
Expand All @@ -121,7 +123,9 @@ var _ = Describe("Template", func() {
Expect(pod.Spec.Containers[1].Name).To(Equal("hook-sidecar-some-image:v1"))
Expect(pod.Spec.Containers[1].Image).To(Equal("some-image:v1"))
Expect(pod.Spec.Containers[1].ImagePullPolicy).To(Equal(kubev1.PullPolicy("IfNotPresent")))
Expect(pod.Spec.Volumes[0].HostPath.Path).To(Equal("/var/run/kubevirt"))
Expect(pod.Spec.Containers[1].VolumeMounts[0].MountPath).To(Equal(hooks.HookSocketsSharedDirectory))
Expect(pod.Spec.Volumes[0].EmptyDir.Medium).To(Equal(kubev1.StorageMedium("")))
Expect(pod.Spec.Volumes[1].HostPath.Path).To(Equal("/var/run/kubevirt"))
Expect(pod.Spec.Containers[0].VolumeMounts[0].MountPath).To(Equal("/var/run/kubevirt"))
Expect(*pod.Spec.TerminationGracePeriodSeconds).To(Equal(int64(60)))
})
Expand Down

0 comments on commit bb5d086

Please sign in to comment.