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
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ PLUGINS := \
$(BIN_PATH)/template \
$(BIN_PATH)/wasm \
$(BIN_PATH)/network-device-injector \
$(BIN_PATH)/network-logger
$(BIN_PATH)/network-logger \
$(BIN_PATH)/rdt

ifneq ($(V),1)
Q := @
Expand Down Expand Up @@ -128,9 +129,9 @@ $(BIN_PATH)/wasm build/bin/wasm: FORCE
# test targets
#

test-gopkgs: ginkgo-tests test-ulimits
test-gopkgs: ginkgo-tests test-ulimits test-rdt

SKIPPED_PKGS="ulimit-adjuster,device-injector"
SKIPPED_PKGS="ulimit-adjuster,device-injector,rdt"

ginkgo-tests:
$(Q)$(GINKGO) run \
Expand All @@ -152,6 +153,9 @@ test-ulimits:
test-device-injector:
$(Q)cd ./plugins/device-injector && $(GO_TEST) -v

test-rdt:
$(Q)cd ./plugins/rdt && $(GO_TEST) -v

codecov: SHELL := $(shell which bash)
codecov:
bash <(curl -s https://codecov.io/bash) -f $(COVERAGE_PATH)/coverprofile
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ The following sample plugins exist for NRI:
- [ulimit adjuster](plugins/ulimit-adjuster)
- [NRI v0.1.0 plugin adapter](plugins/v010-adapter)
- [WebAssembly plugin](plugins/wasm)
- [RDT](plugins/rdt)
- [template](plugins/template)

Please see the documentation of these plugins for further details
Expand Down
30 changes: 30 additions & 0 deletions contrib/kustomize/rdt/base/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nri-plugin-rdt
spec:
template:
spec:
containers:
- name: plugin
image: plugin:latest
args:
- "-idx"
- "10"
resources:
requests:
cpu: "2m"
memory: "5Mi"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumeMounts:
- name: nri-socket
mountPath: /var/run/nri/nri.sock
volumes:
- name: nri-socket
hostPath:
path: /var/run/nri/nri.sock
type: Socket
12 changes: 12 additions & 0 deletions contrib/kustomize/rdt/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: kube-system
resources:
- daemonset.yaml
images:
- name: plugin
newName: ghcr.io/containerd/nri/plugins/rdt
labels:
- includeSelectors: true
pairs:
app.kubernetes.io/name: nri-plugin-rdt
6 changes: 6 additions & 0 deletions contrib/kustomize/rdt/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- base/
components:
- ../components/image-stable
6 changes: 6 additions & 0 deletions contrib/kustomize/rdt/unstable/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base/
components:
- ../../components/image-unstable
32 changes: 32 additions & 0 deletions pkg/adaptation/adaptation_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,13 @@ var _ = Describe("Plugin container creation adjustments", func() {
return api.FromOCILinuxSeccomp(&seccomp)
}(),
)
case "rdt":
if overwrite {
a.RemoveLinuxRDT()
}
a.SetLinuxRDTClosID(p.name)
a.SetLinuxRDTSchemata([]string{"L3:0=ff", "MB:0=50"})
a.SetLinuxRDTEnableMonitoring(true)
}

return a, nil, nil
Expand Down Expand Up @@ -948,6 +955,17 @@ var _ = Describe("Plugin container creation adjustments", func() {
},
},
),
Entry("adjust RDT", "rdt",
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Rdt: &api.LinuxRdt{
ClosId: api.String("test"),
Schemata: api.RepeatedString([]string{"L3:0=ff", "MB:0=50"}),
EnableMonitoring: api.Bool(true),
},
},
},
),
)
})

Expand Down Expand Up @@ -1121,8 +1139,22 @@ 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),

Entry("adjust RDT (conflicts)", "rdt", false, true, nil),
Entry("adjust RDT", "rdt", true, false,
&api.ContainerAdjustment{
Linux: &api.LinuxContainerAdjustment{
Rdt: &api.LinuxRdt{
ClosId: api.String("foo"),
Schemata: api.RepeatedString([]string{"L3:0=ff", "MB:0=50"}),
EnableMonitoring: api.Bool(true),
},
},
},
),
)
})

