Skip to content

Commit 22f776f

Browse files
authored
Merge pull request #3253 from samifruit514/master
driver kubernetes: allow to work in a Memory mount to speed up things
2 parents d09eb75 + d5f914a commit 22f776f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-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-volume-memory":
290+
if v != "" {
291+
deploymentOpt.BuildKitRootVolumeMemory = v
292+
}
289293
case "default-load":
290294
defaultLoad, err = strconv.ParseBool(v)
291295
if err != nil {

driver/kubernetes/manifest/manifest.go

Lines changed: 23 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+
BuildKitRootVolumeMemory string
3536
Rootless bool
3637
NodeSelector map[string]string
3738
CustomAnnotations map[string]string
@@ -50,6 +51,8 @@ const (
5051
containerName = "buildkitd"
5152
AnnotationPlatform = "buildx.docker.com/platform"
5253
LabelApp = "app"
54+
rootVolumeName = "buildkit-memory"
55+
rootVolumePath = "/var/lib/buildkit"
5356
)
5457

5558
type ErrReservedAnnotationPlatform struct{}
@@ -247,6 +250,26 @@ func NewDeployment(opt *DeploymentOpt) (d *appsv1.Deployment, c []*corev1.Config
247250
d.Spec.Template.Spec.Containers[0].Resources.Limits[corev1.ResourceEphemeralStorage] = limEphemeralStorage
248251
}
249252

253+
if opt.BuildKitRootVolumeMemory != "" {
254+
buildKitRootVolumeMemory, err := resource.ParseQuantity(opt.BuildKitRootVolumeMemory)
255+
if err != nil {
256+
return nil, nil, err
257+
}
258+
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, corev1.Volume{
259+
Name: rootVolumeName,
260+
VolumeSource: corev1.VolumeSource{
261+
EmptyDir: &corev1.EmptyDirVolumeSource{
262+
Medium: "Memory",
263+
SizeLimit: &buildKitRootVolumeMemory,
264+
},
265+
},
266+
})
267+
d.Spec.Template.Spec.Containers[0].VolumeMounts = append(d.Spec.Template.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
268+
Name: rootVolumeName,
269+
MountPath: rootVolumePath,
270+
})
271+
}
272+
250273
return
251274
}
252275

0 commit comments

Comments
 (0)