Skip to content

Commit

Permalink
hooks: add requested hook sidecars as containers to VM Pod
Browse files Browse the repository at this point in the history
  • Loading branch information
phoracek committed Jul 2, 2018
1 parent 03c7c33 commit 79c1582
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,13 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (
}

// Read requested hookSidecars from VM annotation
// TODO: Add requested sidecars as Containers to Pod
numberOfRequestedHookSidecars := 0
var err error
requestedHookSidecarList := make(hooks.HookSidecarList, 0)
if rawRequestedHookSidecarList, requestedHookSidecarListDefined := vm.GetObjectMeta().GetAnnotations()[hooks.HookSidecarListAnnotationName]; requestedHookSidecarListDefined {
requestedHookSidecarList, err := hooks.UnmarshalHookSidecarList(rawRequestedHookSidecarList)
requestedHookSidecarList, err = hooks.UnmarshalHookSidecarList(rawRequestedHookSidecarList)
if err != nil {
return nil, err
}
numberOfRequestedHookSidecars = len(requestedHookSidecarList)
}

command := []string{"/usr/share/kubevirt/virt-launcher/entrypoint.sh",
Expand All @@ -224,7 +223,7 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (
"--kubevirt-share-dir", t.virtShareDir,
"--readiness-file", "/tmp/healthy",
"--grace-period-seconds", strconv.Itoa(int(gracePeriodSeconds)),
"--requested-hooks", strconv.Itoa(numberOfRequestedHookSidecars),
"--requested-hooks", strconv.Itoa(len(requestedHookSidecarList)),
}

useEmulation, err := IsEmulationAllowed(t.store)
Expand Down Expand Up @@ -317,6 +316,14 @@ func (t *templateService) RenderLaunchManifest(vmi *v1.VirtualMachineInstance) (

containers = append(containers, container)

for _, requestedHookSidecar := range requestedHookSidecarList {
containers = append(containers, k8sv1.Container{
Name: "hook-sidecar-" + requestedHookSidecar.Image,
Image: requestedHookSidecar.Image,
ImagePullPolicy: requestedHookSidecar.ImagePullPolicy,
})
}

hostName := dns.SanitizeHostname(vmi)

// TODO use constants for podLabels
Expand Down
6 changes: 6 additions & 0 deletions pkg/virt-controller/services/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ var _ = Describe("Template", func() {
"--readiness-file", "/tmp/healthy",
"--grace-period-seconds", "45",
"--requested-hooks", "1"}))
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.TerminationGracePeriodSeconds).To(Equal(int64(60)))
By("setting the right hostname")
Expect(pod.Spec.Hostname).To(Equal("testvmi"))
Expand Down Expand Up @@ -115,6 +118,9 @@ var _ = Describe("Template", func() {
"--readiness-file", "/tmp/healthy",
"--grace-period-seconds", "45",
"--requested-hooks", "1"}))
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[0].VolumeMounts[0].MountPath).To(Equal("/var/run/kubevirt"))
Expect(*pod.Spec.TerminationGracePeriodSeconds).To(Equal(int64(60)))
Expand Down

0 comments on commit 79c1582

Please sign in to comment.