Skip to content

Commit 66914f7

Browse files
committed
move workload create duplicate check only to create
Signed-off-by: lujunsan <[email protected]>
1 parent 47879b5 commit 66914f7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

pkg/api/v1/workloads.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ func (s *WorkloadRoutes) createWorkload(w http.ResponseWriter, r *http.Request)
269269
return
270270
}
271271

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+
272285
// Create the workload using shared logic
273286
runConfig, err := s.createWorkloadFromRequest(ctx, &req)
274287
if err != nil {
@@ -713,18 +726,6 @@ func (s *WorkloadRoutes) createWorkloadFromRequest(ctx context.Context, req *cre
713726
return nil, fmt.Errorf("failed to retrieve MCP server image: %v", err)
714727
}
715728

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-
}
728729

729730
// Build RunConfig
730731
runSecrets := secrets.SecretParametersToCLI(req.Secrets)

0 commit comments

Comments
 (0)