-
Notifications
You must be signed in to change notification settings - Fork 191
Allow runtime image in workload API #3772
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
base: main
Are you sure you want to change the base?
Changes from all commits
97e8aa6
3538749
a3e0fae
22a536b
c9e06bc
1e6e895
23ff88f
a638c4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,11 +104,13 @@ func TestCreateWorkload(t *testing.T) { | |
| logger.Initialize() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| requestBody string | ||
| setupMock func(*testing.T, *workloadsmocks.MockManager, *runtimemocks.MockRuntime, *groupsmocks.MockManager) | ||
| expectedStatus int | ||
| expectedBody string | ||
| name string | ||
| requestBody string | ||
| setupMock func(*testing.T, *workloadsmocks.MockManager, *runtimemocks.MockRuntime, *groupsmocks.MockManager) | ||
| expectedServerOrImage string | ||
| expectedRuntimeConfig *templates.RuntimeConfig | ||
| expectedStatus int | ||
| expectedBody string | ||
| }{ | ||
| { | ||
| name: "invalid JSON", | ||
|
|
@@ -137,6 +139,28 @@ func TestCreateWorkload(t *testing.T) { | |
| expectedStatus: http.StatusBadRequest, | ||
| expectedBody: "Invalid proxy_mode", | ||
| }, | ||
| { | ||
| name: "with runtime config override", | ||
| requestBody: `{"name": "test-workload", "image": "go://github.com/example/server", "runtime_config": {"builder_image": "golang:1.24-alpine", "additional_packages": ["ca-certificates"]}}`, | ||
| setupMock: func(_ *testing.T, wm *workloadsmocks.MockManager, _ *runtimemocks.MockRuntime, gm *groupsmocks.MockManager) { | ||
| wm.EXPECT().DoesWorkloadExist(gomock.Any(), "test-workload").Return(false, nil) | ||
| gm.EXPECT().Exists(gomock.Any(), "default").Return(true, nil) | ||
| wm.EXPECT().RunWorkloadDetached(gomock.Any(), gomock.Any()). | ||
| DoAndReturn(func(_ context.Context, runConfig *runner.RunConfig) error { | ||
| assert.NotNil(t, runConfig.RuntimeConfig) | ||
| assert.Equal(t, "golang:1.24-alpine", runConfig.RuntimeConfig.BuilderImage) | ||
| assert.Equal(t, []string{"ca-certificates"}, runConfig.RuntimeConfig.AdditionalPackages) | ||
| return nil | ||
| }) | ||
| }, | ||
| expectedRuntimeConfig: &templates.RuntimeConfig{ | ||
| BuilderImage: "golang:1.24-alpine", | ||
| AdditionalPackages: []string{"ca-certificates"}, | ||
| }, | ||
| expectedServerOrImage: "go://github.com/example/server", | ||
| expectedStatus: http.StatusCreated, | ||
| expectedBody: "test-workload", | ||
| }, | ||
| { | ||
| name: "with tool filters", | ||
|
Comment on lines
+142
to
165
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good test for the happy path! A few edge cases are missing that would strengthen coverage:
|
||
| requestBody: `{"name": "test-workload", "image": "test-image", "tools": ["filter1", "filter2"]}`, | ||
|
|
@@ -212,12 +236,17 @@ func TestCreateWorkload(t *testing.T) { | |
| mockGroupManager := groupsmocks.NewMockManager(ctrl) | ||
|
|
||
| tt.setupMock(t, mockWorkloadManager, mockRuntime, mockGroupManager) | ||
| expectedServerOrImage := tt.expectedServerOrImage | ||
| if expectedServerOrImage == "" { | ||
| expectedServerOrImage = "test-image" | ||
| } | ||
|
|
||
| mockRetriever := makeMockRetriever(t, | ||
| "test-image", | ||
| expectedServerOrImage, | ||
| "test-image", | ||
| ®types.ImageMetadata{Image: "test-image"}, | ||
| nil, | ||
| tt.expectedRuntimeConfig, | ||
| ) | ||
|
|
||
| routes := &WorkloadRoutes{ | ||
|
|
@@ -411,6 +440,7 @@ func TestUpdateWorkload(t *testing.T) { | |
| "test-image", | ||
| ®types.ImageMetadata{Image: "test-image"}, | ||
| nil, | ||
| nil, | ||
| ) | ||
|
|
||
| routes := &WorkloadRoutes{ | ||
|
|
@@ -556,6 +586,7 @@ func TestUpdateWorkload_PortReuse(t *testing.T) { | |
| "test-image", | ||
| ®types.ImageMetadata{Image: "test-image"}, | ||
| nil, | ||
| nil, | ||
| ) | ||
|
|
||
| routes := &WorkloadRoutes{ | ||
|
|
@@ -595,12 +626,14 @@ func makeMockRetriever( | |
| returnedImage string, | ||
| returnedServerMetadata regtypes.ServerMetadata, | ||
| returnedError error, | ||
| expectedRuntimeConfig *templates.RuntimeConfig, | ||
| ) retriever.Retriever { | ||
| t.Helper() | ||
|
|
||
| return func(_ context.Context, serverOrImage string, _ string, verificationType string, _ string, _ *templates.RuntimeConfig) (string, regtypes.ServerMetadata, error) { | ||
| return func(_ context.Context, serverOrImage string, _ string, verificationType string, _ string, runtimeConfig *templates.RuntimeConfig) (string, regtypes.ServerMetadata, error) { | ||
| assert.Equal(t, expectedServerOrImage, serverOrImage) | ||
| assert.Equal(t, retriever.VerifyImageWarn, verificationType) | ||
| assert.Equal(t, expectedRuntimeConfig, runtimeConfig) | ||
| return returnedImage, returnedServerMetadata, returnedError | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "Runtime overrides only apply to protocol-scheme image builds" but if a user passes
runtime_configwith a regular Docker image (notgo://,npx://,uvx://), no warning or error is returned -- it's silently ignored. This will confuse users who expect it to have an effect.Consider returning a validation error (or at least a warning in the response) when
runtime_configis provided alongside a non-protocol-scheme image.