Skip to content

Commit 725289b

Browse files
committed
pkg/runtime-tools/generate: support new RDT fields
Add support for direct manipulation of the linuxRdt object in the container config. Signed-off-by: Markus Lehtonen <[email protected]>
1 parent a7832a2 commit 725289b

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

pkg/runtime-tools/generate/generate.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"slices"
2324
"sort"
2425
"strings"
2526

@@ -189,6 +190,7 @@ func (g *Generator) Adjust(adjust *nri.ContainerAdjustment) error {
189190
if err := g.AdjustRdtClass(resources.GetRdtClass().Get()); err != nil {
190191
return err
191192
}
193+
g.AdjustRdt(adjust.GetLinux().GetRdt())
192194

193195
if err := g.AdjustMounts(adjust.GetMounts()); err != nil {
194196
return err
@@ -388,6 +390,38 @@ func (g *Generator) AdjustRdtClass(rdtClass *string) error {
388390
return nil
389391
}
390392

393+
// AdjustRdt adjusts the intelRdt object in the OCI Spec.
394+
func (g *Generator) AdjustRdt(r *nri.LinuxRdt) {
395+
if r == nil {
396+
return
397+
}
398+
399+
g.AdjustRdtClosID(r.ClosId.Get())
400+
g.AdjustRdtSchemata(r.Schemata.Get())
401+
g.AdjustRdtEnableMonitoring(r.EnableMonitoring.Get())
402+
}
403+
404+
// AdjustRdtClosID adjusts the RDT CLOS id in the OCI Spec.
405+
func (g *Generator) AdjustRdtClosID(value *string) {
406+
if value != nil {
407+
g.SetLinuxIntelRdtClosID(*value)
408+
}
409+
}
410+
411+
// AdjustRdtSchemata adjusts the RDT schemata in the OCI Spec.
412+
func (g *Generator) AdjustRdtSchemata(value *[]string) {
413+
if value != nil {
414+
g.SetLinuxIntelRdtSchemata(*value)
415+
}
416+
}
417+
418+
// AdjustRdtEnableMonitoring adjusts the RDT monitoring in the OCI Spec.
419+
func (g *Generator) AdjustRdtEnableMonitoring(value *bool) {
420+
if value != nil {
421+
g.SetLinuxIntelRdtEnableMonitoring(*value)
422+
}
423+
}
424+
391425
// AdjustCgroupsPath adjusts the cgroup pseudofs path in the OCI Spec.
392426
func (g *Generator) AdjustCgroupsPath(path string) {
393427
if path != "" {
@@ -682,6 +716,24 @@ func (g *Generator) SetLinuxIntelRdt(rdt *rspec.LinuxIntelRdt) {
682716
g.Config.Linux.IntelRdt = rdt
683717
}
684718

719+
// SetLinuxIntelRdtClosID sets g.Config.Linux.IntelRdt.ClosID
720+
func (g *Generator) SetLinuxIntelRdtClosID(closID string) {
721+
g.initConfigLinuxIntelRdt()
722+
g.Config.Linux.IntelRdt.ClosID = closID
723+
}
724+
725+
// SetLinuxIntelRdtEnableMonitoring sets g.Config.Linux.IntelRdt.EnableMonitoring
726+
func (g *Generator) SetLinuxIntelRdtEnableMonitoring(value bool) {
727+
g.initConfigLinuxIntelRdt()
728+
g.Config.Linux.IntelRdt.EnableMonitoring = value
729+
}
730+
731+
// SetLinuxIntelRdtSchemata sets g.Config.Linux.IntelRdt.Schemata
732+
func (g *Generator) SetLinuxIntelRdtSchemata(schemata []string) {
733+
g.initConfigLinuxIntelRdt()
734+
g.Config.Linux.IntelRdt.Schemata = slices.Clone(schemata)
735+
}
736+
685737
// ClearLinuxResourcesBlockIO clears Block I/O settings.
686738
func (g *Generator) ClearLinuxResourcesBlockIO() {
687739
g.initConfigLinuxResources()
@@ -773,3 +825,10 @@ func (g *Generator) initConfigLinuxNetDevices() {
773825
g.Config.Linux.NetDevices = map[string]rspec.LinuxNetDevice{}
774826
}
775827
}
828+
829+
func (g *Generator) initConfigLinuxIntelRdt() {
830+
g.initConfigLinux()
831+
if g.Config.Linux.IntelRdt == nil {
832+
g.Config.Linux.IntelRdt = &rspec.LinuxIntelRdt{}
833+
}
834+
}

pkg/runtime-tools/generate/generate_suite_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,31 @@ var _ = Describe("Adjustment", func() {
457457
})
458458
})
459459

460+
When("has a RDT adjustment", func() {
461+
It("adjusts Spec correctly", func() {
462+
spec := makeSpec()
463+
adjust := &api.ContainerAdjustment{
464+
Linux: &api.LinuxContainerAdjustment{
465+
Rdt: &api.LinuxRdt{
466+
ClosId: api.String("foo"),
467+
Schemata: api.RepeatedString([]string{"L2:0=ff", "L3:0=f"}),
468+
EnableMonitoring: api.Bool(true),
469+
},
470+
},
471+
}
472+
473+
rg := &rgen.Generator{Config: spec}
474+
xg := xgen.SpecGenerator(rg)
475+
476+
Expect(xg).ToNot(BeNil())
477+
Expect(xg.Adjust(adjust)).To(Succeed())
478+
Expect(spec.Linux.IntelRdt).To(Equal(&rspec.LinuxIntelRdt{
479+
ClosID: "foo",
480+
Schemata: []string{"L2:0=ff", "L3:0=f"},
481+
EnableMonitoring: true,
482+
}))
483+
})
484+
})
460485
})
461486

462487
type specOption func(*rspec.Spec)

0 commit comments

Comments
 (0)