From f1f89a92aa01646594426e9a79db0c6833d30eba Mon Sep 17 00:00:00 2001 From: Jakub Buczak Date: Fri, 11 Oct 2024 12:07:50 +0200 Subject: [PATCH] perf: Remove default template store implementation Pass created client stores in tests Signed-off-by: Jakub Buczak --- server/cronworkflow/cron_workflow_server.go | 8 -------- server/cronworkflow/cron_workflow_server_test.go | 6 +++++- server/workflow/workflow_server.go | 8 -------- server/workflow/workflow_server_test.go | 6 +++++- server/workflowtemplate/workflow_template_server_test.go | 5 ++++- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/server/cronworkflow/cron_workflow_server.go b/server/cronworkflow/cron_workflow_server.go index 3c40cfea91fa..28a3c203e65a 100644 --- a/server/cronworkflow/cron_workflow_server.go +++ b/server/cronworkflow/cron_workflow_server.go @@ -12,9 +12,7 @@ import ( cronworkflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/cronworkflow" "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/argoproj/argo-workflows/v3/server/auth" - "github.com/argoproj/argo-workflows/v3/server/clusterworkflowtemplate" servertypes "github.com/argoproj/argo-workflows/v3/server/types" - "github.com/argoproj/argo-workflows/v3/server/workflowtemplate" "github.com/argoproj/argo-workflows/v3/util/instanceid" "github.com/argoproj/argo-workflows/v3/workflow/creator" "github.com/argoproj/argo-workflows/v3/workflow/validate" @@ -30,12 +28,6 @@ type cronWorkflowServiceServer struct { // NewCronWorkflowServer returns a new cronWorkflowServiceServer func NewCronWorkflowServer(instanceIDService instanceid.Service, wftmplStore servertypes.WorkflowTemplateStore, cwftmplStore servertypes.ClusterWorkflowTemplateStore) cronworkflowpkg.CronWorkflowServiceServer { - if wftmplStore == nil { - wftmplStore = workflowtemplate.NewWorkflowTemplateClientStore() - } - if cwftmplStore == nil { - cwftmplStore = clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore() - } return &cronWorkflowServiceServer{instanceIDService, wftmplStore, cwftmplStore} } diff --git a/server/cronworkflow/cron_workflow_server_test.go b/server/cronworkflow/cron_workflow_server_test.go index a9b7e75e790f..7a8abcc1632d 100644 --- a/server/cronworkflow/cron_workflow_server_test.go +++ b/server/cronworkflow/cron_workflow_server_test.go @@ -13,6 +13,8 @@ import ( wftFake "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/fake" "github.com/argoproj/argo-workflows/v3/server/auth" "github.com/argoproj/argo-workflows/v3/server/auth/types" + "github.com/argoproj/argo-workflows/v3/server/clusterworkflowtemplate" + "github.com/argoproj/argo-workflows/v3/server/workflowtemplate" "github.com/argoproj/argo-workflows/v3/util/instanceid" "github.com/argoproj/argo-workflows/v3/workflow/common" ) @@ -52,7 +54,9 @@ metadata: `, &unlabelled) wfClientset := wftFake.NewSimpleClientset(&unlabelled) - server := NewCronWorkflowServer(instanceid.NewService("my-instanceid"), nil, nil) + wftmplStore := workflowtemplate.NewWorkflowTemplateClientStore() + cwftmplStore := clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore() + server := NewCronWorkflowServer(instanceid.NewService("my-instanceid"), wftmplStore, cwftmplStore) ctx := context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}}) t.Run("CreateCronWorkflow", func(t *testing.T) { diff --git a/server/workflow/workflow_server.go b/server/workflow/workflow_server.go index d89f63b30dda..0a10d9672ddc 100644 --- a/server/workflow/workflow_server.go +++ b/server/workflow/workflow_server.go @@ -28,11 +28,9 @@ import ( wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned" "github.com/argoproj/argo-workflows/v3/server/auth" - "github.com/argoproj/argo-workflows/v3/server/clusterworkflowtemplate" servertypes "github.com/argoproj/argo-workflows/v3/server/types" sutils "github.com/argoproj/argo-workflows/v3/server/utils" "github.com/argoproj/argo-workflows/v3/server/workflow/store" - "github.com/argoproj/argo-workflows/v3/server/workflowtemplate" argoutil "github.com/argoproj/argo-workflows/v3/util" "github.com/argoproj/argo-workflows/v3/util/fields" "github.com/argoproj/argo-workflows/v3/util/instanceid" @@ -65,12 +63,6 @@ var _ workflowpkg.WorkflowServiceServer = &workflowServer{} // NewWorkflowServer returns a new WorkflowServer func NewWorkflowServer(instanceIDService instanceid.Service, offloadNodeStatusRepo sqldb.OffloadNodeStatusRepo, wfArchive sqldb.WorkflowArchive, wfClientSet versioned.Interface, wfLister store.WorkflowLister, wfStore store.WorkflowStore, wftmplStore servertypes.WorkflowTemplateStore, cwftmplStore servertypes.ClusterWorkflowTemplateStore, namespace *string) *workflowServer { - if wftmplStore == nil { - wftmplStore = workflowtemplate.NewWorkflowTemplateClientStore() - } - if cwftmplStore == nil { - cwftmplStore = clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore() - } ws := &workflowServer{ instanceIDService: instanceIDService, offloadNodeStatusRepo: offloadNodeStatusRepo, diff --git a/server/workflow/workflow_server_test.go b/server/workflow/workflow_server_test.go index 997c886e6634..2469cd09dc36 100644 --- a/server/workflow/workflow_server_test.go +++ b/server/workflow/workflow_server_test.go @@ -27,8 +27,10 @@ import ( v1alpha "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/fake" "github.com/argoproj/argo-workflows/v3/server/auth" "github.com/argoproj/argo-workflows/v3/server/auth/types" + "github.com/argoproj/argo-workflows/v3/server/clusterworkflowtemplate" sutils "github.com/argoproj/argo-workflows/v3/server/utils" "github.com/argoproj/argo-workflows/v3/server/workflow/store" + "github.com/argoproj/argo-workflows/v3/server/workflowtemplate" "github.com/argoproj/argo-workflows/v3/util" "github.com/argoproj/argo-workflows/v3/util/instanceid" "github.com/argoproj/argo-workflows/v3/workflow/common" @@ -640,7 +642,9 @@ func getWorkflowServer() (workflowpkg.WorkflowServiceServer, context.Context) { panic(err) } namespaceAll := metav1.NamespaceAll - server := NewWorkflowServer(instanceIdSvc, offloadNodeStatusRepo, archivedRepo, wfClientset, wfStore, wfStore, nil, nil, &namespaceAll) + wftmplStore := workflowtemplate.NewWorkflowTemplateClientStore() + cwftmplStore := clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore() + server := NewWorkflowServer(instanceIdSvc, offloadNodeStatusRepo, archivedRepo, wfClientset, wfStore, wfStore, wftmplStore, cwftmplStore, &namespaceAll) return server, ctx } diff --git a/server/workflowtemplate/workflow_template_server_test.go b/server/workflowtemplate/workflow_template_server_test.go index ca466320b487..1c14d2ba06c2 100644 --- a/server/workflowtemplate/workflow_template_server_test.go +++ b/server/workflowtemplate/workflow_template_server_test.go @@ -15,6 +15,7 @@ import ( wftFake "github.com/argoproj/argo-workflows/v3/pkg/client/clientset/versioned/fake" "github.com/argoproj/argo-workflows/v3/server/auth" "github.com/argoproj/argo-workflows/v3/server/auth/types" + "github.com/argoproj/argo-workflows/v3/server/clusterworkflowtemplate" "github.com/argoproj/argo-workflows/v3/util/instanceid" "github.com/argoproj/argo-workflows/v3/workflow/common" ) @@ -169,7 +170,9 @@ func getWorkflowTemplateServer() (workflowtemplatepkg.WorkflowTemplateServiceSer kubeClientSet := fake.NewSimpleClientset() wfClientset := wftFake.NewSimpleClientset(&unlabelledObj, &wftObj1, &wftObj2) ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}}) - return NewWorkflowTemplateServer(instanceid.NewService("my-instanceid"), nil, nil), ctx + wftmplStore := NewWorkflowTemplateClientStore() + cwftmplStore := clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore() + return NewWorkflowTemplateServer(instanceid.NewService("my-instanceid"), wftmplStore, cwftmplStore), ctx } func TestWorkflowTemplateServer_CreateWorkflowTemplate(t *testing.T) {