mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-10 08:56:47 +00:00
This patch completes part of the work in #20 by porting the code for faas-containerd in-tree. When tested, I was able to deploy and then remove figlet from the store on `x86_64`. In a follow-up PR, duplication will be removed where possible and consolidated with updated documentation. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
35 lines
854 B
Go
35 lines
854 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/containerd/containerd"
|
|
"github.com/gorilla/mux"
|
|
"github.com/openfaas/faas-provider/types"
|
|
)
|
|
|
|
func MakeReplicaReaderHandler(client *containerd.Client) func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
functionName := vars["name"]
|
|
|
|
if f, err := GetFunction(client, functionName); err == nil {
|
|
found := types.FunctionStatus{
|
|
Name: functionName,
|
|
AvailableReplicas: uint64(f.replicas),
|
|
Replicas: uint64(f.replicas),
|
|
Namespace: f.namespace,
|
|
}
|
|
|
|
functionBytes, _ := json.Marshal(found)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(functionBytes)
|
|
} else {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|
|
}
|
|
}
|