mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-21 00:06:37 +00:00
Ensure scaling up from zero works in faasd CE
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
@ -96,32 +96,24 @@ func MakeReplicaUpdateHandler(client *containerd.Client, cni gocni.CNI) func(w h
|
|||||||
|
|
||||||
createNewTask := false
|
createNewTask := false
|
||||||
|
|
||||||
// Scale to zero
|
|
||||||
if req.Replicas == 0 {
|
if req.Replicas == 0 {
|
||||||
// If a task is running, pause it
|
http.Error(w, "replicas must > 0 for faasd CE", http.StatusBadRequest)
|
||||||
if taskExists && taskStatus.Status == containerd.Running {
|
return
|
||||||
if pauseErr := task.Pause(ctx); pauseErr != nil {
|
|
||||||
wrappedPauseErr := fmt.Errorf("error pausing task %s, error: %s", name, pauseErr)
|
|
||||||
log.Printf("[Scale] %s\n", wrappedPauseErr.Error())
|
|
||||||
http.Error(w, wrappedPauseErr.Error(), http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if taskExists {
|
if taskExists {
|
||||||
if taskStatus != nil {
|
if taskStatus != nil {
|
||||||
if taskStatus.Status == containerd.Paused {
|
if taskStatus.Status == containerd.Paused {
|
||||||
if resumeErr := task.Resume(ctx); resumeErr != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
log.Printf("[Scale] error resuming task %s, error: %s\n", name, resumeErr)
|
log.Printf("[Scale] error deleting paused task %s, error: %s\n", name, err)
|
||||||
http.Error(w, resumeErr.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if taskStatus.Status == containerd.Stopped {
|
} else if taskStatus.Status == containerd.Stopped {
|
||||||
// Stopped tasks cannot be restarted, must be removed, and created again
|
// Stopped tasks cannot be restarted, must be removed, and created again
|
||||||
if _, delErr := task.Delete(ctx); delErr != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
log.Printf("[Scale] error deleting stopped task %s, error: %s\n", name, delErr)
|
log.Printf("[Scale] error deleting stopped task %s, error: %s\n", name, err)
|
||||||
http.Error(w, delErr.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
createNewTask = true
|
createNewTask = true
|
||||||
|
Reference in New Issue
Block a user