generated from knative-extensions/sample-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix runner crash: align WASI_CONFIG wire format with controller #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92eeb8f
Fix runner crash: align WASI_CONFIG wire format with controller
cardil 3b92276
Handle MarshalIndent errors in test
cardil 7a30e0e
Merge remote-tracking branch 'upstream/main' into bugfix/runner-env-c…
cardil 2858cf3
Export BuildRunnerConfig, fix test pkg & lint
cardil 1667d10
Use CARGO_MANIFEST_DIR for robust golden path
cardil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
pkg/reconciler/wasmmodule/testdata/wasi_config.golden.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "args": ["--verbose"], | ||
| "env": {"GREETING": "hello", "PORT": "8080"}, | ||
| "dirs": [ | ||
| {"hostPath": "/mnt/data", "guestPath": "/mnt/data", "readOnly": false}, | ||
| {"hostPath": "/mnt/ro", "guestPath": "/mnt/ro", "readOnly": true} | ||
| ], | ||
| "network": { | ||
| "allowIpNameLookup": true, | ||
| "tcpConnect": ["example.com:443"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| Copyright 2026 The Knative Authors | ||
|
|
||
| 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 wasmmodule | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "testing" | ||
|
|
||
| api "github.com/cardil/knative-serving-wasm/pkg/apis/wasm/v1alpha1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // TestBuildRunnerConfigMatchesGolden verifies that the JSON produced by | ||
| // buildRunnerConfig matches the documented wire format that the runner parses. | ||
| // If this test fails, both the golden file and the runner must be updated together. | ||
| func TestBuildRunnerConfigMatchesGolden(t *testing.T) { | ||
| trueVal := true | ||
| module := &api.WasmModule{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test"}, | ||
| Spec: api.WasmModuleSpec{ | ||
| Image: "example.com/img:latest", | ||
| Args: []string{"--verbose"}, | ||
| Env: []corev1.EnvVar{ | ||
| {Name: "GREETING", Value: "hello"}, | ||
| {Name: "PORT", Value: "8080"}, | ||
| }, | ||
| VolumeMounts: []corev1.VolumeMount{ | ||
| {Name: "data", MountPath: "/mnt/data", ReadOnly: false}, | ||
| {Name: "ro", MountPath: "/mnt/ro", ReadOnly: true}, | ||
| }, | ||
| Volumes: []corev1.Volume{ | ||
| {Name: "data"}, | ||
| {Name: "ro"}, | ||
| }, | ||
| Network: &api.NetworkSpec{ | ||
| Inherit: false, | ||
| AllowIpNameLookup: &trueVal, | ||
| Tcp: &api.TcpSpec{ | ||
| Connect: []string{"example.com:443"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| got, err := buildRunnerConfig(module) | ||
| if err != nil { | ||
| t.Fatalf("buildRunnerConfig() error: %v", err) | ||
| } | ||
|
|
||
| goldenBytes, err := os.ReadFile("testdata/wasi_config.golden.json") | ||
| if err != nil { | ||
| t.Fatalf("read golden file: %v", err) | ||
| } | ||
|
|
||
| var gotMap, wantMap any | ||
| if err := json.Unmarshal([]byte(got), &gotMap); err != nil { | ||
| t.Fatalf("unmarshal got: %v", err) | ||
| } | ||
| if err := json.Unmarshal(goldenBytes, &wantMap); err != nil { | ||
| t.Fatalf("unmarshal golden: %v", err) | ||
| } | ||
|
|
||
| gotJSON, _ := json.MarshalIndent(gotMap, "", " ") | ||
| wantJSON, _ := json.MarshalIndent(wantMap, "", " ") | ||
|
|
||
| if string(gotJSON) != string(wantJSON) { | ||
| t.Errorf("buildRunnerConfig output does not match golden.\ngot:\n%s\n\nwant:\n%s", gotJSON, wantJSON) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.