Skip to content

Commit

Permalink
api: add namespace adjustment
Browse files Browse the repository at this point in the history
We are interested in running some parts of a pod in host or totally
separate pid and network namespaces, so add an adjustment that allows for
that.

Signed-off-by: Tycho Andersen <[email protected]>
  • Loading branch information
tych0 committed Nov 25, 2024
1 parent 6d486ac commit 698e6ae
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 156 deletions.
32 changes: 32 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
return err
}
if err := r.adjustNamespaces(rpl.Linux.Namespaces, plugin); err != nil {
return err
}
}
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
Expand Down Expand Up @@ -738,6 +741,22 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
return nil
}

func (r *result) adjustNamespaces(adjustment []*LinuxNamespace, plugin string) error {
if adjustment == nil {
return nil
}
create, id := r.request.create, r.request.create.Container.Id

if err := r.owners.claimNamespaces(id, plugin); err != nil {
return err
}

create.Container.Linux.Namespaces = adjustment
r.reply.adjust.Linux.Namespaces = adjustment

return nil
}

func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
for _, l := range rlimits {
Expand Down Expand Up @@ -976,6 +995,7 @@ type owners struct {
unified map[string]string
cgroupsPath string
oomScoreAdj string
namespaces string
rlimits map[string]string
}

Expand Down Expand Up @@ -1096,6 +1116,10 @@ func (ro resultOwners) claimOomScoreAdj(id, plugin string) error {
return ro.ownersFor(id).claimOomScoreAdj(plugin)
}

func (ro resultOwners) claimNamespaces(id, plugin string) error {
return ro.ownersFor(id).claimNamespaces(plugin)
}

func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
return ro.ownersFor(id).claimRlimit(typ, plugin)
}
Expand Down Expand Up @@ -1349,6 +1373,14 @@ func (o *owners) claimOomScoreAdj(plugin string) error {
return nil
}

func (o *owners) claimNamespaces(plugin string) error {
if other := o.namespaces; other != "" {
return conflict(plugin, other, "namespaces")
}
o.namespaces = plugin
return nil
}

func (ro resultOwners) clearAnnotation(id, key string) {
ro.ownersFor(id).clearAnnotation(key)
}
Expand Down
Loading

0 comments on commit 698e6ae

Please sign in to comment.