From e16793d48e182abb31a59787556ead5cfa18ef93 Mon Sep 17 00:00:00 2001 From: binnn6 <734819342@qq.com> Date: Thu, 16 Nov 2023 20:36:02 +0800 Subject: [PATCH 1/2] fix context logic Signed-off-by: binnn6 <734819342@qq.com> --- context/context.go | 30 ++++++++++++++++++++++++++++-- runtime/runtime.go | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/context/context.go b/context/context.go index 2c2d7f1..21f7030 100644 --- a/context/context.go +++ b/context/context.go @@ -752,8 +752,34 @@ func hasPlugin(plugins []string, target string) bool { func GetRuntimeContext() (RuntimeContext, error) { if ctx, err := parseContext(); err != nil { return nil, err - } else { - return ctx, nil + } + return ctx, nil +} + +func CloneRuntimeContext(ctx RuntimeContext) RuntimeContext { + return &FunctionContext{ + + Name: ctx.GetName(), + Version: ctx.GetContext().Version, + Inputs: ctx.GetInputs(), + Outputs: ctx.GetOutputs(), + + Runtime: ctx.GetRuntime(), + Port: ctx.GetPort(), + State: ctx.GetContext().State, + + PrePlugins: ctx.GetPrePlugins(), + PostPlugins: ctx.GetPostPlugins(), + PluginsTracing: ctx.GetContext().PluginsTracing, + HttpPattern: ctx.GetHttpPattern(), + + Event: &EventRequest{}, + SyncRequest: &SyncRequest{}, + mode: ctx.GetMode(), + podName: ctx.GetPodName(), + podNamespace: ctx.GetPodNamespace(), + options: ctx.GetContext().options, + daprClient: ctx.GetContext().daprClient, } } diff --git a/runtime/runtime.go b/runtime/runtime.go index 89332d5..c0d6dcf 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -49,7 +49,7 @@ type RuntimeManager struct { } func NewRuntimeManager(funcContext ofctx.RuntimeContext, prePlugin []plugin.Plugin, postPlugin []plugin.Plugin) *RuntimeManager { - ctx := funcContext + ctx := ofctx.CloneRuntimeContext(funcContext) rm := &RuntimeManager{ FuncContext: ctx, prePlugins: prePlugin, From 830635ba6add5d04b8f09e39b5b3ad45009579a2 Mon Sep 17 00:00:00 2001 From: binnn6 <734819342@qq.com> Date: Thu, 16 Nov 2023 22:08:20 +0800 Subject: [PATCH 2/2] fix context logic Signed-off-by: binnn6 <734819342@qq.com> --- context/context.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 21f7030..a486410 100644 --- a/context/context.go +++ b/context/context.go @@ -750,7 +750,8 @@ func hasPlugin(plugins []string, target string) bool { } func GetRuntimeContext() (RuntimeContext, error) { - if ctx, err := parseContext(); err != nil { + ctx, err := parseContext() + if err != nil { return nil, err } return ctx, nil