Skip to content

Commit 9668cab

Browse files
authored
Merge pull request #323 from kate-goldenring/component-filtering
feat: support only running a subset of components of a Spin app
2 parents c1b079c + 43dbb39 commit 9668cab

File tree

12 files changed

+99
-3
lines changed

12 files changed

+99
-3
lines changed

.github/workflows/sample-apps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
app: [cpu-load-gen, hello-world, outbound-http, variabletester, redis-sample]
17+
app: [cpu-load-gen, hello-world, outbound-http, variabletester, redis-sample, salutations]
1818
env:
1919
IMAGE_NAME: ${{ github.repository }}
2020

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Create a k3d cluster:
5656

5757
```shell
5858
k3d cluster create wasm-cluster \
59-
--image ghcr.io/spinkube/containerd-shim-spin/k3d:v0.15.1 \
59+
--image ghcr.io/spinkube/containerd-shim-spin/k3d:v0.16.0 \
6060
-p "8081:80@loadbalancer" \
6161
--agents 2
6262
```

api/v1alpha1/spinapp_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ type SpinAppSpec struct {
8080

8181
// Resources defines the resource requirements for this app.
8282
Resources Resources `json:"resources,omitempty"`
83+
84+
// Components of the app to execute.
85+
//
86+
// If this is not provided all components are executed.
87+
// +kubebuilder:validation:MinItems:=1
88+
Components []string `json:"components,omitempty"`
8389
}
8490

8591
// SpinAppStatus defines the observed state of SpinApp

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/salutations/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main.wasm
2+
.spin/

apps/salutations/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/salutations
2+
3+
go 1.20
4+
5+
require github.com/fermyon/spin/sdk/go/v2 v2.2.0
6+
7+
require github.com/julienschmidt/httprouter v1.3.0 // indirect

apps/salutations/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/fermyon/spin/sdk/go/v2 v2.2.0 h1:zHZdIqjbUwyxiwdygHItnM+vUUNSZ3CX43jbIUemBI4=
2+
github.com/fermyon/spin/sdk/go/v2 v2.2.0/go.mod h1:kfJ+gdf/xIaKrsC6JHCUDYMv2Bzib1ohFIYUzvP+SCw=
3+
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
4+
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=

apps/salutations/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
spinhttp "github.com/fermyon/spin/sdk/go/v2/http"
8+
)
9+
10+
func init() {
11+
spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) {
12+
w.Header().Set("Content-Type", "text/plain")
13+
fmt.Fprintln(w, "Goodbye!")
14+
})
15+
}
16+
17+
func main() {}

apps/salutations/spin.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "salutations"
5+
version = "0.1.0"
6+
authors = ["Kate Goldenring <[email protected]>"]
7+
description = "An app that gives salutations"
8+
9+
[[trigger.http]]
10+
route = "/hi"
11+
component = "hello"
12+
13+
[component.hello]
14+
source = "../hello-world/main.wasm"
15+
allowed_outbound_hosts = []
16+
[component.hello.build]
17+
command = "pushd ../hello-world && tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go && popd"
18+
watch = ["**/*.go", "go.mod"]
19+
20+
[[trigger.http]]
21+
route = "/bye"
22+
component = "goodbye"
23+
24+
[component.goodbye]
25+
source = "main.wasm"
26+
allowed_outbound_hosts = []
27+
[component.goodbye.build]
28+
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
29+
watch = ["**/*.go", "go.mod"]

config/crd/bases/core.spinoperator.dev_spinapps.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ spec:
188188
type: integer
189189
type: object
190190
type: object
191+
components:
192+
description: Components to be executed in this group.
193+
items:
194+
type: string
195+
minItems: 1
196+
type: array
191197
deploymentAnnotations:
192198
additionalProperties:
193199
type: string

0 commit comments

Comments
 (0)