Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Set resource limits/requests on tasks' jobs
Browse files Browse the repository at this point in the history
Issue: cloudfoundry/korifi#1197

Co-authored-by: Georgi Sabev <[email protected]>
  • Loading branch information
danail-branekov and georgethebeatle committed Jun 15, 2022
1 parent 8dfe718 commit 74fa3e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions k8s/jobs/task_to_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
eiriniv1 "code.cloudfoundry.org/eirini-controller/pkg/apis/eirini/v1"
batch "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

const (
Expand Down Expand Up @@ -49,6 +50,16 @@ func (m *Converter) Convert(task *eiriniv1.Task, privateRegistrySecret *corev1.S
ImagePullPolicy: corev1.PullAlways,
Env: envs,
Command: task.Spec.Command,
Resources: corev1.ResourceRequirements{
Limits: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceMemory: *resource.NewScaledQuantity(task.Spec.MemoryMB, resource.Mega),
corev1.ResourceEphemeralStorage: *resource.NewScaledQuantity(task.Spec.DiskMB, resource.Mega),
},
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceMemory: *resource.NewScaledQuantity(task.Spec.MemoryMB, resource.Mega),
corev1.ResourceEphemeralStorage: *resource.NewScaledQuantity(task.Spec.DiskMB, resource.Mega),
},
},
},
}

Expand Down
9 changes: 9 additions & 0 deletions k8s/jobs/task_to_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/gomega/gstruct"
batch "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -143,6 +144,14 @@ var _ = Describe("TaskToJob", func() {
corev1.LocalObjectReference{Name: "registry-secret"},
))
})

By("setting limits and request", func() {
resources := job.Spec.Template.Spec.Containers[0].Resources
Expect(resources.Limits.Memory().ScaledValue(resource.Mega)).To(BeNumerically("==", 1))
Expect(resources.Requests.Memory().ScaledValue(resource.Mega)).To(BeNumerically("==", 1))
Expect(resources.Limits.StorageEphemeral().ScaledValue(resource.Mega)).To(BeNumerically("==", 3))
Expect(resources.Requests.StorageEphemeral().ScaledValue(resource.Mega)).To(BeNumerically("==", 3))
})
})

When("the task has environment set", func() {
Expand Down

0 comments on commit 74fa3e7

Please sign in to comment.