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

Commit

Permalink
Apply task CPUMillis to job spec
Browse files Browse the repository at this point in the history
CPUWeight was not being used in production code. It also had a strange
datatype of uint8 which was not suitable for a CPU request. Given that
korifi is eirini-controller's only client, we can remove this field
without problems.

Add a new field CPUMillis accurately describing the property. This is
applied to the request CPU in the job's container spec.

Issue: cloudfoundry/korifi#1203
  • Loading branch information
Kieron Browne committed Jul 21, 2022
1 parent e25dea1 commit bc6835f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion k8s/jobs/desire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Desire", func() {
OrgGUID: "org-id",
GUID: taskGUID,
MemoryMB: 1,
CPUWeight: 2,
CPUMillis: 2,
DiskMB: 3,
},
}
Expand Down
1 change: 1 addition & 0 deletions k8s/jobs/task_to_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (m *Converter) Convert(task *eiriniv1.Task, privateRegistrySecret *corev1.S
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceMemory: *resource.NewScaledQuantity(task.Spec.MemoryMB, resource.Mega),
corev1.ResourceEphemeralStorage: *resource.NewScaledQuantity(task.Spec.DiskMB, resource.Mega),
corev1.ResourceCPU: *resource.NewScaledQuantity(task.Spec.CPUMillis, resource.Milli),
},
},
SecurityContext: k8s.ContainerSecurityContext(),
Expand Down
11 changes: 6 additions & 5 deletions k8s/jobs/task_to_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _ = Describe("TaskToJob", func() {
"my-env-var": "env",
},
MemoryMB: 1,
CPUWeight: 2,
CPUMillis: 2,
DiskMB: 3,
},
}
Expand Down Expand Up @@ -144,10 +144,11 @@ var _ = Describe("TaskToJob", func() {

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))
Expect(resources.Limits.Memory().ScaledValue(resource.Mega)).To(BeEquivalentTo(1))
Expect(resources.Requests.Memory().ScaledValue(resource.Mega)).To(BeEquivalentTo(1))
Expect(resources.Limits.StorageEphemeral().ScaledValue(resource.Mega)).To(BeEquivalentTo(3))
Expect(resources.Requests.StorageEphemeral().ScaledValue(resource.Mega)).To(BeEquivalentTo(3))
Expect(resources.Requests.Cpu().ScaledValue(resource.Milli)).To(BeEquivalentTo(2))
})

By("configuring pod security context", func() {
Expand Down
2 changes: 1 addition & 1 deletion k8s/reconciler/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var _ = Describe("Task", func() {
SpaceGUID: "spacid",
MemoryMB: 768,
DiskMB: 512,
CPUWeight: 13,
CPUMillis: 13,
},
}
statusGetter.GetStatusConditionsReturns([]metav1.Condition{
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/eirini/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type TaskSpec struct {
SpaceGUID string `json:"spaceGUID"`
MemoryMB int64 `json:"memoryMB"`
DiskMB int64 `json:"diskMB"`
// +kubebuilder:validation:Format:=uint8
CPUWeight uint8 `json:"cpuWeight"`
CPUMillis int64 `json:"cpuMillis"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down

0 comments on commit bc6835f

Please sign in to comment.