Skip to content

Commit 4996fd6

Browse files
yroblataskbot
andauthored
do not check duplicate names when name is empty (#1440)
Co-authored-by: taskbot <[email protected]>
1 parent dec613a commit 4996fd6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

cmd/thv/app/run.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
149149
return fmt.Errorf("failed to create workload manager: %v", err)
150150
}
151151

152-
exists, err := workloadManager.DoesWorkloadExist(ctx, runFlags.Name)
153-
if err != nil {
154-
return fmt.Errorf("failed to check if workload exists: %v", err)
155-
}
156-
if exists {
157-
return fmt.Errorf("workload with name '%s' already exists", runFlags.Name)
152+
if runFlags.Name != "" {
153+
exists, err := workloadManager.DoesWorkloadExist(ctx, runFlags.Name)
154+
if err != nil {
155+
return fmt.Errorf("failed to check if workload exists: %v", err)
156+
}
157+
if exists {
158+
return fmt.Errorf("workload with name '%s' already exists", runFlags.Name)
159+
}
158160
}
159161
err = validateGroup(ctx, workloadManager, serverOrImage)
160162
if err != nil {

pkg/api/v1/workloads.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,16 @@ func (s *WorkloadRoutes) createWorkload(w http.ResponseWriter, r *http.Request)
276276
}
277277

278278
// check if the workload already exists
279-
exists, err := s.workloadManager.DoesWorkloadExist(ctx, req.Name)
280-
if err != nil {
281-
http.Error(w, fmt.Sprintf("Failed to check if workload exists: %v", err), http.StatusInternalServerError)
282-
return
283-
}
284-
if exists {
285-
http.Error(w, fmt.Sprintf("Workload with name %s already exists", req.Name), http.StatusConflict)
286-
return
279+
if req.Name != "" {
280+
exists, err := s.workloadManager.DoesWorkloadExist(ctx, req.Name)
281+
if err != nil {
282+
http.Error(w, fmt.Sprintf("Failed to check if workload exists: %v", err), http.StatusInternalServerError)
283+
return
284+
}
285+
if exists {
286+
http.Error(w, fmt.Sprintf("Workload with name %s already exists", req.Name), http.StatusConflict)
287+
return
288+
}
287289
}
288290

289291
// NOTE: None of the k8s-related config logic is included here.

0 commit comments

Comments
 (0)