Skip to content

Commit 96f0f20

Browse files
authored
Merge pull request #248 from samuelkarp/sysctl
Add support for sysctl adjustment
2 parents fd33dea + 914fbf3 commit 96f0f20

File tree

10 files changed

+1094
-511
lines changed

10 files changed

+1094
-511
lines changed

pkg/adaptation/result.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
235235
if err := r.adjustNamespaces(rpl.Linux.Namespaces, plugin); err != nil {
236236
return err
237237
}
238+
if err := r.adjustSysctl(rpl.Linux.Sysctl, plugin); err != nil {
239+
return err
240+
}
238241
}
239242
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
240243
return err
@@ -451,6 +454,41 @@ func (r *result) adjustNamespaces(namespaces []*LinuxNamespace, plugin string) e
451454
return nil
452455
}
453456

457+
func (r *result) adjustSysctl(sysctl map[string]string, plugin string) error {
458+
if len(sysctl) == 0 {
459+
return nil
460+
}
461+
462+
create, id := r.request.create, r.request.create.Container.Id
463+
del := map[string]struct{}{}
464+
for k := range sysctl {
465+
if key, marked := IsMarkedForRemoval(k); marked {
466+
del[key] = struct{}{}
467+
delete(sysctl, k)
468+
}
469+
}
470+
471+
for k, v := range sysctl {
472+
if _, ok := del[k]; ok {
473+
r.owners.ClearSysctl(id, k, plugin)
474+
delete(create.Container.Linux.Sysctl, k)
475+
r.reply.adjust.Linux.Sysctl[MarkForRemoval(k)] = ""
476+
}
477+
if err := r.owners.ClaimSysctl(id, k, plugin); err != nil {
478+
return err
479+
}
480+
create.Container.Linux.Sysctl[k] = v
481+
r.reply.adjust.Linux.Sysctl[k] = v
482+
delete(del, k)
483+
}
484+
485+
for k := range del {
486+
r.reply.adjust.Annotations[MarkForRemoval(k)] = ""
487+
}
488+
489+
return nil
490+
}
491+
454492
func (r *result) adjustCDIDevices(devices []*CDIDevice, plugin string) error {
455493
if len(devices) == 0 {
456494
return nil

pkg/api/adjustment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ func (a *ContainerAdjustment) SetLinuxSeccompPolicy(seccomp *LinuxSeccomp) {
310310
a.Linux.SeccompPolicy = seccomp
311311
}
312312

313+
// SetLinuxSysctl records setting a sysctl for a container.
314+
func (a *ContainerAdjustment) SetLinuxSysctl(key, value string) {
315+
a.initLinux()
316+
if a.Linux.Sysctl == nil {
317+
a.Linux.Sysctl = make(map[string]string)
318+
}
319+
a.Linux.Sysctl[key] = value
320+
}
321+
313322
//
314323
// Initializing a container adjustment and container update.
315324
//

pkg/api/api.pb.go

Lines changed: 549 additions & 508 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/api.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ message LinuxContainer {
377377
LinuxIOPriority io_priority = 6;
378378
SecurityProfile seccomp_profile = 7;
379379
LinuxSeccomp seccomp_policy = 8;
380+
map<string, string> sysctl = 9;
380381
}
381382

382383
// A linux namespace.
@@ -516,6 +517,7 @@ message LinuxContainerAdjustment {
516517
LinuxIOPriority io_priority = 5;
517518
LinuxSeccomp seccomp_policy = 6;
518519
repeated LinuxNamespace namespaces = 7;
520+
map<string, string> sysctl = 8;
519521
}
520522

521523
message LinuxSeccomp {
@@ -673,4 +675,5 @@ enum Field {
673675
IoPriority = 31;
674676
SeccompPolicy = 32;
675677
Namespace = 33;
678+
Sysctl = 34;
676679
}

0 commit comments

Comments
 (0)