@@ -269,6 +269,19 @@ func (s *WorkloadRoutes) createWorkload(w http.ResponseWriter, r *http.Request)
269
269
return
270
270
}
271
271
272
+ // check if the workload already exists
273
+ if req .Name != "" {
274
+ exists , err := s .workloadManager .DoesWorkloadExist (ctx , req .Name )
275
+ if err != nil {
276
+ http .Error (w , fmt .Sprintf ("Failed to check if workload exists: %v" , err ), http .StatusInternalServerError )
277
+ return
278
+ }
279
+ if exists {
280
+ http .Error (w , fmt .Sprintf ("Workload with name %s already exists" , req .Name ), http .StatusConflict )
281
+ return
282
+ }
283
+ }
284
+
272
285
// Create the workload using shared logic
273
286
runConfig , err := s .createWorkloadFromRequest (ctx , & req )
274
287
if err != nil {
@@ -713,18 +726,6 @@ func (s *WorkloadRoutes) createWorkloadFromRequest(ctx context.Context, req *cre
713
726
return nil , fmt .Errorf ("failed to retrieve MCP server image: %v" , err )
714
727
}
715
728
716
- // check if the workload already exists
717
- if req .Name != "" {
718
- exists , err := s .workloadManager .DoesWorkloadExist (ctx , req .Name )
719
- if err != nil {
720
- http .Error (w , fmt .Sprintf ("Failed to check if workload exists: %v" , err ), http .StatusInternalServerError )
721
- return
722
- }
723
- if exists {
724
- http .Error (w , fmt .Sprintf ("Workload with name %s already exists" , req .Name ), http .StatusConflict )
725
- return
726
- }
727
- }
728
729
729
730
// Build RunConfig
730
731
runSecrets := secrets .SecretParametersToCLI (req .Secrets )
0 commit comments