forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hooks: Add pre-create hooks for runtime-config manipulation
There's been a lot of discussion over in [1] about how to support the NVIDIA folks and others who want to be able to create devices (possibly after having loaded kernel modules) and bind userspace libraries into the container. Currently that's happening in the middle of runc's create-time mount handling before the container pivots to its new root directory with runc's incorrectly-timed prestart hook trigger [2]. With this commit, we extend hooks with a 'precreate' stage to allow trusted parties to manipulate the config JSON before calling the runtime's 'create'. I'm recycling the existing Hook schema from pkg/hooks for this, because we'll want Timeout for reliability and When to avoid the expense of fork/exec when a given hook does not need to make config changes [3]. [1]: opencontainers/runc#1811 [2]: opencontainers/runc#1710 [3]: containers#1828 (comment) Signed-off-by: W. Trevor King <[email protected]>
- Loading branch information
Showing
6 changed files
with
337 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package exec | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"time" | ||
|
||
spec "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// RuntimeConfigFilter calls a series of hooks. But instead of | ||
// passing container state on their standard input, | ||
// RuntimeConfigFilter passes the proposed runtime configuration (and | ||
// reads back a possibly-altered form from their standard output). | ||
func RuntimeConfigFilter(ctx context.Context, hooks []spec.Hook, config *spec.Spec, postKillTimeout time.Duration) (hookErr, err error) { | ||
data, err := json.Marshal(config) | ||
for _, hook := range hooks { | ||
var stdout bytes.Buffer | ||
hookErr, err = Run(ctx, &hook, data, &stdout, nil, postKillTimeout) | ||
if err != nil { | ||
return hookErr, err | ||
} | ||
|
||
data = stdout.Bytes() | ||
} | ||
err = json.Unmarshal(data, config) | ||
if err != nil { | ||
logrus.Debugf("invalid JSON from config-filter hooks:\n%s", string(data)) | ||
return nil, errors.Wrap(err, "unmarshal output from config-filter hooks") | ||
} | ||
|
||
return nil, nil | ||
} |
Oops, something went wrong.