Skip to content

Commit

Permalink
runtime-tools/generate: adjust LinuxNamespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
  • Loading branch information
champtar committed Jan 23, 2025
1 parent 8717f58 commit 29bb2a8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/runtime-tools/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func (g *Generator) Adjust(adjust *nri.ContainerAdjustment) error {
g.AdjustDevices(adjust.GetLinux().GetDevices())
g.AdjustCgroupsPath(adjust.GetLinux().GetCgroupsPath())
g.AdjustOomScoreAdj(adjust.GetLinux().GetOomScoreAdj())
if err := g.AdjustNamespaces(adjust.GetLinux().GetNamespaces()); err != nil {
return err
}

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

// AdjustNamespaces adds or replaces namespaces in the OCI Spec.
func (g *Generator) AdjustNamespaces(namespaces []*nri.LinuxNamespace) error {
for _, n := range namespaces {
if n == nil {
continue
}
if key, marked := n.IsMarkedForRemoval(); marked {
if err := g.RemoveLinuxNamespace(key); err != nil {
return err
}
} else {
if err := g.AddOrReplaceLinuxNamespace(n.Type, n.Path); err != nil {
return err
}
}
}
return nil
}

// AdjustDevices adjusts the (Linux) devices in the OCI Spec.
func (g *Generator) AdjustDevices(devices []*nri.LinuxDevice) {
for _, d := range devices {
Expand Down

0 comments on commit 29bb2a8

Please sign in to comment.