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 @@ -210,6 +210,7 @@ The following pieces of container metadata are available to plugins in NRI:
- Unified cgroup v2 parameter map
- Linux seccomp profile and policy
- Linux network devices
- scheduling policy parameters
- container (init) process ID
- container (init process) exit status
- timestamp of container creation
Expand Down Expand Up @@ -260,6 +261,7 @@ container parameters:
- Linux seccomp policy
- Linux network devices
- Linux namespaces
- scheduling policy parameters

### Container Updates

Expand Down
39 changes: 39 additions & 0 deletions pkg/adaptation/adaptation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,20 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
)

case "linux scheduler":
a.SetLinuxScheduler(&api.LinuxScheduler{
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
Priority: 10,
Flags: []api.LinuxSchedulerFlag{
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
},
})

case "clear linux scheduler":
a.SetLinuxScheduler(&api.LinuxScheduler{
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
})

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

Entry("adjust linux scheduler", "linux scheduler",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Scheduler: &api.LinuxScheduler{
Policy: api.LinuxSchedulerPolicy_SCHED_FIFO,
Priority: 10,
Flags: []api.LinuxSchedulerFlag{
api.LinuxSchedulerFlag_SCHED_FLAG_RESET_ON_FORK,
},
},
},
},
),

Entry("clear I/O priority", "clear I/O priority",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
IoPriority: &api.LinuxIOPriority{},
},
},
),
Entry("clear linux scheduler", "clear linux scheduler",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Scheduler: &api.LinuxScheduler{
Policy: api.LinuxSchedulerPolicy_SCHED_NONE,
},
},
},
),

Entry("adjust CPU resources", "resources/cpu",
&api.ContainerAdjustment{
Expand Down Expand Up @@ -1071,6 +1108,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),

Entry("adjust linux net devices", "linux net device", true, false,
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Expand All @@ -1084,6 +1122,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
),
Entry("adjust linux net devices (conflicts)", "linux net device", false, true, nil),
Entry("adjust linux scheduler (conflicts)", "linux scheduler", false, true, nil),
)
})

Expand Down
3 changes: 3 additions & 0 deletions pkg/adaptation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type (
LinuxIOPriority = api.LinuxIOPriority
LinuxSeccomp = api.LinuxSeccomp
LinuxNetDevice = api.LinuxNetDevice
LinuxScheduler = api.LinuxScheduler
LinuxSchedulerPolicy = api.LinuxSchedulerPolicy
LinuxSchedulerFlag = api.LinuxSchedulerFlag
CDIDevice = api.CDIDevice
HugepageLimit = api.HugepageLimit
Hooks = api.Hooks
Expand Down
20 changes: 20 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustLinuxNetDevices(rpl.Linux.NetDevices, plugin); err != nil {
return err
}
if err := r.adjustLinuxScheduler(rpl.Linux.Scheduler, plugin); err != nil {
return err
}
}
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
Expand Down Expand Up @@ -954,6 +957,23 @@ func (r *result) adjustSeccompPolicy(adjustment *LinuxSeccomp, plugin string) er
return nil
}

func (r *result) adjustLinuxScheduler(sch *LinuxScheduler, plugin string) error {
if sch == nil {
return nil
}

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

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

create.Container.Linux.Scheduler = sch
r.reply.adjust.Linux.Scheduler = sch

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 @@ -337,6 +337,12 @@ func (a *ContainerAdjustment) SetLinuxSysctl(key, value string) {
a.Linux.Sysctl[key] = value
}

// SetLinuxScheduler records setting the Linux scheduler attributes for a container.
func (a *ContainerAdjustment) SetLinuxScheduler(sch *LinuxScheduler) {
a.initLinux()
a.Linux.Scheduler = sch
}

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