Skip to content

Commit

Permalink
perf: Remove default template store implementation
Browse files Browse the repository at this point in the history
Pass created client stores in tests

Signed-off-by: Jakub Buczak <jbuczak@splunk.com>
  • Loading branch information
jakkubu committed Oct 11, 2024
1 parent 062d964 commit f1f89a9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
8 changes: 0 additions & 8 deletions server/cronworkflow/cron_workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}
}

Expand Down
6 changes: 5 additions & 1 deletion server/cronworkflow/cron_workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions server/workflow/workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion server/workflow/workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion server/workflowtemplate/workflow_template_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f1f89a9

Please sign in to comment.