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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ The following pieces of container metadata are available to plugins in NRI:
- mounts
- OCI hooks
- rlimits
- I/O priority
- linux
- namespace IDs
- devices
Expand Down Expand Up @@ -227,6 +228,7 @@ container parameters:
- environment variables
- OCI hooks
- rlimits
- I/O priority
- linux
- devices
- resources
Expand Down
31 changes: 31 additions & 0 deletions pkg/adaptation/adaptation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,17 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
)

case "I/O priority":
a.SetLinuxIOPriority(&nri.LinuxIOPriority{
Class: api.IOPrioClass_IOPRIO_CLASS_RT,
Priority: 5,
})

case "clear I/O priority":
a.SetLinuxIOPriority(&nri.LinuxIOPriority{
Class: api.IOPrioClass_IOPRIO_CLASS_NONE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Priority: 0, // :-)

})

case "resources/cpu":
a.SetLinuxCPUShares(123)
a.SetLinuxCPUQuota(456)
Expand Down Expand Up @@ -700,6 +711,25 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
},
),

Entry("adjust I/O priority", "I/O priority",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
IoPriority: &api.LinuxIOPriority{
Class: api.IOPrioClass_IOPRIO_CLASS_RT,
Priority: 5,
},
},
},
),
Entry("clear I/O priority", "clear I/O priority",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
IoPriority: &api.LinuxIOPriority{},
},
},
),

Entry("adjust CPU resources", "resources/cpu",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Expand Down Expand Up @@ -921,6 +951,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
),
Entry("adjust resources", "resources/classes", false, true, nil),
Entry("adjust I/O priority (conflicts)", "I/O priority", false, true, nil),
)
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/adaptation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type (
LinuxMemory = api.LinuxMemory
LinuxDevice = api.LinuxDevice
LinuxDeviceCgroup = api.LinuxDeviceCgroup
LinuxIOPriority = api.LinuxIOPriority
CDIDevice = api.CDIDevice
HugepageLimit = api.HugepageLimit
Hooks = api.Hooks
Expand Down Expand Up @@ -160,6 +161,7 @@ var (
FromOCILinuxNamespaces = api.FromOCILinuxNamespaces
FromOCILinuxDevices = api.FromOCILinuxDevices
FromOCILinuxResources = api.FromOCILinuxResources
FromOCILinuxIOPriority = api.FromOCILinuxIOPriority
DupStringSlice = api.DupStringSlice
DupStringMap = api.DupStringMap
IsMarkedForRemoval = api.IsMarkedForRemoval
Expand Down
20 changes: 20 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
return err
}
if err := r.adjustIOPriority(rpl.Linux.IoPriority, plugin); err != nil {
return err
}
}
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
Expand Down Expand Up @@ -773,6 +776,23 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
return nil
}

func (r *result) adjustIOPriority(priority *LinuxIOPriority, plugin string) error {
if priority == nil {
return nil
}

create, id := r.request.create, r.request.create.Container.Id

if err := r.owners.ClaimIOPriority(id, plugin); err != nil {
return err
}

create.Container.Linux.IoPriority = priority
r.reply.adjust.Linux.IoPriority = priority

return nil
}

func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
for _, l := range rlimits {
Expand Down
6 changes: 6 additions & 0 deletions pkg/api/adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (a *ContainerAdjustment) SetLinuxOomScoreAdj(value *int) {
a.Linux.OomScoreAdj = Int(value) // using Int(value) from ./options.go to optionally allocate a pointer to normalized copy of value
}

// SetLinuxIOPriority records setting the I/O priority for a container.
func (a *ContainerAdjustment) SetLinuxIOPriority(ioprio *LinuxIOPriority) {
a.initLinux()
a.Linux.IoPriority = ioprio
}

//
// Initializing a container adjustment and container update.
//
Expand Down
Loading
Loading