Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/workloadmanager/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func (s *Server) extractUserK8sClient(c *gin.Context) (dynamic.Interface, error)
return userClient.dynamicClient, nil
}

func respondSandboxBuildError(c *gin.Context, err error) {
switch {
case errors.Is(err, api.ErrAgentRuntimeNotFound), errors.Is(err, api.ErrCodeInterpreterNotFound):
respondError(c, http.StatusNotFound, err.Error())
case errors.Is(err, api.ErrPublicKeyMissing):
respondError(c, http.StatusServiceUnavailable, err.Error())
default:
respondError(c, http.StatusInternalServerError, "internal server error")
}
}

// handleSandboxCreate handles sandbox creation given a specific kind.
func (s *Server) handleSandboxCreate(c *gin.Context, kind string) {
sandboxReq := &types.CreateSandboxRequest{}
Expand Down Expand Up @@ -109,11 +120,7 @@ func (s *Server) handleSandboxCreate(c *gin.Context, kind string) {

if err != nil {
klog.Errorf("build sandbox failed %s/%s: %v", sandboxReq.Namespace, sandboxReq.Name, err)
if errors.Is(err, api.ErrAgentRuntimeNotFound) || errors.Is(err, api.ErrCodeInterpreterNotFound) {
respondError(c, http.StatusNotFound, err.Error())
} else {
respondError(c, http.StatusInternalServerError, "internal server error")
}
respondSandboxBuildError(c, err)
return
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/workloadmanager/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ func TestHandleSandboxCreate(t *testing.T) {
expectStatus: http.StatusNotFound,
expectMessage: api.ErrAgentRuntimeNotFound.Error(),
},
{
name: "public key missing returns service unavailable",
kind: types.CodeInterpreterKind,
body: `{"name":"workload","namespace":"ns"}`,
buildErr: api.ErrPublicKeyMissing,
expectStatus: http.StatusServiceUnavailable,
expectMessage: api.ErrPublicKeyMissing.Error(),
},
{
name: "build sandbox internal error",
kind: types.AgentRuntimeKind,
Expand Down
Loading