@@ -12,6 +12,7 @@ import (
1212 "github.com/gin-gonic/gin"
1313 redisv9 "github.com/redis/go-redis/v9"
1414 sandboxv1alpha1 "sigs.k8s.io/agent-sandbox/api/v1alpha1"
15+ "sigs.k8s.io/agent-sandbox/controllers"
1516 extensionsv1alpha1 "sigs.k8s.io/agent-sandbox/extensions/api/v1alpha1"
1617
1718 "github.com/volcano-sh/agentcube/pkg/common/types"
@@ -76,7 +77,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
7677 namespace := sandbox .Namespace
7778
7879 dynamicClient := s .k8sClient .dynamicClient
79- if s .enableAuth {
80+ if s .config . EnableAuth {
8081 // Extract user information from context
8182 userToken , userNamespace , _ , serviceAccountName := extractUserInfo (c )
8283 if userToken == "" || userNamespace == "" || serviceAccountName == "" {
@@ -162,7 +163,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
162163 }()
163164
164165 sandboxPodName := ""
165- if podName , exists := createdSandbox .Annotations ["agents.x-k8s.io/pod-name" ]; exists {
166+ if podName , exists := createdSandbox .Annotations [controllers . SanboxPodNameAnnotation ]; exists {
166167 sandboxPodName = podName
167168 }
168169 podIP , err := s .k8sClient .GetSandboxPodIP (c .Request .Context (), namespace , sandboxName , sandboxPodName )
@@ -194,6 +195,12 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
194195 return
195196 }
196197
198+ if len (redisCacheInfo .EntryPoints ) == 0 {
199+ respondError (c , http .StatusInternalServerError , "SANDBOX_INIT_FAILED" ,
200+ "No access endpoint found for sandbox initialization" )
201+ return
202+ }
203+
197204 // Code Interpreter sandbox created, init code interpreter
198205 // Find the /init endpoint from entryPoints
199206 var initEndpoint string
@@ -204,17 +211,10 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
204211 }
205212 }
206213
207- // If no /init path found, use the first entryPoint endpoint with /init appended
214+ // If no /init path found, use the first entryPoint endpoint fallback
208215 if initEndpoint == "" {
209- if len (redisCacheInfo .EntryPoints ) > 0 {
210- initEndpoint = fmt .Sprintf ("%s://%s" ,
211- redisCacheInfo .EntryPoints [0 ].Protocol ,
212- redisCacheInfo .EntryPoints [0 ].Endpoint )
213- } else {
214- respondError (c , http .StatusInternalServerError , "SANDBOX_INIT_FAILED" ,
215- "No access endpoint found for sandbox initialization" )
216- return
217- }
216+ initEndpoint = fmt .Sprintf ("%s://%s" , redisCacheInfo .EntryPoints [0 ].Protocol ,
217+ redisCacheInfo .EntryPoints [0 ].Endpoint )
218218 }
219219
220220 // Call sandbox init endpoint with JWT-signed request
@@ -224,6 +224,7 @@ func (s *Server) handleCreateSandbox(c *gin.Context) {
224224 sandbox .Labels [SessionIdLabelKey ],
225225 createAgentRequest .PublicKey ,
226226 createAgentRequest .Metadata ,
227+ createAgentRequest .InitTimeoutSeconds ,
227228 )
228229
229230 if err != nil {
@@ -263,7 +264,7 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
263264 }
264265
265266 dynamicClient := s .k8sClient .dynamicClient
266- if s .enableAuth {
267+ if s .config . EnableAuth {
267268 // Extract user information from context
268269 userToken , userNamespace , _ , serviceAccountName := extractUserInfo (c )
269270
@@ -282,20 +283,18 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
282283 dynamicClient = userClient .dynamicClient
283284 }
284285
285- if sandbox .SandboxClaimName != "" {
286- // SandboxClaimName is not empty, we should delete SandboxClaim
287- err = deleteSandboxClaim (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .SandboxClaimName )
286+ if sandbox .Kind == types .SandboxClaimsKind {
287+ err = deleteSandboxClaim (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .Name )
288288 if err != nil {
289- log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .SandboxClaimName , err )
289+ log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .Name , err )
290290 respondError (c , http .StatusForbidden , "SANDBOX_CLAIM_DELETE_FAILED" ,
291291 fmt .Sprintf ("Failed to delete sandbox claim (namespace: %s): %v" , sandbox .SandboxNamespace , err ))
292292 return
293293 }
294294 } else {
295- // SandboxClaimName is empty, we should delete Sandbox directly
296- err = deleteSandbox (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .SandboxName )
295+ err = deleteSandbox (c .Request .Context (), dynamicClient , sandbox .SandboxNamespace , sandbox .Name )
297296 if err != nil {
298- log .Printf ("failed to delete sandbox claim %s/%s: %v" , sandbox .SandboxNamespace , sandbox .SandboxName , err )
297+ log .Printf ("failed to delete sandbox %s/%s: %v" , sandbox .SandboxNamespace , sandbox .Name , err )
299298 respondError (c , http .StatusForbidden , "SANDBOX_DELETE_FAILED" ,
300299 fmt .Sprintf ("Failed to delete sandbox (namespace: %s): %v" , sandbox .SandboxNamespace , err ))
301300 return
@@ -309,12 +308,7 @@ func (s *Server) handleDeleteSandbox(c *gin.Context) {
309308 return
310309 }
311310
312- objectType := SandboxGVR .Resource
313- objectName := sandbox .SandboxName
314- if sandbox .SandboxClaimName != "" {
315- objectName = sandbox .SandboxClaimName
316- }
317- log .Printf ("delete %s %s/%s successfully, sessionID: %v " , objectType , sandbox .SandboxNamespace , objectName , sandbox .SessionID )
311+ log .Printf ("delete %s %s/%s successfully, sessionID: %v " , sandbox .Kind , sandbox .SandboxNamespace , sandbox .Name , sandbox .SessionID )
318312 respondJSON (c , http .StatusOK , map [string ]string {
319313 "message" : "Sandbox deleted successfully" ,
320314 })
0 commit comments