Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/device/mthreads/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ func (dev *MthreadsDevices) MutateAdmission(ctr *corev1.Container, p *corev1.Pod
if count.Value() <= 0 {
return false, fmt.Errorf("%s must be greater than 0", MthreadsResourceCount)
}
if ctr.Resources.Limits == nil {
Comment thread
imantaba marked this conversation as resolved.
Resolved
ctr.Resources.Limits = corev1.ResourceList{}
}
if count.Value() > 1 {
ctr.Resources.Limits[corev1.ResourceName(MthreadsResourceCores)] = *resource.NewQuantity(count.Value()*int64(coresPerMthreadsGPU), resource.DecimalSI)
ctr.Resources.Limits[corev1.ResourceName(MthreadsResourceMemory)] = *resource.NewQuantity(count.Value()*int64(memoryPerMthreadsGPU), resource.DecimalSI)
if p.Annotations == nil {
p.Annotations = make(map[string]string)
}
p.Annotations["mthreads.com/request-gpu-num"] = fmt.Sprint(count.Value())
return ok, nil
}
Expand Down
59 changes: 59 additions & 0 deletions pkg/device/mthreads/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,65 @@ func Test_MutateAdmission(t *testing.T) {
},
want: true,
},
{
Comment thread
archlitchi marked this conversation as resolved.
Resolved
name: "count over one without pod annotations",
args: struct {
ctr *corev1.Container
p *corev1.Pod
}{
ctr: &corev1.Container{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
"mthreads.com/vgpu": *resource.NewQuantity(2, resource.DecimalSI),
},
},
},
p: &corev1.Pod{},
},
want: true,
},
{
name: "count over one requested without limits",
args: struct {
ctr *corev1.Container
p *corev1.Pod
}{
ctr: &corev1.Container{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
"mthreads.com/vgpu": *resource.NewQuantity(2, resource.DecimalSI),
},
},
},
p: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{},
},
},
},
want: true,
},
{
name: "count one requested without limits",
args: struct {
ctr *corev1.Container
p *corev1.Pod
}{
ctr: &corev1.Container{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
"mthreads.com/vgpu": *resource.NewQuantity(1, resource.DecimalSI),
},
},
},
p: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{},
},
},
},
want: true,
},
{
name: "don't set to count limit",
args: struct {
Expand Down
Loading