@@ -14,6 +14,7 @@ import (
1414 "github.com/volcano-sh/agentcube/pkg/common/types"
1515 "github.com/volcano-sh/agentcube/pkg/redis"
1616 sandboxv1alpha1 "sigs.k8s.io/agent-sandbox/api/v1alpha1"
17+ "sigs.k8s.io/agent-sandbox/controllers"
1718 extensionsv1alpha1 "sigs.k8s.io/agent-sandbox/extensions/api/v1alpha1"
1819)
1920
@@ -75,7 +76,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
7576 namespace := sandbox .Namespace
7677
7778 dynamicClient := s .k8sClient .dynamicClient
78- if s .enableAuth {
79+ if s .config . EnableAuth {
7980 // Extract user information from context
8081 userToken , userNamespace , _ , serviceAccountName := extractUserInfo (c )
8182 if userToken == "" || userNamespace == "" || serviceAccountName == "" {
@@ -161,7 +162,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
161162 }()
162163
163164 sandboxPodName := ""
164- if podName , exists := createdSandbox .Annotations ["agents.x-k8s.io/pod-name" ]; exists {
165+ if podName , exists := createdSandbox .Annotations [controllers . SanboxPodNameAnnotation ]; exists {
165166 sandboxPodName = podName
166167 }
167168 podIP , err := s .k8sClient .GetSandboxPodIP (c .Request .Context (), namespace , sandboxName , sandboxPodName )
@@ -193,6 +194,12 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
193194 return
194195 }
195196
197+ if len (redisCacheInfo .EntryPoints ) == 0 {
198+ respondError (c , http .StatusInternalServerError , "SANDBOX_INIT_FAILED" ,
199+ "No access endpoint found for sandbox initialization" )
200+ return
201+ }
202+
196203 // Code Interpreter sandbox created, init code interpreter
197204 // Find the /init endpoint from entryPoints
198205 var initEndpoint string
@@ -203,17 +210,10 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
203210 }
204211 }
205212
206- // If no /init path found, use the first entryPoint endpoint with /init appended
213+ // If no /init path found, use the first entryPoint endpoint fallback
207214 if initEndpoint == "" {
208- if len (redisCacheInfo .EntryPoints ) > 0 {
209- initEndpoint = fmt .Sprintf ("%s://%s" ,
210- redisCacheInfo .EntryPoints [0 ].Protocol ,
211- redisCacheInfo .EntryPoints [0 ].Endpoint )
212- } else {
213- respondError (c , http .StatusInternalServerError , "SANDBOX_INIT_FAILED" ,
214- "No access endpoint found for sandbox initialization" )
215- return
216- }
215+ initEndpoint = fmt .Sprintf ("%s://%s" , redisCacheInfo .EntryPoints [0 ].Protocol ,
216+ redisCacheInfo .EntryPoints [0 ].Endpoint )
217217 }
218218
219219 // Call sandbox init endpoint with JWT-signed request
@@ -223,6 +223,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
223223 sandbox .Labels [SessionIdLabelKey ],
224224 createAgentRequest .PublicKey ,
225225 createAgentRequest .Metadata ,
226+ createAgentRequest .InitTimeoutSeconds ,
226227 )
227228
228229 if err != nil {
@@ -262,7 +263,7 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
262263 }
263264
264265 dynamicClient := s .k8sClient .dynamicClient
265- if s .enableAuth {
266+ if s .config . EnableAuth {
266267 // Extract user information from context
267268 userToken , userNamespace , _ , serviceAccountName := extractUserInfo (c )
268269
@@ -281,20 +282,18 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
281282 dynamicClient = userClient .dynamicClient
282283 }
283284
284- if sandbox .SandboxClaimName != "" {
285- // SandboxClaimName is not empty, we should delete SandboxClaim
286- err = deleteSandboxClaim (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .SandboxClaimName )
285+ if sandbox .Kind == types .SandboxClaimsKind {
286+ err = deleteSandboxClaim (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .Name )
287287 if err != nil {
288- log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .SandboxClaimName , err )
288+ log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .Name , err )
289289 respondError (c , http .StatusForbidden , "SANDBOX_CLAIM_DELETE_FAILED" ,
290290 fmt .Sprintf ("Failed to delete sandbox claim (namespace: %s): %v" , sandbox .SandboxNamespace , err ))
291291 return
292292 }
293293 } else {
294- // SandboxClaimName is empty, we should delete Sandbox directly
295- err = deleteSandbox (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .SandboxName )
294+ err = deleteSandbox (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .Name )
296295 if err != nil {
297- log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .SandboxName , err )
296+ log .Printf ("failed to delete sandbox %s/%s: %v" , sandbox .SandboxNamespace , sandbox .Name , err )
298297 respondError (c , http .StatusForbidden , "SANDBOX_DELETE_FAILED" ,
299298 fmt .Sprintf ("Failed to delete sandbox (namespace: %s): %v" , sandbox .SandboxNamespace , err ))
300299 return
@@ -308,12 +307,7 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
308307 return
309308 }
310309
311- objectType := SandboxGVR .Resource
312- objectName := sandbox .SandboxName
313- if sandbox .SandboxClaimName != "" {
314- objectName = sandbox .SandboxClaimName
315- }
316- log .Printf ("delete %s %s/%s successfully, sessionID: %v " , objectType , sandbox .SandboxNamespace , objectName , sandbox .SessionID )
310+ log .Printf ("delete %s %s/%s successfully, sessionID: %v " , sandbox .Kind , sandbox .SandboxNamespace , sandbox .Name , sandbox .SessionID )
317311 respondJSON (c , http .StatusOK , map [string ]string {
318312 "message" : "Sandbox deleted successfully" ,
319313 })
0 commit comments