containerd / nri

Node Resource Interface
Apache License 2.0
220 stars 58 forks source link

stale "prestart" branch in repository #56

Open thaJeztah opened 9 months ago

thaJeztah commented 9 months ago

I just noticed there's a stale prestart branch in this repository; AFAICS, it contains a single commit that's not in main (https://github.com/containerd/nri/compare/main...prestart (patch below)) created by @crosbymichael

Do we know

@crosbymichael (👋 👋 ) perhaps you recall?

https://github.com/containerd/nri/commit/197b471dec087c78c80300bc51c64ad06a88c018

From 197b471dec087c78c80300bc51c64ad06a88c018 Mon Sep 17 00:00:00 2001
From: Michael Crosby <michael@thepasture.io>
Date: Wed, 2 Sep 2020 04:32:00 -0400
Subject: [PATCH] Add precreate state and invoke func

Signed-off-by: Michael Crosby <michael@thepasture.io>
---
 client.go         | 35 +++++++++++++++++++++++++++++++++++
 types/v1/types.go |  3 +++
 2 files changed, 38 insertions(+)

diff --git a/client.go b/client.go
index 6b6c6e40..8c54064f 100644
--- a/client.go
+++ b/client.go
@@ -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)
diff --git a/types/v1/types.go b/types/v1/types.go
index e0703f5a..3dbbd16d 100644
--- a/types/v1/types.go
+++ b/types/v1/types.go
@@ -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