-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virt-controller, template: use a builder pattern to handle launcher p…
…ods volumes Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
- Loading branch information
Showing
4 changed files
with
83 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package services | ||
|
||
import ( | ||
k8sv1 "k8s.io/api/core/v1" | ||
"kubevirt.io/kubevirt/pkg/util" | ||
"path/filepath" | ||
) | ||
|
||
type VolumeRendererOption func(renderer *VolumeRenderer) | ||
|
||
type VolumeRenderer struct { | ||
containerDiskDir string | ||
ephemeralDiskDir string | ||
virtShareDir string | ||
} | ||
|
||
func NewVolumeRenderer(ephemeralDisk string, containerDiskDir string, virtShareDir string) *VolumeRenderer { | ||
return &VolumeRenderer{ | ||
containerDiskDir: containerDiskDir, | ||
ephemeralDiskDir: ephemeralDisk, | ||
virtShareDir: virtShareDir, | ||
} | ||
} | ||
|
||
func (vr *VolumeRenderer) Mounts() []k8sv1.VolumeMount { | ||
volumeMounts := []k8sv1.VolumeMount{ | ||
mountPath("private", util.VirtPrivateDir), | ||
mountPath("public", util.VirtShareDir), | ||
mountPath("ephemeral-disks", vr.ephemeralDiskDir), | ||
mountPathWithPropagation(containerDisks, vr.containerDiskDir, k8sv1.MountPropagationHostToContainer), | ||
mountPath("libvirt-runtime", "/var/run/libvirt"), | ||
mountPath("sockets", filepath.Join(vr.virtShareDir, "sockets")), | ||
} | ||
return volumeMounts | ||
} | ||
|
||
func (vr *VolumeRenderer) Volumes() []k8sv1.Volume { | ||
volumes := []k8sv1.Volume{ | ||
emptyDirVolume("private"), | ||
emptyDirVolume("public"), | ||
emptyDirVolume("sockets"), | ||
} | ||
return volumes | ||
} | ||
|
||
func mountPath(name string, path string) k8sv1.VolumeMount { | ||
return k8sv1.VolumeMount{ | ||
Name: name, | ||
MountPath: path, | ||
} | ||
} | ||
|
||
func mountPathWithPropagation(name string, path string, propagation k8sv1.MountPropagationMode) k8sv1.VolumeMount { | ||
return k8sv1.VolumeMount{ | ||
Name: name, | ||
MountPath: path, | ||
MountPropagation: &propagation, | ||
} | ||
} | ||
|
||
func emptyDirVolume(name string) k8sv1.Volume { | ||
return k8sv1.Volume{ | ||
Name: name, | ||
VolumeSource: k8sv1.VolumeSource{ | ||
EmptyDir: &k8sv1.EmptyDirVolumeSource{}}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters