Skip to content

Commit

Permalink
add wasm runtimes (embedded and nodejs) in kpt (kptdev#3450)
Browse files Browse the repository at this point in the history
* add wasm runtime in kpt

* add testcase for wasm eval
  • Loading branch information
Mengqi Yu authored and chunglu-chou committed Aug 20, 2022
1 parent 2de7d76 commit 69cfd59
Show file tree
Hide file tree
Showing 41 changed files with 2,009 additions and 102 deletions.
46 changes: 44 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ on:
- "**.md"
push:

env:
GOPATH: ${{ github.workspace }}/go

jobs:
build:
build-test-linux:
name: Build-test-kpt-CLI
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
runtime: [docker, podman]
steps:
Expand All @@ -47,12 +51,50 @@ jobs:
go-version: 1.18
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v3
with:
path: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
- name: Build, Test, Lint
working-directory: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
run: |
git config --global user.email you@example.com
git config --global user.name Your Name
make all
make test-docker
env:
KPT_FN_RUNTIME: ${{ matrix.runtime }}

build-macos:
runs-on: macos-latest
steps:
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.18
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
path: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
- name: Build
working-directory: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
run: |
make build
# TODO: fix https://github.com/GoogleContainerTools/kpt/issues/3463
# build-windows:
# runs-on: windows-2019
# steps:
# - name: Set up Go 1.18
# uses: actions/setup-go@v1
# with:
# go-version: 1.18
# id: go
# - name: Check out code into the Go module directory
# uses: actions/checkout@v3
# with:
# path: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
# - name: Build
# working-directory: ${{ env.GOPATH }}/src/github.com/GoogleContainerTools/kpt
# run: |
# make build
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ GIT_COMMIT := $(shell git rev-parse --short HEAD)
# By default, make test-fn-render/test-fn-eval will run all tests.
T ?= ".*"

all: generate license fix vet fmt lint license-check test build buildall tidy
all: generate license fix vet fmt lint license-check test build tidy

build:
go build -ldflags "-X github.com/GoogleContainerTools/kpt/run.version=${GIT_COMMIT}" -o $(GOBIN)/kpt -v .

buildall:
GOOS=windows go build -o /dev/null
GOOS=linux go build -o /dev/null
GOOS=darwin go build -o /dev/null

update-deps-to-head:
go get sigs.k8s.io/cli-utils@master
go get sigs.k8s.io/kustomize/kyaml@master
Expand Down
1 change: 1 addition & 0 deletions commands/alphacmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GetAlphaCommand(ctx context.Context, name, version string) *cobra.Command {
NewRepoCommand(ctx, version),
NewRpkgCommand(ctx, version),
NewSyncCommand(ctx, version),
NewWasmCommand(ctx, version),
GetAlphaLiveCommand(ctx, "", version),
)

Expand Down
39 changes: 39 additions & 0 deletions commands/wasmcmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"context"

"github.com/GoogleContainerTools/kpt/internal/cmdwasmpull"
"github.com/GoogleContainerTools/kpt/internal/cmdwasmpush"
"github.com/GoogleContainerTools/kpt/internal/docs/generated/wasmdocs"
"github.com/spf13/cobra"
)

func NewWasmCommand(ctx context.Context, version string) *cobra.Command {
wasmcmd := &cobra.Command{
Use: "wasm",
Short: "[Alpha] " + wasmdocs.WasmShort,
Long: "[Alpha] " + wasmdocs.WasmLong,
}

wasmcmd.AddCommand(
cmdwasmpull.NewCommand(ctx),
cmdwasmpush.NewCommand(ctx),
)

return wasmcmd
}
19 changes: 19 additions & 0 deletions e2e/testdata/fn-eval/wasm-function/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

testType: eval
image: gcr.io/kpt-fn-demo/set-namespace:v0.5.0
args:
namespace: staging
allowWasm: true
11 changes: 11 additions & 0 deletions e2e/testdata/fn-eval/wasm-function/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/resources.yaml b/resources.yaml
index e8efba7..2ac7759 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -15,5 +15,6 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
+ namespace: staging
spec:
replicas: 3
1 change: 1 addition & 0 deletions e2e/testdata/fn-eval/wasm-function/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
19 changes: 19 additions & 0 deletions e2e/testdata/fn-eval/wasm-function/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
16 changes: 16 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sequential: true
allowWasm: true
29 changes: 29 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/resources.yaml b/resources.yaml
index ac634f3..ef2a1b1 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -15,12 +15,24 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
+ namespace: staging
+ labels:
+ tier: backend
spec:
replicas: 3
+ selector:
+ matchLabels:
+ tier: backend
+ template:
+ metadata:
+ labels:
+ tier: backend
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
+ labels:
+ tier: backend
spec:
image: nginx:1.2.3
16 changes: 16 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/.expected/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

export KPT_FN_WASM_RUNTIME=wasmtime
16 changes: 16 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/.expected/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env bash
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

unset KPT_FN_WASM_RUNTIME
1 change: 1 addition & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/.krmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
14 changes: 14 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: app
labels:
tier: backend
pipeline:
mutators:
- image: gcr.io/kpt-fn-demo/set-namespace:v0.5.0 # TODO: switch to use the kpt-fn GCR when it is built there.
configMap:
namespace: staging
- image: gcr.io/kpt-fn-demo/set-labels:v0.2.0 # TODO: switch to use the kpt-fn GCR when it is built there.
configMap:
tier: backend
26 changes: 26 additions & 0 deletions e2e/testdata/fn-render/basicpipeline-wasm/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
spec:
image: nginx:1.2.3
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/GoogleContainerTools/kpt/porch/api v0.0.0-20220707151439-cb4c4e496c92
github.com/bytecodealliance/wasmtime-go v0.39.0
github.com/cpuguy83/go-md2man/v2 v2.0.2
github.com/go-errors/errors v1.4.2
github.com/google/go-cmp v0.5.8
Expand All @@ -12,6 +13,7 @@ require (
github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac
github.com/otiai10/copy v1.7.0
github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f
github.com/prep/wasmexec v0.0.0-20220807105708-6554945c1dec
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.7.1
github.com/xlab/treeprint v1.1.0
Expand All @@ -28,7 +30,7 @@ require (
k8s.io/klog/v2 v2.60.1
k8s.io/kubectl v0.24.0
sigs.k8s.io/cli-utils v0.32.1-0.20220804181346-99ba319afc0b
sigs.k8s.io/controller-runtime v0.11.0
sigs.k8s.io/controller-runtime v0.11.1
sigs.k8s.io/kustomize/api v0.12.1
sigs.k8s.io/kustomize/kyaml v0.13.9
)
Expand All @@ -43,8 +45,6 @@ require (
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.12.0 // indirect
Expand All @@ -59,14 +59,14 @@ require (
github.com/fatih/camelcase v1.0.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fvbommel/sortorder v1.0.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
Expand Down Expand Up @@ -101,7 +101,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spyzhov/ajson v0.4.2 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.starlark.net v0.0.0-20210901212718-87f333178d59 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
Expand All @@ -113,7 +113,7 @@ require (
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20220401212409-b28bf2818661 // indirect
k8s.io/kube-openapi v0.0.0-20220413171646-5e7f5fdc6da6 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
Expand Down
Loading

0 comments on commit 69cfd59

Please sign in to comment.