@@ -32,8 +32,6 @@ import (
3232 "github.com/containerd/nri/pkg/log"
3333 validator "github.com/containerd/nri/plugins/default-validator/builtin"
3434 "github.com/containerd/ttrpc"
35- "github.com/tetratelabs/wazero"
36- "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
3735
3836 "google.golang.org/protobuf/proto"
3937)
@@ -80,6 +78,9 @@ type Adaptation struct {
8078var (
8179 // Used instead of nil Context in logging.
8280 noCtx = context .TODO ()
81+
82+ // ErrWasmDisabled is returned for WASM initialization if WASM support is disabled.
83+ ErrWasmDisabled = errors .New ("WASM support is disabled (at build time)" )
8384)
8485
8586// Option to apply to the NRI runtime.
@@ -155,23 +156,12 @@ func New(name, version string, syncFn SyncFn, updateFn UpdateFn, opts ...Option)
155156 return nil , fmt .Errorf ("failed to create NRI adaptation, nil UpdateFn" )
156157 }
157158
158- wasmWithCloseOnContextDone := func (ctx context.Context ) (wazero.Runtime , error ) {
159- var (
160- cfg = wazero .NewRuntimeConfig ().WithCloseOnContextDone (true )
161- r = wazero .NewRuntimeWithConfig (ctx , cfg )
162- )
163- if _ , err := wasi_snapshot_preview1 .Instantiate (ctx , r ); err != nil {
159+ wasmService , err := getWasmService ()
160+ if err != nil {
161+ log .Errorf (noCtx , "failed to initialize WASM support: %v" , err )
162+ if ! errors .Is (err , ErrWasmDisabled ) {
164163 return nil , err
165164 }
166- return r , nil
167- }
168-
169- wasmPlugins , err := api .NewPluginPlugin (
170- context .Background (),
171- api .WazeroRuntime (wasmWithCloseOnContextDone ),
172- )
173- if err != nil {
174- return nil , fmt .Errorf ("unable to initialize WASM service: %w" , err )
175165 }
176166
177167 r := & Adaptation {
@@ -183,7 +173,7 @@ func New(name, version string, syncFn SyncFn, updateFn UpdateFn, opts ...Option)
183173 dropinPath : DefaultPluginConfigPath ,
184174 socketPath : DefaultSocketPath ,
185175 syncLock : sync.RWMutex {},
186- wasmService : wasmPlugins ,
176+ wasmService : wasmService ,
187177 }
188178
189179 for _ , o := range opts {
0 commit comments