Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix suspend judgement #196

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
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 @@
}
w.wfCtx = wfCtx

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

Check warning on line 125 in pkg/executor/workflow.go

View check run for this annotation

Codecov / codecov/patch

pkg/executor/workflow.go#L125

Added line #L125 was not covered by tests
}
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 @@
// 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
36 changes: 20 additions & 16 deletions pkg/executor/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1772,10 +1772,11 @@ var _ = Describe("Test Workflow", func() {
},
}, {
StepStatus: v1alpha1.StepStatus{
Name: "s2",
ID: "s2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: "s2",
ID: "s2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
},
}},
})).Should(BeEquivalentTo(""))
Expand Down Expand Up @@ -1805,10 +1806,11 @@ var _ = Describe("Test Workflow", func() {
},
}, {
StepStatus: v1alpha1.StepStatus{
Name: "s2",
ID: "s2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
Name: "s2",
ID: "s2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
},
}, {
StepStatus: v1alpha1.StepStatus{
Expand Down Expand Up @@ -1884,10 +1886,11 @@ var _ = Describe("Test Workflow", func() {
Type: "success",
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
}, {
Name: "s2-sub2",
ID: "s2-sub2",
Type: "suspend",
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: "s2-sub2",
ID: "s2-sub2",
Type: "suspend",
Reason: types.StatusReasonSuspend,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
},
},
}},
Expand Down Expand Up @@ -2234,10 +2237,11 @@ func makeRunner(step v1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner) t
}
}
return v1alpha1.StepStatus{
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Name: step.Name,
Type: "suspend",
ID: step.Name,
Phase: v1alpha1.WorkflowStepPhaseSuspending,
Reason: types.StatusReasonSuspend,
}, &types.Operation{
Suspend: true,
}, nil
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 @@

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 @@
req.Trailer = trailer

if params.Params.TLSConfig != nil {
if params.Params.TLSConfig.Namespace == "" {
params.Params.TLSConfig.Namespace = fmt.Sprint(params.ProcessContext.GetData(model.ContextNamespace))

Check warning on line 150 in pkg/providers/http/http.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/http/http.go#L150

Added line #L150 was not covered by tests
}
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 @@

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 @@
// 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 @@
req.Trailer = trailer

if params.Params.TLSConfig != nil {
if params.Params.TLSConfig.Namespace == "" {
params.Params.TLSConfig.Namespace = fmt.Sprint(params.ProcessContext.GetData(model.ContextNamespace))

Check warning on line 147 in pkg/providers/legacy/http/http.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/legacy/http/http.go#L147

Added line #L147 was not covered by tests
}
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
Loading