Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[codespell]
skip = .git,*.pdf,*.svg,go.sum,go.mod
skip = .git,*.pdf,*.svg,go.sum,go.mod,*.pb.go
ignore-words-list = clos
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ jobs:
with:
go-version: 1.21.x

# needed for wasm plugins
- uses: acifani/setup-tinygo@v2
with:
tinygo-version: "0.34.0"

- name: Set env
shell: bash
run: |
Expand All @@ -53,7 +58,7 @@ jobs:
- name: Install protoc and plugins
run: |
sudo make install-protoc
make install-protoc-dependencies install-ttrpc-plugin
make install-protoc-dependencies install-ttrpc-plugin install-wasm-plugin

- name: Force regeneration of protobuf files on build
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.21.x

- uses: acifani/setup-tinygo@v2
with:
tinygo-version: "0.34.0"

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
31 changes: 29 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ PROTO_GOFILES = $(patsubst %.proto,%.pb.go,$(PROTO_SOURCES))
PROTO_INCLUDE = -I$(PWD):/usr/local/include:/usr/include
PROTO_OPTIONS = --proto_path=. $(PROTO_INCLUDE) \
--go_opt=paths=source_relative --go_out=. \
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=.
--go-ttrpc_opt=paths=source_relative --go-ttrpc_out=. \
--go-plugin_opt=paths=source_relative,disable_pb_gen=true --go-plugin_out=.
PROTO_COMPILE = PATH=$(PATH):$(shell go env GOPATH)/bin; protoc $(PROTO_OPTIONS)

GO_CMD := go
Expand All @@ -33,6 +34,15 @@ GO_MODULES := $(shell $(GO_CMD) list ./...)
GOLANG_CILINT := golangci-lint
GINKGO := ginkgo

TINYGO_CMD := tinygo
TINYGO_BUILD := $(TINYGO_CMD) build -scheduler=none -target=wasi -no-debug
TINYGO_DOCKER ?= 0
# Keep the tinygo version in sync with .github/workflows/ci.yml
tinygo-docker-build = \
echo "Docker-tinygo-building $(1)..."; \
docker run --rm -v $(PWD):$(PWD) tinygo/tinygo:0.34.0 \
/bin/bash -c "cd $(PWD); make TINYGO_DOCKER=0 $(1)"

BUILD_PATH := $(shell pwd)/build
BIN_PATH := $(BUILD_PATH)/bin
COVERAGE_PATH := $(BUILD_PATH)/coverage
Expand All @@ -44,7 +54,8 @@ PLUGINS := \
$(BIN_PATH)/differ \
$(BIN_PATH)/ulimit-adjuster \
$(BIN_PATH)/v010-adapter \
$(BIN_PATH)/template
$(BIN_PATH)/template \
$(BIN_PATH)/wasm


