mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-14 19:06:46 +00:00
Adding label when a /system/function/<name> endpoint is invoked as it was missed in the previous commit Signed-off-by: Martin Dekov <mvdekov@gmail.com>
36 lines
888 B
Go
36 lines
888 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,
|
|
Labels: &f.labels,
|
|
}
|
|
|
|
functionBytes, _ := json.Marshal(found)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write(functionBytes)
|
|
} else {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|
|
}
|
|
}
|