Skip to content

Commit e5b126b

Browse files
samuelkarpchrishenzie
authored andcommitted
legacy: deprecate old NRI types
This commit adds deprecation comments to old types and adds a new method that the runtime can use to retrieve configured plugins, so a deprecation warning can be produced at runtime. Signed-off-by: Samuel Karp <samuelkarp@google.com> Signed-off-by: Chris Henzie <chrishenzie@google.com>
1 parent 559caa2 commit e5b126b

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

client.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const (
4242
var appendPathOnce sync.Once
4343

4444
// New nri client
45+
//
46+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
4547
func New() (*Client, error) {
4648
conf, err := loadConfig(DefaultConfPath)
4749
if err != nil {
@@ -60,12 +62,28 @@ func New() (*Client, error) {
6062
}, nil
6163
}
6264

65+
// Plugins returns a slice of the configured plugin names. This can be used by
66+
// the runtime to detect which plugins are configured.
67+
//
68+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
69+
func (c *Client) Plugins() []string {
70+
names := make([]string, 0)
71+
for _, p := range c.conf.Plugins {
72+
names = append(names, p.Type)
73+
}
74+
return names
75+
}
76+
6377
// Client for calling nri plugins
78+
//
79+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
6480
type Client struct {
6581
conf *types.ConfigList
6682
}
6783

6884
// Sandbox information
85+
//
86+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
6987
type Sandbox struct {
7088
// ID of the sandbox
7189
ID string
@@ -82,6 +100,8 @@ type process interface {
82100
}
83101

84102
// Task is a subset of containerd's Task interface.
103+
//
104+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
85105
type Task interface {
86106
process
87107

@@ -90,11 +110,15 @@ type Task interface {
90110
}
91111

92112
// Invoke the ConfList of nri plugins
113+
//
114+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
93115
func (c *Client) Invoke(ctx context.Context, task Task, state types.State) ([]*types.Result, error) {
94116
return c.InvokeWithSandbox(ctx, task, state, nil)
95117
}
96118

97119
// InvokeWithSandbox invokes the ConfList of nri plugins
120+
//
121+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
98122
func (c *Client) InvokeWithSandbox(ctx context.Context, task Task, state types.State, sandbox *Sandbox) ([]*types.Result, error) {
99123
if len(c.conf.Plugins) == 0 {
100124
return nil, nil
@@ -129,7 +153,7 @@ func (c *Client) InvokeWithSandbox(ctx context.Context, task Task, state types.S
129153
return r.Results, nil
130154
}
131155

132-
func (c *Client) invokePlugin(ctx context.Context, name string, r *types.Request) (*types.Result, error) {
156+
func (c *Client) invokePlugin(ctx context.Context, name string, r *types.Request) (*types.Result, error) { //nolint:staticcheck
133157
payload, err := json.Marshal(r)
134158
if err != nil {
135159
return nil, err
@@ -154,28 +178,28 @@ func (c *Client) invokePlugin(ctx context.Context, name string, r *types.Request
154178
return nil, err
155179
}
156180
}
157-
var result types.Result
181+
var result types.Result //nolint:staticcheck
158182
if err := json.Unmarshal(out, &result); err != nil {
159183
return nil, fmt.Errorf("failed to unmarshal plugin output %s: %w", msg, err)
160184
}
161-
if result.Err() != nil {
162-
return nil, result.Err()
185+
if result.Err() != nil { //nolint:staticcheck
186+
return nil, result.Err() //nolint:staticcheck
163187
}
164188
return &result, nil
165189
}
166190

167-
func loadConfig(path string) (*types.ConfigList, error) {
191+
func loadConfig(path string) (*types.ConfigList, error) { //nolint:staticcheck
168192
f, err := os.Open(path)
169193
if err != nil {
170194
// if we don't have a config list on disk, create a new one for use
171195
if os.IsNotExist(err) {
172-
return &types.ConfigList{
196+
return &types.ConfigList{ //nolint:staticcheck
173197
Version: Version,
174198
}, nil
175199
}
176200
return nil, err
177201
}
178-
var c types.ConfigList
202+
var c types.ConfigList //nolint:staticcheck
179203
err = json.NewDecoder(f).Decode(&c)
180204
f.Close()
181205
if err != nil {
@@ -184,8 +208,8 @@ func loadConfig(path string) (*types.ConfigList, error) {
184208
return &c, nil
185209
}
186210

187-
func createSpec(spec *oci.Spec) (*types.Spec, error) {
188-
s := types.Spec{
211+
func createSpec(spec *oci.Spec) (*types.Spec, error) { //nolint:staticcheck
212+
s := types.Spec{ //nolint:staticcheck
189213
Namespaces: make(map[string]string),
190214
Annotations: spec.Annotations,
191215
}

skel/skel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ type Plugin interface {
3030
// Type or plugin name
3131
Type() string
3232
// Invoke the plugin
33-
Invoke(context.Context, *types.Request) (*types.Result, error)
33+
Invoke(context.Context, *types.Request) (*types.Result, error) //nolint:staticcheck
3434
}
3535

3636
// Run the plugin from a main() function
3737
func Run(ctx context.Context, plugin Plugin) error {
3838
enc := json.NewEncoder(os.Stdout)
39-
var request types.Request
39+
var request types.Request //nolint:staticcheck
4040
if err := json.NewDecoder(os.Stdin).Decode(&request); err != nil {
4141
return err
4242
}
@@ -45,14 +45,14 @@ func Run(ctx context.Context, plugin Plugin) error {
4545
result, err := plugin.Invoke(ctx, &request)
4646
if err != nil {
4747
// if the plugin sets ErrorMessage we ignore it
48-
result = request.NewResult(plugin.Type())
48+
result = request.NewResult(plugin.Type()) //nolint:staticcheck
4949
result.Error = err.Error()
5050
}
5151
if err := enc.Encode(result); err != nil {
5252
return fmt.Errorf("unable to encode plugin error to stdout: %w", err)
5353
}
5454
default:
55-
result := request.NewResult(plugin.Type())
55+
result := request.NewResult(plugin.Type()) //nolint:staticcheck
5656
result.Error = fmt.Sprintf("invalid arg %s", os.Args[1])
5757
if err := enc.Encode(result); err != nil {
5858
return fmt.Errorf("unable to encode invalid parameter error to stdout: %w", err)

types/v1/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
)
2323

2424
// Plugin type and configuration
25+
//
26+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
2527
type Plugin struct {
2628
// Type of plugin
2729
Type string `json:"type"`
@@ -32,6 +34,8 @@ type Plugin struct {
3234
// ConfigList for the global configuration of NRI
3335
//
3436
// Normally located at /etc/nri/conf.json
37+
//
38+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
3539
type ConfigList struct {
3640
// Version of the list
3741
Version string `json:"version"`
@@ -40,6 +44,8 @@ type ConfigList struct {
4044
}
4145

4246
// Spec for the container being processed
47+
//
48+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
4349
type Spec struct {
4450
// Resources struct from the OCI specification
4551
//
@@ -54,6 +60,8 @@ type Spec struct {
5460
}
5561

5662
// State of the request
63+
//
64+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
5765
type State string
5866

5967
const (
@@ -70,6 +78,8 @@ const (
7078
)
7179

7280
// Request for a plugin invocation
81+
//
82+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
7383
type Request struct {
7484
// Conf specific for the plugin
7585
Conf json.RawMessage `json:"conf,omitempty"`
@@ -98,11 +108,15 @@ type Request struct {
98108
}
99109

100110
// IsSandbox returns true if the request is for a sandbox
111+
//
112+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
101113
func (r *Request) IsSandbox() bool {
102114
return r.ID == r.SandboxID
103115
}
104116

105117
// NewResult returns a result from the original request
118+
//
119+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
106120
func (r *Request) NewResult(plugin string) *Result {
107121
return &Result{
108122
Plugin: plugin,
@@ -112,6 +126,8 @@ func (r *Request) NewResult(plugin string) *Result {
112126
}
113127

114128
// Result of the plugin invocation
129+
//
130+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
115131
type Result struct {
116132
// Plugin name that populated the result
117133
Plugin string `json:"plugin"`
@@ -124,6 +140,8 @@ type Result struct {
124140
}
125141

126142
// Err creates an Error object if ErrorMessage is populated
143+
//
144+
// Deprecated: NRI 0.1.0-style plugins should only be used through the v010-adapter plugin
127145
func (r *Result) Err() error {
128146
if r.Error != "" {
129147
return errors.New(r.Error)

0 commit comments

Comments
 (0)