Skip to content

Commit 808dd0b

Browse files
committed
runtime-tools/generate: adjust LinuxNamespaces
Signed-off-by: Etienne Champetier <[email protected]>
1 parent b3763c4 commit 808dd0b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/runtime-tools/generate/generate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func (g *Generator) Adjust(adjust *nri.ContainerAdjustment) error {
117117
g.AdjustDevices(adjust.GetLinux().GetDevices())
118118
g.AdjustCgroupsPath(adjust.GetLinux().GetCgroupsPath())
119119
g.AdjustOomScoreAdj(adjust.GetLinux().GetOomScoreAdj())
120+
if err := g.AdjustNamespaces(adjust.GetLinux().GetNamespaces()); err != nil {
121+
return err
122+
}
120123

121124
resources := adjust.GetLinux().GetResources()
122125
if err := g.AdjustResources(resources); err != nil {
@@ -332,6 +335,25 @@ func (g *Generator) AdjustOomScoreAdj(score *nri.OptionalInt) {
332335
}
333336
}
334337

338+
// AdjustNamespaces adds or replaces namespaces in the OCI Spec.
339+
func (g *Generator) AdjustNamespaces(namespaces []*nri.LinuxNamespace) error {
340+
for _, n := range namespaces {
341+
if n == nil {
342+
continue
343+
}
344+
if key, marked := n.IsMarkedForRemoval(); marked {
345+
if err := g.RemoveLinuxNamespace(key); err != nil {
346+
return err
347+
}
348+
} else {
349+
if err := g.AddOrReplaceLinuxNamespace(n.Type, n.Path); err != nil {
350+
return err
351+
}
352+
}
353+
}
354+
return nil
355+
}
356+
335357
// AdjustDevices adjusts the (Linux) devices in the OCI Spec.
336358
func (g *Generator) AdjustDevices(devices []*nri.LinuxDevice) {
337359
for _, d := range devices {

0 commit comments

Comments
 (0)