Skip to content

Commit a41fed3

Browse files
committed
Rename to /scaletozero/{pin,unpin} and Pin/Unpin per review
Address review feedback: - Path /system/standby/* implied VM-state mutation; rename to /scaletozero/{pin,unpin} so the operation is specific to the scale-to-zero gate. - Interface methods DisablePin/EnablePin read as inverted; rename to Pin/Unpin for clarity. - Rewrite openapi summary/description to be caller-focused (what it does, when to call, what pairs with).
1 parent 6d93680 commit a41fed3

7 files changed

Lines changed: 361 additions & 361 deletions

File tree

server/cmd/api/api/scaletozero.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package api
2+
3+
import (
4+
"context"
5+
6+
"github.com/kernel/kernel-images/server/lib/logger"
7+
oapi "github.com/kernel/kernel-images/server/lib/oapi"
8+
)
9+
10+
func (s *ApiService) PinScaleToZero(ctx context.Context, _ oapi.PinScaleToZeroRequestObject) (oapi.PinScaleToZeroResponseObject, error) {
11+
if err := s.stz.Pin(ctx); err != nil {
12+
logger.FromContext(ctx).Error("failed to pin scale-to-zero", "err", err)
13+
return oapi.PinScaleToZero500JSONResponse{InternalErrorJSONResponse: oapi.InternalErrorJSONResponse{Message: "failed to pin scale-to-zero"}}, nil
14+
}
15+
return oapi.PinScaleToZero204Response{}, nil
16+
}
17+
18+
func (s *ApiService) UnpinScaleToZero(ctx context.Context, _ oapi.UnpinScaleToZeroRequestObject) (oapi.UnpinScaleToZeroResponseObject, error) {
19+
if err := s.stz.Unpin(ctx); err != nil {
20+
logger.FromContext(ctx).Error("failed to unpin scale-to-zero", "err", err)
21+
return oapi.UnpinScaleToZero500JSONResponse{InternalErrorJSONResponse: oapi.InternalErrorJSONResponse{Message: "failed to unpin scale-to-zero"}}, nil
22+
}
23+
return oapi.UnpinScaleToZero204Response{}, nil
24+
}

server/cmd/api/api/standby.go

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"github.com/stretchr/testify/require"
1111
)
1212

13-
// TestStandbyDisableEnable exercises POST /system/standby/{disable,enable}
14-
// against the real built image. The unikraft control file does not exist
15-
// inside the docker test container, so the underlying scale-to-zero write
16-
// is a no-op — this test validates HTTP wiring, idempotency, and that the
17-
// scale-to-zero middleware coexists with the pin handlers.
18-
func TestStandbyDisableEnable(t *testing.T) {
13+
// TestScaleToZeroPinUnpin exercises POST /scaletozero/{pin,unpin} against the
14+
// real built image. The unikraft control file does not exist inside the docker
15+
// test container, so the underlying scale-to-zero write is a no-op — this test
16+
// validates HTTP wiring, idempotency, and that the scale-to-zero middleware
17+
// coexists with the pin handlers.
18+
func TestScaleToZeroPinUnpin(t *testing.T) {
1919
t.Parallel()
2020

2121
if _, err := exec.LookPath("docker"); err != nil {
@@ -34,13 +34,13 @@ func TestStandbyDisableEnable(t *testing.T) {
3434
client, err := c.APIClient()
3535
require.NoError(t, err, "failed to create API client")
3636

37-
// Idempotent disable.
38-
r1, err := client.DisableStandbyWithResponse(ctx)
39-
require.NoError(t, err, "DisableStandby request failed")
37+
// Idempotent pin.
38+
r1, err := client.PinScaleToZeroWithResponse(ctx)
39+
require.NoError(t, err, "PinScaleToZero request failed")
4040
require.Equal(t, http.StatusNoContent, r1.StatusCode(), "unexpected status: %s body=%s", r1.Status(), string(r1.Body))
4141

42-
r2, err := client.DisableStandbyWithResponse(ctx)
43-
require.NoError(t, err, "second DisableStandby request failed")
42+
r2, err := client.PinScaleToZeroWithResponse(ctx)
43+
require.NoError(t, err, "second PinScaleToZero request failed")
4444
require.Equal(t, http.StatusNoContent, r2.StatusCode(), "unexpected status: %s body=%s", r2.Status(), string(r2.Body))
4545

4646
// Normal request must still flow while pinned (scaletozero middleware
@@ -49,12 +49,12 @@ func TestStandbyDisableEnable(t *testing.T) {
4949
require.NoError(t, err, "ReadClipboard request failed while pinned")
5050
require.Equal(t, http.StatusOK, readResp.StatusCode(), "unexpected read status while pinned: %s body=%s", readResp.Status(), string(readResp.Body))
5151

52-
// Idempotent enable.
53-
r3, err := client.EnableStandbyWithResponse(ctx)
54-
require.NoError(t, err, "EnableStandby request failed")
52+
// Idempotent unpin.
53+
r3, err := client.UnpinScaleToZeroWithResponse(ctx)
54+
require.NoError(t, err, "UnpinScaleToZero request failed")
5555
require.Equal(t, http.StatusNoContent, r3.StatusCode(), "unexpected status: %s body=%s", r3.Status(), string(r3.Body))
5656

57-
r4, err := client.EnableStandbyWithResponse(ctx)
58-
require.NoError(t, err, "second EnableStandby request failed")
57+
r4, err := client.UnpinScaleToZeroWithResponse(ctx)
58+
require.NoError(t, err, "second UnpinScaleToZero request failed")
5959
require.Equal(t, http.StatusNoContent, r4.StatusCode(), "unexpected status: %s body=%s", r4.Status(), string(r4.Body))
6060
}

0 commit comments

Comments
 (0)