Skip to content

Commit

Permalink
Fix: fix context in provider (kubevela#194)
Browse files Browse the repository at this point in the history
fix: fix context in provider

Signed-off-by: FogDong <[email protected]>
  • Loading branch information
FogDong committed Sep 24, 2024
1 parent 94c9275 commit 952ac74
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
17 changes: 9 additions & 8 deletions pkg/executor/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
}
return v1alpha1.WorkflowStateFailed, nil
}
if checkWorkflowSuspended(status) {
return v1alpha1.WorkflowStateSuspending, nil
}
if allRunnersSucceeded {
return v1alpha1.WorkflowStateSucceeded, nil
}

wfCtx, err := w.makeContext(ctx, w.instance.Name)
if err != nil {
Expand All @@ -127,6 +121,13 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
}
w.wfCtx = wfCtx

if checkWorkflowSuspended(status) {
return v1alpha1.WorkflowStateSuspending, nil
}
if allRunnersSucceeded {
return v1alpha1.WorkflowStateSucceeded, nil
}

if cacheValue, ok := StepStatusCache.Load(cacheKey); ok {
// handle cache resource
if len(status.Steps) < cacheValue.(int) {
Expand Down Expand Up @@ -173,11 +174,11 @@ func checkWorkflowSuspended(status *v1alpha1.WorkflowRunStatus) bool {
// if workflow is suspended and the suspended step is still running, return false to run the suspended step
if status.Suspend {
for _, step := range status.Steps {
if step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
if step.Reason == types.StatusReasonSuspend && step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
return false
}
for _, sub := range step.SubStepsStatus {
if sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
if sub.Reason == types.StatusReasonSuspend && sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/http/http.cue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// +usgae=The tls config of the request
tls_config?: {
secret: string
namespace: context.namespace
namespace?: string
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

cuexruntime "github.com/kubevela/pkg/cue/cuex/runtime"

"github.com/kubevela/workflow/pkg/cue/model"
"github.com/kubevela/workflow/pkg/providers/legacy/http/ratelimiter"
providertypes "github.com/kubevela/workflow/pkg/providers/types"
)
Expand Down Expand Up @@ -145,6 +146,9 @@ func runHTTP(ctx context.Context, params *DoParams) (*DoReturns, error) {
req.Trailer = trailer

if params.Params.TLSConfig != nil {
if params.Params.TLSConfig.Namespace == "" {
params.Params.TLSConfig.Namespace = fmt.Sprint(params.ProcessContext.GetData(model.ContextNamespace))
}
if tr, err := getTransport(ctx, params.KubeClient, params.Params.TLSConfig.Secret, params.Params.TLSConfig.Namespace); err == nil && tr != nil {
defaultClient.Transport = tr
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/legacy/http/http.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// +usgae=The tls config of the request
tls_config?: {
secret: string
namespace: context.namespace
namespace?: string
}
// +usage=The response of the request will be filled in this field after the action is executed
response: {
Expand Down
6 changes: 5 additions & 1 deletion pkg/providers/legacy/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

cuexruntime "github.com/kubevela/pkg/cue/cuex/runtime"

"github.com/kubevela/workflow/pkg/cue/model"
"github.com/kubevela/workflow/pkg/providers/legacy/http/ratelimiter"
providertypes "github.com/kubevela/workflow/pkg/providers/types"
)
Expand Down Expand Up @@ -69,7 +70,7 @@ type RateLimiter struct {
// TLSConfig .
type TLSConfig struct {
Secret string `json:"secret"`
Namespace string `json:"namespace"`
Namespace string `json:"namespace,omitempty"`
}

// RequestVars is the vars for http request
Expand Down Expand Up @@ -142,6 +143,9 @@ func runHTTP(ctx context.Context, params *DoParams) (*ResponseVars, error) {
req.Trailer = trailer

if params.Params.TLSConfig != nil {
if params.Params.TLSConfig.Namespace == "" {
params.Params.TLSConfig.Namespace = fmt.Sprint(params.ProcessContext.GetData(model.ContextNamespace))
}
if tr, err := getTransport(ctx, params.KubeClient, params.Params.TLSConfig.Secret, params.Params.TLSConfig.Namespace); err == nil && tr != nil {
defaultClient.Transport = tr
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/custom/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (exec *executor) Terminate(message string) {
// Wait let workflow wait.
func (exec *executor) Wait(message string) {
exec.wait = true
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed {
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed && exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseSuspending {
exec.wfStatus.Phase = v1alpha1.WorkflowStepPhaseRunning
exec.wfStatus.Reason = types.StatusReasonWait
if message != "" {
Expand Down

0 comments on commit 952ac74

Please sign in to comment.