Add function in payload instead of just metadata (#1919)

Passing information of function from router to executor is more efficient than calling the K8S API. This change does that instead of passing only metadata and then executor calling the K8S API again.
This commit is contained in:
Rahul Bhati
2021-03-10 14:52:23 +05:30
committed by GitHub
parent c7d448ca49
commit cc552d9777
4 changed files with 8 additions and 20 deletions
+4 -16
View File
@@ -28,8 +28,6 @@ import (
"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp"
"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/core/v1"
ferror "github.com/fission/fission/pkg/error"
@@ -44,23 +42,13 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
}
// get function metadata
m := metav1.ObjectMeta{}
err = json.Unmarshal(body, &m)
fn := &fv1.Function{}
err = json.Unmarshal(body, &fn)
if err != nil {
http.Error(w, "Failed to parse request", http.StatusBadRequest)
return
}
fn, err := executor.fissionClient.CoreV1().Functions(m.Namespace).Get(m.Name, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
http.Error(w, "Failed to find function", http.StatusNotFound)
} else {
http.Error(w, "Failed to get function", http.StatusInternalServerError)
}
return
}
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
et, exists := executor.executorTypes[t]
if !exists {
@@ -88,7 +76,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
code, msg := ferror.GetHTTPError(err)
executor.logger.Error("error getting service for function",
zap.Error(err),
zap.String("function", m.Name),
zap.String("function", fn.ObjectMeta.Name),
zap.String("fission_http_error", msg))
http.Error(w, msg, code)
return
@@ -98,7 +86,7 @@ func (executor *Executor) getServiceForFunctionAPI(w http.ResponseWriter, r *htt
if err != nil {
executor.logger.Error(
"error writing HTTP response",
zap.String("function", m.Name),
zap.String("function", fn.ObjectMeta.Name),
zap.Error(err),
)
}