Skip to content

Commit 1b1c34a

Browse files
committed
virt-launcher,hooks: Expose CONTAINER_NAME env var
Expose on the sidecar a new env var CONTAINER_NAME, this way the container will able to know its full path volume mount on the compute container. More details can be found on kubevirt/community#294 section "Network Binding Plugin and Kubevirt requirements". Signed-off-by: Or Shoval <[email protected]>
1 parent da6d5cf commit 1b1c34a

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

pkg/hooks/hooks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
const HookSidecarListAnnotationName = "hooks.kubevirt.io/hookSidecars"
3131
const HookSocketsSharedDirectory = "/var/run/kubevirt-hooks"
3232

33+
const ContainerNameEnvVar = "CONTAINER_NAME"
34+
3335
type HookSidecarList []HookSidecar
3436

3537
type ConfigMap struct {

pkg/virt-controller/services/rendercontainer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type ContainerSpecRenderer struct {
3535
ports []k8sv1.ContainerPort
3636
capabilities *k8sv1.Capabilities
3737
args []string
38+
extraEnvVars []k8sv1.EnvVar
3839
}
3940

4041
type Option func(*ContainerSpecRenderer)
@@ -84,6 +85,8 @@ func (csr *ContainerSpecRenderer) envVars() []k8sv1.EnvVar {
8485
})
8586
}
8687

88+
env = append(env, csr.extraEnvVars...)
89+
8790
return env
8891
}
8992

@@ -183,6 +186,12 @@ func WithReadinessProbe(vmi *v1.VirtualMachineInstance) Option {
183186
}
184187
}
185188

189+
func WithExtraEnvVars(envVars []k8sv1.EnvVar) Option {
190+
return func(renderer *ContainerSpecRenderer) {
191+
renderer.extraEnvVars = append(renderer.extraEnvVars, envVars...)
192+
}
193+
}
194+
186195
func xdgEnvironmentVariables() []k8sv1.EnvVar {
187196
const varRun = "/var/run"
188197
return []k8sv1.EnvVar{

pkg/virt-controller/services/template.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,11 @@ func newSidecarContainerRenderer(sidecarName string, vmiSpec *v1.VirtualMachineI
740740
sidecarOpts := []Option{
741741
WithResourceRequirements(resources),
742742
WithArgs(requestedHookSidecar.Args),
743+
WithExtraEnvVars([]k8sv1.EnvVar{
744+
k8sv1.EnvVar{
745+
Name: hooks.ContainerNameEnvVar,
746+
Value: sidecarName,
747+
}}),
743748
}
744749

745750
var mounts []k8sv1.VolumeMount

pkg/virt-controller/services/template_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,11 @@ var _ = Describe("Template", func() {
28762876
MountPath: hooks.HookSocketsSharedDirectory,
28772877
SubPath: "hook-sidecar-0",
28782878
}))
2879+
2880+
Expect(pod.Spec.Containers[1].Env).To(ContainElement(k8sv1.EnvVar{
2881+
Name: hooks.ContainerNameEnvVar,
2882+
Value: "hook-sidecar-0",
2883+
}))
28792884
})
28802885

28812886
Context("with pod networking", func() {

0 commit comments

Comments
 (0)