Expand Down
18 changes: 10 additions & 8 deletions pkg/adaptation/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type (
LinuxScheduler = api.LinuxScheduler
LinuxSchedulerPolicy = api.LinuxSchedulerPolicy
LinuxSchedulerFlag = api.LinuxSchedulerFlag
LinuxRdt = api.LinuxRdt
CDIDevice = api.CDIDevice
HugepageLimit = api.HugepageLimit
Hooks = api.Hooks
Expand Down Expand Up @@ -156,14 +157,15 @@ type (

// Aliased functions for api/optional.go.
var (
String = api.String
Int = api.Int
Int32 = api.Int32
UInt32 = api.UInt32
Int64 = api.Int64
UInt64 = api.UInt64
Bool = api.Bool
FileMode = api.FileMode
String = api.String
RepeatedString = api.RepeatedString
Int = api.Int
Int32 = api.Int32
UInt32 = api.UInt32
Int64 = api.Int64
UInt64 = api.UInt64
Bool = api.Bool
FileMode = api.FileMode
)

// Aliased functions for api/types.go.
Expand Down
66 changes: 66 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustLinuxScheduler(rpl.Linux.Scheduler, plugin); err != nil {
return err
}
if err := r.adjustRdt(rpl.Linux.Rdt, plugin); err != nil {
return err
}
}

if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
}
Expand Down Expand Up @@ -499,6 +503,48 @@ func (r *result) adjustSysctl(sysctl map[string]string, plugin string) error {
return nil
}

func (r *result) adjustRdt(rdt *LinuxRdt, plugin string) error {
if r == nil {
return nil
}

r.initAdjustRdt()

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

if rdt.GetRemove() {
r.owners.ClearRdt(id, plugin)
r.reply.adjust.Linux.Rdt = &LinuxRdt{
// Propagate the remove request (if not overridden below).
Remove: true,
}
}

if v := rdt.GetClosId(); v != nil {
if err := r.owners.ClaimRdtClosID(id, plugin); err != nil {
return err
}
r.reply.adjust.Linux.Rdt.ClosId = String(v.GetValue())
r.reply.adjust.Linux.Rdt.Remove = false
}
if v := rdt.GetSchemata(); v != nil {
if err := r.owners.ClaimRdtSchemata(id, plugin); err != nil {
return err
}
r.reply.adjust.Linux.Rdt.Schemata = RepeatedString(v.GetValue())
r.reply.adjust.Linux.Rdt.Remove = false
}
if v := rdt.GetEnableMonitoring(); v != nil {
if err := r.owners.ClaimRdtEnableMonitoring(id, plugin); err != nil {
return err
}
r.reply.adjust.Linux.Rdt.EnableMonitoring = Bool(v.GetValue())
r.reply.adjust.Linux.Rdt.Remove = false
}

return nil
}

func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error {
if len(devices) == 0 {
return nil
Expand Down Expand Up @@ -1131,3 +1177,23 @@ func (r *result) getContainerUpdate(u *ContainerUpdate, plugin string) (*Contain

return update, nil
}

func (r *result) initAdjust() {
if r.reply.adjust == nil {
r.reply.adjust = &ContainerAdjustment{}
}
}

func (r *result) initAdjustLinux() {
r.initAdjust()
if r.reply.adjust.Linux == nil {
r.reply.adjust.Linux = &LinuxContainerAdjustment{}
}
}

func (r *result) initAdjustRdt() {
r.initAdjustLinux()
if r.reply.adjust.Linux.Rdt == nil {
r.reply.adjust.Linux.Rdt = &LinuxRdt{}
}
}
31 changes: 31 additions & 0 deletions pkg/api/adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ func (a *ContainerAdjustment) SetLinuxRDTClass(value string) {
a.Linux.Resources.RdtClass = String(value)
}

// SetLinuxRDTClosID records setting the RDT CLOS id for a container.
func (a *ContainerAdjustment) SetLinuxRDTClosID(value string) {
a.initLinuxRdt()
a.Linux.Rdt.ClosId = String(value)
}

// SetLinuxRDTSchemata records setting the RDT schemata for a container.
func (a *ContainerAdjustment) SetLinuxRDTSchemata(value []string) {
a.initLinuxRdt()
a.Linux.Rdt.Schemata = RepeatedString(value)
}

// SetLinuxRDTEnableMonitoring records enabling RDT monitoring for a container.
func (a *ContainerAdjustment) SetLinuxRDTEnableMonitoring(value bool) {
a.initLinuxRdt()
a.Linux.Rdt.EnableMonitoring = Bool(value)
}

// RemoveLinuxRDT records the removal of the RDT configuration.
func (a *ContainerAdjustment) RemoveLinuxRDT() {
a.initLinuxRdt()
a.Linux.Rdt.Remove = true
}

// AddLinuxUnified sets a cgroupv2 unified resource.
func (a *ContainerAdjustment) AddLinuxUnified(key, value string) {
a.initLinuxResourcesUnified()
Expand Down Expand Up @@ -419,3 +443,10 @@ func (a *ContainerAdjustment) initLinuxNetDevices() {
a.Linux.NetDevices = make(map[string]*LinuxNetDevice)
}
}

func (a *ContainerAdjustment) initLinuxRdt() {
a.initLinux()
if a.Linux.Rdt == nil {
a.Linux.Rdt = &LinuxRdt{}
}
}
Loading
Loading