Skip to content

Commit dba5efd

Browse files
Map public key
Signed-off-by: Mrinal Chaturvedi <mrinal.chaturvedi27@gmail.com>
1 parent abb1bf3 commit dba5efd

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

pkg/workloadmanager/handlers.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ func (s *Server) extractUserK8sClient(c *gin.Context) (dynamic.Interface, error)
7979
return userClient.dynamicClient, nil
8080
}
8181

82+
func respondSandboxBuildError(c *gin.Context, err error) {
83+
switch {
84+
case errors.Is(err, api.ErrAgentRuntimeNotFound), errors.Is(err, api.ErrCodeInterpreterNotFound):
85+
respondError(c, http.StatusNotFound, err.Error())
86+
case errors.Is(err, api.ErrPublicKeyMissing):
87+
respondError(c, http.StatusServiceUnavailable, err.Error())
88+
default:
89+
respondError(c, http.StatusInternalServerError, "internal server error")
90+
}
91+
}
92+
8293
// handleSandboxCreate handles sandbox creation given a specific kind.
8394
func (s *Server) handleSandboxCreate(c *gin.Context, kind string) {
8495
sandboxReq := &types.CreateSandboxRequest{}
@@ -109,11 +120,7 @@ func (s *Server) handleSandboxCreate(c *gin.Context, kind string) {
109120

110121
if err != nil {
111122
klog.Errorf("build sandbox failed %s/%s: %v", sandboxReq.Namespace, sandboxReq.Name, err)
112-
if errors.Is(err, api.ErrAgentRuntimeNotFound) || errors.Is(err, api.ErrCodeInterpreterNotFound) {
113-
respondError(c, http.StatusNotFound, err.Error())
114-
} else {
115-
respondError(c, http.StatusInternalServerError, "internal server error")
116-
}
123+
respondSandboxBuildError(c, err)
117124
return
118125
}
119126

pkg/workloadmanager/handlers_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ func TestHandleSandboxCreate(t *testing.T) {
334334
expectStatus: http.StatusNotFound,
335335
expectMessage: api.ErrAgentRuntimeNotFound.Error(),
336336
},
337+
{
338+
name: "public key missing returns service unavailable",
339+
kind: types.CodeInterpreterKind,
340+
body: `{"name":"workload","namespace":"ns"}`,
341+
buildErr: api.ErrPublicKeyMissing,
342+
expectStatus: http.StatusServiceUnavailable,
343+
expectMessage: api.ErrPublicKeyMissing.Error(),
344+
},
337345
{
338346
name: "build sandbox internal error",
339347
kind: types.AgentRuntimeKind,

0 commit comments

Comments
 (0)