Skip to content

Commit

Permalink
Add precreate state and invoke func
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crosby <michael@thepasture.io>
  • Loading branch information
crosbymichael committed Sep 2, 2020
1 parent 0afc7f0 commit 197b471
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ type Sandbox struct {
Labels map[string]string
}

// InvokePre the ConfList of nri plugins before a runtime object has been created.
func (c *Client) InvokePre(ctx context.Context, container containerd.Container, sandbox *Sandbox) ([]*types.Result, error) {
if len(c.conf.Plugins) == 0 {
return nil, nil
}
spec, err := container.Spec(ctx)
if err != nil {
return nil, err
}
rs, err := createSpec(spec)
if err != nil {
return nil, err
}
r := &types.Request{
Version: c.conf.Version,
ID: container.ID(),
Pid: -1,
State: types.PreCreate,
Spec: rs,
}
if sandbox != nil {
r.SandboxID = sandbox.ID
r.Labels = sandbox.Labels
}
for _, p := range c.conf.Plugins {
r.Conf = p.Conf
result, err := c.invokePlugin(ctx, p.Type, r)
if err != nil {
return nil, errors.Wrapf(err, "plugin: %s", p.Type)
}
r.Results = append(r.Results, result)
}
return r.Results, nil
}

// Invoke the ConfList of nri plugins
func (c *Client) Invoke(ctx context.Context, task containerd.Task, state types.State) ([]*types.Result, error) {
return c.InvokeWithSandbox(ctx, task, state, nil)
Expand Down
3 changes: 3 additions & 0 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Spec struct {
type State string

const (
// PreCreate happens before any runtime tasks are created
// from the calling runtime/process
PreCreate State = "pre-create"
// Create the initial resource for the container
Create State = "create"
// Delete any resources for the container
Expand Down

0 comments on commit 197b471

Please sign in to comment.