ifneq ($(V),1)
Expand Down Expand Up @@ -118,6 +129,18 @@ $(BIN_PATH)/template: $(wildcard plugins/template/*.go)
$(Q)echo "Building $@..."; \
cd $(dir $<) && $(GO_BUILD) -o $@ .

ifneq ($(TINYGO_DOCKER),1)
$(BIN_PATH)/wasm: $(wildcard plugins/wasm/*.go)
$(Q)echo "Building $@..."; \
mkdir -p $(BIN_PATH) && \
cd $(dir $<) && $(TINYGO_BUILD) -o $@ .
else
$(BIN_PATH)/wasm: $(wildcard plugins/wasm/*.go)
$(Q)echo "Building $@..."; \
mkdir -p $(BIN_PATH) && \
$(call tinygo-docker-build,$@)
endif

#
# test targets
#
Expand Down Expand Up @@ -180,6 +203,7 @@ validate-repo-no-changes:
%.pb.go: %.proto
$(Q)echo "Generating $@..."; \
$(PROTO_COMPILE) $<
sed -i '1s;^;//go:build !tinygo.wasm\n\n;' pkg/api/api_ttrpc.pb.go

#
# targets for installing dependencies
Expand All @@ -191,6 +215,9 @@ install-protoc install-protobuf:
install-ttrpc-plugin:
$(Q)$(GO_INSTALL) -mod=mod github.com/containerd/ttrpc/cmd/protoc-gen-go-ttrpc@74421d10189e8c118870d294c9f7f62db2d33ec1

install-wasm-plugin:
$(Q)$(GO_INSTALL) -mod=mod github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin@d8d42059d8f1b52968cff7226b7094e5c6a0c342

install-protoc-dependencies:
$(Q)$(GO_INSTALL) -mod=mod google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.0

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ go 1.21

require (
github.com/containerd/ttrpc v1.2.6-0.20240827082320-b5cd6e4b3287
github.com/knqyf263/go-plugin v0.8.1-0.20240827022226-114c6257e441
github.com/moby/sys/mountinfo v0.6.2
github.com/onsi/ginkgo/v2 v2.19.1
github.com/onsi/gomega v1.34.0
github.com/opencontainers/runtime-spec v1.0.3-0.20220825212826-86290f6a00fb
github.com/opencontainers/runtime-tools v0.9.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/tetratelabs/wazero v1.8.2-0.20241030035603-dc08732e57d5
golang.org/x/sys v0.21.0
google.golang.org/grpc v1.57.1
google.golang.org/protobuf v1.34.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/knqyf263/go-plugin v0.8.1-0.20240827022226-114c6257e441 h1:Q/sZeuWkXprbKJSs7AwXryuZKSEL/a8ltC7e7xSspN0=
github.com/knqyf263/go-plugin v0.8.1-0.20240827022226-114c6257e441/go.mod h1:CvCrNDMiKFlAlLFLmcoEfsTROEfNKbEZAMMrwQnLXCM=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mndrix/tap-go v0.0.0-20171203230836-629fa407e90b/go.mod h1:pzzDgJWZ34fGzaAZGFW22KVZDfyrYW+QABMrWnJBnSs=
Expand Down Expand Up @@ -61,6 +63,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tetratelabs/wazero v1.8.2-0.20241030035603-dc08732e57d5 h1:F+AT6Jxxww3j4/B/wXU01Raq4J8fg/Cg2HD4XsETGaU=
github.com/tetratelabs/wazero v1.8.2-0.20241030035603-dc08732e57d5/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
49 changes: 28 additions & 21 deletions pkg/adaptation/adaptation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ type UpdateFn func(context.Context, []*ContainerUpdate) ([]*ContainerUpdate, err
// Adaptation is the NRI abstraction for container runtime NRI adaptation/integration.
type Adaptation struct {
sync.Mutex
name string
version string
dropinPath string
pluginPath string
socketPath string
dontListen bool
syncFn SyncFn
updateFn UpdateFn
clientOpts []ttrpc.ClientOpts
serverOpts []ttrpc.ServerOpt
listener net.Listener
plugins []*plugin
syncLock sync.RWMutex
name string
version string
dropinPath string
pluginPath string
socketPath string
dontListen bool
syncFn SyncFn
updateFn UpdateFn
clientOpts []ttrpc.ClientOpts
serverOpts []ttrpc.ServerOpt
listener net.Listener
plugins []*plugin
syncLock sync.RWMutex
wasmService *api.PluginPlugin
}

var (
Expand Down Expand Up @@ -128,15 +129,21 @@ func New(name, version string, syncFn SyncFn, updateFn UpdateFn, opts ...Option)
return nil, fmt.Errorf("failed to create NRI adaptation, nil UpdateFn")
}

wasmPlugins, err := api.NewPluginPlugin(context.Background())
if err != nil {
return nil, fmt.Errorf("unable to initialize WASM service: %w", err)
}

r := &Adaptation{
name: name,
version: version,
syncFn: syncFn,
updateFn: updateFn,
pluginPath: DefaultPluginPath,
dropinPath: DefaultPluginConfigPath,
socketPath: DefaultSocketPath,
syncLock: sync.RWMutex{},
name: name,
version: version,
syncFn: syncFn,
updateFn: updateFn,
pluginPath: DefaultPluginPath,
dropinPath: DefaultPluginConfigPath,
socketPath: DefaultSocketPath,
syncLock: sync.RWMutex{},
wasmService: wasmPlugins,
}

for _, o := range opts {
Expand Down
Loading
Loading