mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-09 00:16:46 +00:00
Fixes a bug when attempting to access a non-existant IP from GetIPfromPID called via the list API. Renames the provider from faas-containerd Updates function deletion grace period to 30s to prevent any errors in the REST API during a long-running deletion. Tested on Linux with the figlet function which by default takes around 5s to delete due to its write_timeout value, the deletion now blocks rather than throwing an error. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/alexellis/faasd/pkg/service"
|
|
"github.com/containerd/containerd"
|
|
"github.com/containerd/containerd/namespaces"
|
|
gocni "github.com/containerd/go-cni"
|
|
"github.com/openfaas/faas/gateway/requests"
|
|
)
|
|
|
|
func MakeDeleteHandler(client *containerd.Client, cni gocni.CNI) func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Body == nil {
|
|
http.Error(w, "expected a body", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
defer r.Body.Close()
|
|
|
|
body, _ := ioutil.ReadAll(r.Body)
|
|
log.Printf("[Delete] request: %s\n", string(body))
|
|
|
|
req := requests.DeleteFunctionRequest{}
|
|
err := json.Unmarshal(body, &req)
|
|
if err != nil {
|
|
log.Printf("[Delete] error parsing input: %s\n", err)
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
|
|
name := req.FunctionName
|
|
|
|
function, err := GetFunction(client, name)
|
|
if err != nil {
|
|
msg := fmt.Sprintf("service %s not found", name)
|
|
log.Printf("[Delete] %s\n", msg)
|
|
http.Error(w, msg, http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
ctx := namespaces.WithNamespace(context.Background(), FunctionNamespace)
|
|
|
|
// TODO: this needs to still happen if the task is paused
|
|
if function.replicas != 0 {
|
|
err = DeleteCNINetwork(ctx, cni, client, name)
|
|
if err != nil {
|
|
log.Printf("[Delete] error removing CNI network for %s, %s\n", name, err)
|
|
}
|
|
}
|
|
|
|
containerErr := service.Remove(ctx, client, name)
|
|
if containerErr != nil {
|
|
log.Printf("[Delete] error removing %s, %s\n", name, containerErr)
|
|
http.Error(w, containerErr.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
log.Printf("[Delete] deleted %s\n", name)
|
|
}
|
|
}
|