From bca032d481eddfb1c3afe40ab874d16ef09fb70e Mon Sep 17 00:00:00 2001 From: Tianxin Dong Date: Wed, 30 Nov 2022 17:19:52 +0800 Subject: [PATCH] Fix: fix the usage of http client and run crd (#93) Signed-off-by: FogDong Signed-off-by: FogDong --- api/v1alpha1/types.go | 4 ++-- api/v1alpha1/zz_generated.deepcopy.go | 10 +++++----- .../crds/core.oam.dev_workflowruns.yaml | 11 ----------- controllers/workflow_test.go | 6 +++--- pkg/providers/http/do.go | 17 +++++------------ 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/api/v1alpha1/types.go b/api/v1alpha1/types.go index 78334ac..10d0de8 100644 --- a/api/v1alpha1/types.go +++ b/api/v1alpha1/types.go @@ -101,8 +101,7 @@ type WorkflowRunStatus struct { // WorkflowSpec defines workflow steps and other attributes type WorkflowSpec struct { - Mode *WorkflowExecuteMode `json:"mode,omitempty"` - Steps []WorkflowStep `json:"steps,omitempty"` + Steps []WorkflowStep `json:"steps,omitempty"` } // WorkflowExecuteMode defines the mode of workflow execution @@ -144,6 +143,7 @@ type Workflow struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` + Mode *WorkflowExecuteMode `json:"mode,omitempty"` WorkflowSpec `json:",inline"` } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 37798d9..6203edf 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -86,6 +86,11 @@ func (in *Workflow) DeepCopyInto(out *Workflow) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.Mode != nil { + in, out := &in.Mode, &out.Mode + *out = new(WorkflowExecuteMode) + **out = **in + } in.WorkflowSpec.DeepCopyInto(&out.WorkflowSpec) } @@ -277,11 +282,6 @@ func (in *WorkflowRunStatus) DeepCopy() *WorkflowRunStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WorkflowSpec) DeepCopyInto(out *WorkflowSpec) { *out = *in - if in.Mode != nil { - in, out := &in.Mode, &out.Mode - *out = new(WorkflowExecuteMode) - **out = **in - } if in.Steps != nil { in, out := &in.Steps, &out.Steps *out = make([]WorkflowStep, len(*in)) diff --git a/charts/vela-workflow/crds/core.oam.dev_workflowruns.yaml b/charts/vela-workflow/crds/core.oam.dev_workflowruns.yaml index b8fc45b..c7fe382 100644 --- a/charts/vela-workflow/crds/core.oam.dev_workflowruns.yaml +++ b/charts/vela-workflow/crds/core.oam.dev_workflowruns.yaml @@ -64,17 +64,6 @@ spec: workflowSpec: description: WorkflowSpec defines workflow steps and other attributes properties: - mode: - description: WorkflowExecuteMode defines the mode of workflow - execution - properties: - steps: - description: Steps is the mode of workflow steps execution - type: string - subSteps: - description: SubSteps is the mode of workflow sub steps execution - type: string - type: object steps: items: description: WorkflowStep defines how to execute a workflow diff --git a/controllers/workflow_test.go b/controllers/workflow_test.go index 536eecb..86c9891 100644 --- a/controllers/workflow_test.go +++ b/controllers/workflow_test.go @@ -96,10 +96,10 @@ var _ = Describe("Test Workflow", func() { Name: "workflow", Namespace: namespace, }, + Mode: &v1alpha1.WorkflowExecuteMode{ + Steps: v1alpha1.WorkflowModeDAG, + }, WorkflowSpec: v1alpha1.WorkflowSpec{ - Mode: &v1alpha1.WorkflowExecuteMode{ - Steps: v1alpha1.WorkflowModeDAG, - }, Steps: []v1alpha1.WorkflowStep{ { WorkflowStepBase: v1alpha1.WorkflowStepBase{ diff --git a/pkg/providers/http/do.go b/pkg/providers/http/do.go index 12ae0ab..50b544a 100644 --- a/pkg/providers/http/do.go +++ b/pkg/providers/http/do.go @@ -46,16 +46,11 @@ const ( ) var ( - defaultClient *http.Client - rateLimiter *ratelimiter.RateLimiter + rateLimiter *ratelimiter.RateLimiter ) func init() { rateLimiter = ratelimiter.NewRateLimiter(128) - defaultClient = &http.Client{ - Transport: http.DefaultTransport, - Timeout: time.Second * 3, - } } type provider struct { @@ -79,7 +74,10 @@ func (h *provider) runHTTP(ctx monitorContext.Context, v *value.Value) (interfac header, trailer http.Header r io.Reader ) - initDefaultClient(defaultClient) + defaultClient := &http.Client{ + Transport: http.DefaultTransport, + Timeout: time.Second * 3, + } if timeout, err := v.GetString("request", "timeout"); err == nil && timeout != "" { duration, err := time.ParseDuration(timeout) if err != nil { @@ -212,11 +210,6 @@ func (h *provider) getTransport(ctx monitorContext.Context, v *value.Value) (htt return tr, nil } -func initDefaultClient(c *http.Client) { - c.Transport = http.DefaultTransport - c.Timeout = time.Second * 3 -} - func parseHeaders(obj cue.Value, label string) (http.Header, error) { m := obj.LookupPath(value.FieldPath("request", label)) if !m.Exists() {