diff --git a/pkg/executor/api.go b/pkg/executor/api.go index b52777f7..33afc89a 100644 --- a/pkg/executor/api.go +++ b/pkg/executor/api.go @@ -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), ) } diff --git a/pkg/executor/client/client.go b/pkg/executor/client/client.go index 0d7e260a..06e6828a 100644 --- a/pkg/executor/client/client.go +++ b/pkg/executor/client/client.go @@ -70,10 +70,10 @@ func MakeClient(logger *zap.Logger, executorURL string) *Client { } // GetServiceForFunction returns the service name for a given function. -func (c *Client) GetServiceForFunction(ctx context.Context, metadata *metav1.ObjectMeta) (string, error) { +func (c *Client) GetServiceForFunction(ctx context.Context, fn *fv1.Function) (string, error) { executorURL := c.executorURL + "/v2/getServiceForFunction" - body, err := json.Marshal(metadata) + body, err := json.Marshal(fn) if err != nil { return "", errors.Wrap(err, "could not marshal request body for getting service for function") } diff --git a/pkg/executor/executor_test.go b/pkg/executor/executor_test.go index cc9bdce3..b8ca3aba 100644 --- a/pkg/executor/executor_test.go +++ b/pkg/executor/executor_test.go @@ -256,7 +256,7 @@ func TestExecutor(t *testing.T) { // the main test: get a service for a given function t1 := time.Now() - svc, err := poolmgrClient.GetServiceForFunction(context.Background(), &f.ObjectMeta) + svc, err := poolmgrClient.GetServiceForFunction(context.Background(), f) if err != nil { log.Panicf("failed to get func svc: %v", err) } diff --git a/pkg/router/functionHandler.go b/pkg/router/functionHandler.go index 055d1f7d..50993a21 100644 --- a/pkg/router/functionHandler.go +++ b/pkg/router/functionHandler.go @@ -528,7 +528,7 @@ func (fh functionHandler) getServiceEntryFromExecutor() (*url.URL, error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() - service, err := fh.executor.GetServiceForFunction(ctx, &fh.function.ObjectMeta) + service, err := fh.executor.GetServiceForFunction(ctx, fh.function) if err != nil { statusCode, errMsg := ferror.GetHTTPError(err) fh.logger.Error("error from GetServiceForFunction",