Skip to content

Commit 7c2f0cc

Browse files
author
Samuel Archambault
committed
driver kubernetes: allow to work in a Memory mount to speed up things
Signed-off-by: Samuel Archambault <[email protected]>
1 parent 08dd378 commit 7c2f0cc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

driver/kubernetes/factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ func (f *factory) processDriverOpts(deploymentName string, namespace string, cfg
286286
if v != "" {
287287
deploymentOpt.Qemu.Image = v
288288
}
289+
case "buildkit-root-folder-memory":
290+
if v != "" {
291+
deploymentOpt.BuildKitRootFolderMemory = v
292+
}
289293
case "default-load":
290294
defaultLoad, err = strconv.ParseBool(v)
291295
if err != nil {

driver/kubernetes/manifest/manifest.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type DeploymentOpt struct {
3232
// files mounted at /etc/buildkitd
3333
ConfigFiles map[string][]byte
3434

35+
BuildKitRootFolderMemory string
3536
Rootless bool
3637
NodeSelector map[string]string
3738
CustomAnnotations map[string]string
@@ -50,6 +51,7 @@ const (
5051
containerName = "buildkitd"
5152
AnnotationPlatform = "buildx.docker.com/platform"
5253
LabelApp = "app"
54+
memoryVolumeName = "buildkit-memory"
5355
)
5456

5557
type ErrReservedAnnotationPlatform struct{}
@@ -247,6 +249,26 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c []*corev1.Config
247249
d.Spec.Template.Spec.Containers[0].Resources.Limits[corev1.ResourceEphemeralStorage] = limEphemeralStorage
248250
}
249251

252+
if opt.BuildKitRootFolderMemory != "" {
253+
buildKitRootFolderMemory, err := resource.ParseQuantity(opt.BuildKitRootFolderMemory)
254+
if err != nil {
255+
return nil, nil, err
256+
}
257+
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, corev1.Volume{
258+
Name: "buildkit-memory",
259+
VolumeSource: corev1.VolumeSource{
260+
EmptyDir: &corev1.EmptyDirVolumeSource{
261+
Medium: "Memory",
262+
SizeLimit: &buildKitRootFolderMemory,
263+
},
264+
},
265+
})
266+
d.Spec.Template.Spec.Containers[0].VolumeMounts = append(d.Spec.Template.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
267+
Name: "buildkit-memory",
268+
MountPath: "/var/lib/buildkit",
269+
})
270+
}
271+
250272
return
251273
}
252274

0 commit comments

Comments
 (0)