From 2ac8bfa685fb25c582d68cf66385218e1987f5b4 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 7 Oct 2024 16:45:31 +0300 Subject: [PATCH] fix: refactor running context model Signed-off-by: Vladislav Sukhin --- .../v1/testworkflowexecution_types.go | 73 +++++++++-------- api/testworkflows/v1/zz_generated.deepcopy.go | 82 +++++++++++++++---- .../testworkflowexecution_controller.go | 16 ++-- .../testworkflows/testworkflow_controller.go | 12 ++- 4 files changed, 119 insertions(+), 64 deletions(-) diff --git a/api/testworkflows/v1/testworkflowexecution_types.go b/api/testworkflows/v1/testworkflowexecution_types.go index 217e66f6..c8e00c07 100644 --- a/api/testworkflows/v1/testworkflowexecution_types.go +++ b/api/testworkflows/v1/testworkflowexecution_types.go @@ -93,55 +93,56 @@ type TestWorkflowExecutionDetails struct { type TestWorkflowRunningContext struct { Interface_ *TestWorkflowRunningContextInterface `json:"interface"` Actor *TestWorkflowRunningContextActor `json:"actor"` - Caller *TestWorkflowRunningContextCaller `json:"caller,omitempty"` } -// TestWorkflowRunningContextActor : supported actors for test workflow running context -// +kubebuilder:validation:Enum=cron;testrigger;user;testworkflow;testworkflowexecution -type TestWorkflowRunningContextActor string +// TestWorkflowRunningContextActorType : supported actors for test workflow running context +// +kubebuilder:validation:Enum=cron;testrigger;user;testworkflow;testworkflowexecution;program +type TestWorkflowRunningContextActorType string -// List of TestWorkflowRunningContextActor +// List of TestWorkflowRunningContextActorType const ( - CRON_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "cron" - TESTRIGGER_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "testrigger" - USER_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "user" - TESTWORKFLOW_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "testworkflow" - TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "testworkflowexecution" + CRON_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "cron" + TESTRIGGER_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "testrigger" + USER_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "user" + TESTWORKFLOW_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "testworkflow" + TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "testworkflowexecution" + PROGRAM_TestWorkflowRunningContextActorType TestWorkflowRunningContextActorType = "program" ) -// running context caller for test workflow execution -type TestWorkflowRunningContextCaller struct { - CallerResourceType *TestWorkflowRunningContextCallerResourceType `json:"callerResourceType"` - // caller resource name - CallerResourceName string `json:"callerResourceName"` - // caller resource execution id - CallerResourceExecutionID string `json:"callerResourceExecutionID,omitempty"` +// running context actor for test workflow execution +type TestWorkflowRunningContextActor struct { + // actor name + Name string `json:"name,omitempty"` + // actor username + Username string `json:"username,omitempty"` + // actor email + Email string `json:"email,omitempty"` + // test workflow execution id + ExecutionId string `json:"executionId,omitempty"` // all test workflow execution ids starting from the root - FullExecutionPath string `json:"fullExecutionPath,omitempty"` + ExecutionPath string `json:"executionPath,omitempty"` + Type_ *TestWorkflowRunningContextActorType `json:"type"` } -// TestWorkflowRunningContextCallerResourceType : supported caller resource types for test workflow running context -// +kubebuilder:validation:Enum=testworkflow;testworkflowexecution;testrigger -type TestWorkflowRunningContextCallerResourceType string +// TestWorkflowRunningContextInterfaceType : supported interfaces for test workflow running context +// +kubebuilder:validation:Enum=cli;ui;api;ci/cd;internal +type TestWorkflowRunningContextInterfaceType string -// List of TestWorkflowRunningContextCallerResourceType +// List of TestWorkflowRunningContextInterfaceType const ( - TESTWORKFLOW_TestWorkflowRunningContextCallerResourceType TestWorkflowRunningContextCallerResourceType = "testworkflow" - TESTWORKFLOWEXECUTION_TestWorkflowRunningContextCallerResourceType TestWorkflowRunningContextCallerResourceType = "testworkflowexecution" - TESTTRIGGER_TestWorkflowRunningContextCallerResourceType TestWorkflowRunningContextCallerResourceType = "testtrigger" + CLI_TestWorkflowRunningContextInterfaceType TestWorkflowRunningContextInterfaceType = "cli" + UI_TestWorkflowRunningContextInterfaceType TestWorkflowRunningContextInterfaceType = "ui" + API_TestWorkflowRunningContextInterfaceType TestWorkflowRunningContextInterfaceType = "api" + CICD_TestWorkflowRunningContextInterfaceType TestWorkflowRunningContextInterfaceType = "ci/cd" + INTERNAL_TestWorkflowRunningContextInterfaceType TestWorkflowRunningContextInterfaceType = "internal" ) -// TestWorkflowRunningContextInterface : supported interfaces for test workflow running context -// +kubebuilder:validation:Enum=cli;ui;api;internal -type TestWorkflowRunningContextInterface string - -// List of TestWorkflowRunningContextInterface -const ( - CLI_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "cli" - UI_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "ui" - API_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "api" - INTERNAL_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "internal" -) +// running context interface for test workflow execution +type TestWorkflowRunningContextInterface struct { + // interface name + Name string `json:"name,omitempty"` + Type_ *TestWorkflowRunningContextInterfaceType `json:"type"` +} // TestWorkflowSignature has signature of TestWorkflow type TestWorkflowSignature struct { diff --git a/api/testworkflows/v1/zz_generated.deepcopy.go b/api/testworkflows/v1/zz_generated.deepcopy.go index d88488d5..744a9832 100644 --- a/api/testworkflows/v1/zz_generated.deepcopy.go +++ b/api/testworkflows/v1/zz_generated.deepcopy.go @@ -321,7 +321,7 @@ func (in *IndependentServiceSpec) DeepCopy() *IndependentServiceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IndependentStep) DeepCopyInto(out *IndependentStep) { *out = *in - out.StepMeta = in.StepMeta + in.StepMeta.DeepCopyInto(&out.StepMeta) in.StepControl.DeepCopyInto(&out.StepControl) in.StepSource.DeepCopyInto(&out.StepSource) if in.Services != nil { @@ -729,7 +729,7 @@ func (in *ServiceSpec) DeepCopy() *ServiceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Step) DeepCopyInto(out *Step) { *out = *in - out.StepMeta = in.StepMeta + in.StepMeta.DeepCopyInto(&out.StepMeta) in.StepControl.DeepCopyInto(&out.StepControl) if in.Use != nil { in, out := &in.Use, &out.Use @@ -988,6 +988,11 @@ func (in *StepExecuteWorkflow) DeepCopy() *StepExecuteWorkflow { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StepMeta) DeepCopyInto(out *StepMeta) { *out = *in + if in.Pure != nil { + in, out := &in.Pure, &out.Pure + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StepMeta. @@ -1365,7 +1370,7 @@ func (in *TestWorkflowExecutionDetails) DeepCopyInto(out *TestWorkflowExecutionD for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } - } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestWorkflowExecutionDetails. @@ -1719,16 +1724,11 @@ func (in *TestWorkflowRunningContext) DeepCopyInto(out *TestWorkflowRunningConte if in.Interface_ != nil { in, out := &in.Interface_, &out.Interface_ *out = new(TestWorkflowRunningContextInterface) - **out = **in + (*in).DeepCopyInto(*out) } if in.Actor != nil { in, out := &in.Actor, &out.Actor *out = new(TestWorkflowRunningContextActor) - **out = **in - } - if in.Caller != nil { - in, out := &in.Caller, &out.Caller - *out = new(TestWorkflowRunningContextCaller) (*in).DeepCopyInto(*out) } } @@ -1744,21 +1744,41 @@ func (in *TestWorkflowRunningContext) DeepCopy() *TestWorkflowRunningContext { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TestWorkflowRunningContextCaller) DeepCopyInto(out *TestWorkflowRunningContextCaller) { +func (in *TestWorkflowRunningContextActor) DeepCopyInto(out *TestWorkflowRunningContextActor) { + *out = *in + if in.Type_ != nil { + in, out := &in.Type_, &out.Type_ + *out = new(TestWorkflowRunningContextActorType) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestWorkflowRunningContextActor. +func (in *TestWorkflowRunningContextActor) DeepCopy() *TestWorkflowRunningContextActor { + if in == nil { + return nil + } + out := new(TestWorkflowRunningContextActor) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestWorkflowRunningContextInterface) DeepCopyInto(out *TestWorkflowRunningContextInterface) { *out = *in - if in.CallerResourceType != nil { - in, out := &in.CallerResourceType, &out.CallerResourceType - *out = new(TestWorkflowRunningContextCallerResourceType) + if in.Type_ != nil { + in, out := &in.Type_, &out.Type_ + *out = new(TestWorkflowRunningContextInterfaceType) **out = **in } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestWorkflowRunningContextCaller. -func (in *TestWorkflowRunningContextCaller) DeepCopy() *TestWorkflowRunningContextCaller { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestWorkflowRunningContextInterface. +func (in *TestWorkflowRunningContextInterface) DeepCopy() *TestWorkflowRunningContextInterface { if in == nil { return nil } - out := new(TestWorkflowRunningContextCaller) + out := new(TestWorkflowRunningContextInterface) in.DeepCopyInto(out) return out } @@ -1846,6 +1866,11 @@ func (in *TestWorkflowSpecBase) DeepCopyInto(out *TestWorkflowSpecBase) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.System != nil { + in, out := &in.System, &out.System + *out = new(TestWorkflowSystem) + (*in).DeepCopyInto(*out) + } if in.Config != nil { in, out := &in.Config, &out.Config *out = make(map[string]ParameterSchema, len(*in)) @@ -1967,6 +1992,31 @@ func (in *TestWorkflowSummary) DeepCopy() *TestWorkflowSummary { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestWorkflowSystem) DeepCopyInto(out *TestWorkflowSystem) { + *out = *in + if in.PureByDefault != nil { + in, out := &in.PureByDefault, &out.PureByDefault + *out = new(bool) + **out = **in + } + if in.IsolatedContainers != nil { + in, out := &in.IsolatedContainers, &out.IsolatedContainers + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestWorkflowSystem. +func (in *TestWorkflowSystem) DeepCopy() *TestWorkflowSystem { + if in == nil { + return nil + } + out := new(TestWorkflowSystem) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TestWorkflowTagSchema) DeepCopyInto(out *TestWorkflowTagSchema) { *out = *in diff --git a/internal/controller/testworkflowexecution/testworkflowexecution_controller.go b/internal/controller/testworkflowexecution/testworkflowexecution_controller.go index c5ae2a52..dcad97fe 100644 --- a/internal/controller/testworkflowexecution/testworkflowexecution_controller.go +++ b/internal/controller/testworkflowexecution/testworkflowexecution_controller.go @@ -76,16 +76,16 @@ func (r *TestWorkflowExecutionReconciler) Reconcile(ctx context.Context, req ctr testWorkflowExecution.Spec.ExecutionRequest = &testworkflowsv1.TestWorkflowExecutionRequest{} } - interface_ := testworkflowsv1.API_TestWorkflowRunningContextInterface - actor := testworkflowsv1.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActor - callerResourceType := testworkflowsv1.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextCallerResourceType + interface_ := testworkflowsv1.API_TestWorkflowRunningContextInterfaceType + actor := testworkflowsv1.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActorType testWorkflowExecution.Spec.ExecutionRequest.RunningContext = []testworkflowsv1.TestWorkflowRunningContext{ { - Interface_: &interface_, - Actor: &actor, - Caller: &testworkflowsv1.TestWorkflowRunningContextCaller{ - CallerResourceType: &callerResourceType, - CallerResourceName: testWorkflowExecution.Name, + Interface_: &testworkflowsv1.TestWorkflowRunningContextInterface{ + Type_: &interface_, + }, + Actor: &testworkflowsv1.TestWorkflowRunningContextActor{ + Name: testWorkflowExecution.Name, + Type_: &actor, }, }, } diff --git a/internal/controller/testworkflows/testworkflow_controller.go b/internal/controller/testworkflows/testworkflow_controller.go index 8999d72b..fd990b46 100644 --- a/internal/controller/testworkflows/testworkflow_controller.go +++ b/internal/controller/testworkflows/testworkflow_controller.go @@ -136,13 +136,17 @@ func (r *TestWorkflowReconciler) Reconcile(ctx context.Context, req ctrl.Request } } - interface_ := testworkflowsv1.API_TestWorkflowRunningContextInterface - actor := testworkflowsv1.CRON_TestWorkflowRunningContextActor + interface_ := testworkflowsv1.API_TestWorkflowRunningContextInterfaceType + actor := testworkflowsv1.CRON_TestWorkflowRunningContextActorType data, err := json.Marshal(testworkflowsv1.TestWorkflowExecutionRequest{ RunningContext: []testworkflowsv1.TestWorkflowRunningContext{ { - Interface_: &interface_, - Actor: &actor, + Interface_: &testworkflowsv1.TestWorkflowRunningContextInterface{ + Type_: &interface_, + }, + Actor: &testworkflowsv1.TestWorkflowRunningContextActor{ + Type_: &actor, + }, }, }, })