-
Notifications
You must be signed in to change notification settings - Fork 67
API for out-of-band scale-to-zero pin #237
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
+864
−191
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b66403f
Add /system/standby API for out-of-band scale-to-zero pin
sjmiller609 6d93680
Add e2e test for /system/standby endpoints
sjmiller609 a41fed3
Rename to /scaletozero/{pin,unpin} and Pin/Unpin per review
sjmiller609 101e27c
Rename API paths to /scaletozero/{disable,enable}
sjmiller609 7d26ce6
Align scale-to-zero internal terminology with OpenAPI spec
sjmiller609 7183576
Revert "Align scale-to-zero internal terminology with OpenAPI spec"
sjmiller609 d6e82dd
Rename Pin/Unpin to DisableStz/EnableStz
sjmiller609 8361537
Revert "Rename Pin/Unpin to DisableStz/EnableStz"
sjmiller609 1f9779c
Make Unpin retryable when the underlying Enable fails
sjmiller609 e15d112
Merge branch 'main' into hypeship/scaletozero-pin-api
sjmiller609 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
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/kernel/kernel-images/server/lib/logger" | ||
| oapi "github.com/kernel/kernel-images/server/lib/oapi" | ||
| ) | ||
|
|
||
| func (s *ApiService) DisableStandby(ctx context.Context, _ oapi.DisableStandbyRequestObject) (oapi.DisableStandbyResponseObject, error) { | ||
| if err := s.stz.DisablePin(ctx); err != nil { | ||
| logger.FromContext(ctx).Error("failed to pin scale-to-zero disabled", "err", err) | ||
| return oapi.DisableStandby500JSONResponse{InternalErrorJSONResponse: oapi.InternalErrorJSONResponse{Message: "failed to disable standby"}}, nil | ||
| } | ||
| return oapi.DisableStandby204Response{}, nil | ||
| } | ||
|
|
||
| func (s *ApiService) EnableStandby(ctx context.Context, _ oapi.EnableStandbyRequestObject) (oapi.EnableStandbyResponseObject, error) { | ||
| if err := s.stz.EnablePin(ctx); err != nil { | ||
| logger.FromContext(ctx).Error("failed to release scale-to-zero pin", "err", err) | ||
| return oapi.EnableStandby500JSONResponse{InternalErrorJSONResponse: oapi.InternalErrorJSONResponse{Message: "failed to enable standby"}}, nil | ||
| } | ||
| return oapi.EnableStandby204Response{}, nil | ||
| } |
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,60 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "os/exec" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestStandbyDisableEnable exercises POST /system/standby/{disable,enable} | ||
| // against the real built image. The unikraft control file does not exist | ||
| // inside the docker test container, so the underlying scale-to-zero write | ||
| // is a no-op — this test validates HTTP wiring, idempotency, and that the | ||
| // scale-to-zero middleware coexists with the pin handlers. | ||
| func TestStandbyDisableEnable(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| if _, err := exec.LookPath("docker"); err != nil { | ||
| t.Skipf("docker not available: %v", err) | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
| defer cancel() | ||
|
|
||
| c := NewTestContainer(t, headlessImage) | ||
| require.NoError(t, c.Start(ctx, ContainerConfig{}), "failed to start container") | ||
| defer c.Stop(ctx) | ||
|
|
||
| require.NoError(t, c.WaitReady(ctx), "api not ready") | ||
|
|
||
| client, err := c.APIClient() | ||
| require.NoError(t, err, "failed to create API client") | ||
|
|
||
| // Idempotent disable. | ||
| r1, err := client.DisableStandbyWithResponse(ctx) | ||
| require.NoError(t, err, "DisableStandby request failed") | ||
| require.Equal(t, http.StatusNoContent, r1.StatusCode(), "unexpected status: %s body=%s", r1.Status(), string(r1.Body)) | ||
|
|
||
| r2, err := client.DisableStandbyWithResponse(ctx) | ||
| require.NoError(t, err, "second DisableStandby request failed") | ||
| require.Equal(t, http.StatusNoContent, r2.StatusCode(), "unexpected status: %s body=%s", r2.Status(), string(r2.Body)) | ||
|
|
||
| // Normal request must still flow while pinned (scaletozero middleware | ||
| // runs on every request — the pin must not deadlock or break it). | ||
| readResp, err := client.ReadClipboardWithResponse(ctx) | ||
| require.NoError(t, err, "ReadClipboard request failed while pinned") | ||
| require.Equal(t, http.StatusOK, readResp.StatusCode(), "unexpected read status while pinned: %s body=%s", readResp.Status(), string(readResp.Body)) | ||
|
|
||
| // Idempotent enable. | ||
| r3, err := client.EnableStandbyWithResponse(ctx) | ||
| require.NoError(t, err, "EnableStandby request failed") | ||
| require.Equal(t, http.StatusNoContent, r3.StatusCode(), "unexpected status: %s body=%s", r3.Status(), string(r3.Body)) | ||
|
|
||
| r4, err := client.EnableStandbyWithResponse(ctx) | ||
| require.NoError(t, err, "second EnableStandby request failed") | ||
| require.Equal(t, http.StatusNoContent, r4.StatusCode(), "unexpected status: %s body=%s", r4.Status(), string(r4.Body)) | ||
| } |
Oops, something went wrong.
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.