Skip to content

Commit

Permalink
restapi: don't allow updating resume task
Browse files Browse the repository at this point in the history
The suspend/resume task is unique and the properties that are updated
for other suspend tasks do not apply.
  • Loading branch information
kevinbarbour authored and mmatczuk committed Apr 11, 2022
1 parent 77033f9 commit 98496ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/restapi/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ func (h *taskHandler) updateTask(w http.ResponseWriter, r *http.Request) {
newTask.ID = t.ID
newTask.Type = t.Type

if newTask.ID == scheduler.ResumeTaskID {
respondError(w, r, errors.New("resume task cannot be updated"))
}

if err := h.validateTask(r.Context(), newTask, newTask.Properties); err != nil {
respondError(w, r, err)
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/scheduler/service_suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ func (s *Service) resetSchedulerLocked(si *suspendInfo) *scheduler.Scheduler {
return l
}

// resumeTaskID is a special task ID reserved for scheduled resume of suspended cluster.
// ResumeTaskID is a special task ID reserved for scheduled resume of suspended cluster.
// It can be reused for different suspend tasks at different times.
// Note that a suspended cluster cannot be suspended.
var resumeTaskID = uuid.MustParse("805E43B0-2C0A-481E-BAB8-9C2418940D67")
var ResumeTaskID = uuid.MustParse("805E43B0-2C0A-481E-BAB8-9C2418940D67")

func newResumeTask(si *suspendInfo, p SuspendProperties) (*Task, error) {
p.Resume = true
Expand All @@ -187,7 +187,7 @@ func newResumeTask(si *suspendInfo, p SuspendProperties) (*Task, error) {
return &Task{
ClusterID: si.ClusterID,
Type: SuspendTask,
ID: resumeTaskID,
ID: ResumeTaskID,
Name: "resume",
Enabled: true,
Sched: Schedule{
Expand All @@ -204,7 +204,7 @@ func newDisabledResumeTask(clusterID uuid.UUID) *Task {
return &Task{
ClusterID: clusterID,
Type: SuspendTask,
ID: resumeTaskID,
ID: ResumeTaskID,
Name: "resume",
}
}
Expand Down

0 comments on commit 98496ef

Please sign in to comment.