Skip to content

Commit

Permalink
fix(kube/builder): include ram disk into memory limits (#227)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Mar 31, 2024
1 parent f4ed874 commit 015638e
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions cluster/kube/builder/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,32 @@ func (b *Workload) container() corev1.Container {
kcontainer.Resources.Limits[resourceName] = resource.NewQuantity(int64(gpu.Units.Value()), resource.DecimalSI).DeepCopy()
}

if mem := service.Resources.Memory; mem != nil {
requestedMem := sdlutil.ComputeCommittedResources(b.settings.MemoryCommitLevel, mem.Quantity)
kcontainer.Resources.Requests[corev1.ResourceMemory] = resource.NewQuantity(int64(requestedMem.Value()), resource.DecimalSI).DeepCopy()
kcontainer.Resources.Limits[corev1.ResourceMemory] = resource.NewQuantity(int64(mem.Quantity.Value()), resource.DecimalSI).DeepCopy()
}
var requestedMem uint64

for _, ephemeral := range service.Resources.Storage {
attr := ephemeral.Attributes.Find(sdl.StorageAttributePersistent)
if persistent, _ := attr.AsBool(); !persistent {
requestedStorage := sdlutil.ComputeCommittedResources(b.settings.StorageCommitLevel, ephemeral.Quantity)
kcontainer.Resources.Requests[corev1.ResourceEphemeralStorage] = resource.NewQuantity(int64(requestedStorage.Value()), resource.DecimalSI).DeepCopy()
kcontainer.Resources.Limits[corev1.ResourceEphemeralStorage] = resource.NewQuantity(int64(ephemeral.Quantity.Value()), resource.DecimalSI).DeepCopy()

break
persistent, _ := attr.AsBool()
attr = ephemeral.Attributes.Find(sdl.StorageAttributeClass)
class, _ := attr.AsString()

if !persistent {
if class == "" {
requestedStorage := sdlutil.ComputeCommittedResources(b.settings.StorageCommitLevel, ephemeral.Quantity)
kcontainer.Resources.Requests[corev1.ResourceEphemeralStorage] = resource.NewQuantity(int64(requestedStorage.Value()), resource.DecimalSI).DeepCopy()
kcontainer.Resources.Limits[corev1.ResourceEphemeralStorage] = resource.NewQuantity(int64(ephemeral.Quantity.Value()), resource.DecimalSI).DeepCopy()
} else if class == "ram" {
requestedMem += ephemeral.Quantity.Value()
}
}
}

// fixme: ram is never expected to be nil
if mem := service.Resources.Memory; mem != nil {
requestedRam := sdlutil.ComputeCommittedResources(b.settings.MemoryCommitLevel, mem.Quantity)

Check failure on line 128 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var requestedRam should be requestedRAM (revive)

Check failure on line 128 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var requestedRam should be requestedRAM (revive)
kcontainer.Resources.Requests[corev1.ResourceMemory] = resource.NewQuantity(int64(requestedRam.Value()), resource.DecimalSI).DeepCopy()
kcontainer.Resources.Limits[corev1.ResourceMemory] = resource.NewQuantity(int64(mem.Quantity.Value()+requestedMem), resource.DecimalSI).DeepCopy()
}

if service.Params != nil {
for _, params := range service.Params.Storage {
kcontainer.VolumeMounts = append(kcontainer.VolumeMounts, corev1.VolumeMount{
Expand Down

0 comments on commit 015638e

Please sign in to comment.