From 515d6606093611604045f88320ed476d236c3222 Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Mon, 22 May 2023 11:26:01 -0400 Subject: [PATCH] feat: Support GetWorkflow regardless of its archival status (#11055) --- api/openapi-spec/swagger.json | 5 + persist/sqldb/mocks/WorkflowArchive.go | 18 +-- persist/sqldb/null_workflow_archive.go | 2 +- persist/sqldb/workflow_archive.go | 48 +++++- pkg/apiclient/argo-kube-client.go | 5 +- .../workflowarchive/workflow-archive.pb.go | 153 ++++++++++++------ .../workflowarchive/workflow-archive.proto | 1 + .../client/docs/ArchivedWorkflowServiceApi.md | 6 +- .../api/archived_workflow_service_api.py | 6 + .../client/docs/ArchivedWorkflowServiceApi.md | 4 +- server/apiserver/argoserver.go | 6 +- server/artifacts/artifact_server.go | 4 +- server/artifacts/artifact_server_test.go | 2 +- server/workflow/workflow_server.go | 19 ++- server/workflow/workflow_server_test.go | 26 ++- .../archived_workflow_server.go | 2 +- .../archived_workflow_server_test.go | 21 ++- 17 files changed, 236 insertions(+), 92 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 117fb9fe21fd..ad3ce538af07 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -238,6 +238,11 @@ "type": "string", "name": "namespace", "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" } ], "responses": { diff --git a/persist/sqldb/mocks/WorkflowArchive.go b/persist/sqldb/mocks/WorkflowArchive.go index 08f43bc65ef6..16edf80c38fd 100644 --- a/persist/sqldb/mocks/WorkflowArchive.go +++ b/persist/sqldb/mocks/WorkflowArchive.go @@ -82,25 +82,25 @@ func (_m *WorkflowArchive) DeleteWorkflow(uid string) error { return r0 } -// GetWorkflow provides a mock function with given fields: uid -func (_m *WorkflowArchive) GetWorkflow(uid string) (*v1alpha1.Workflow, error) { - ret := _m.Called(uid) +// GetWorkflow provides a mock function with given fields: uid, namespace, name +func (_m *WorkflowArchive) GetWorkflow(uid string, namespace string, name string) (*v1alpha1.Workflow, error) { + ret := _m.Called(uid, namespace, name) var r0 *v1alpha1.Workflow var r1 error - if rf, ok := ret.Get(0).(func(string) (*v1alpha1.Workflow, error)); ok { - return rf(uid) + if rf, ok := ret.Get(0).(func(string, string, string) (*v1alpha1.Workflow, error)); ok { + return rf(uid, namespace, name) } - if rf, ok := ret.Get(0).(func(string) *v1alpha1.Workflow); ok { - r0 = rf(uid) + if rf, ok := ret.Get(0).(func(string, string, string) *v1alpha1.Workflow); ok { + r0 = rf(uid, namespace, name) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*v1alpha1.Workflow) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(uid) + if rf, ok := ret.Get(1).(func(string, string, string) error); ok { + r1 = rf(uid, namespace, name) } else { r1 = ret.Error(1) } diff --git a/persist/sqldb/null_workflow_archive.go b/persist/sqldb/null_workflow_archive.go index 3be1c0426afb..e8e37b481c9f 100644 --- a/persist/sqldb/null_workflow_archive.go +++ b/persist/sqldb/null_workflow_archive.go @@ -29,7 +29,7 @@ func (r *nullWorkflowArchive) CountWorkflows(string, string, string, time.Time, return 0, nil } -func (r *nullWorkflowArchive) GetWorkflow(string) (*wfv1.Workflow, error) { +func (r *nullWorkflowArchive) GetWorkflow(string, string, string) (*wfv1.Workflow, error) { return nil, fmt.Errorf("getting archived workflows not supported") } diff --git a/persist/sqldb/workflow_archive.go b/persist/sqldb/workflow_archive.go index ac7ad1d7436f..35251f1ac3fe 100644 --- a/persist/sqldb/workflow_archive.go +++ b/persist/sqldb/workflow_archive.go @@ -7,6 +7,7 @@ import ( "time" log "github.com/sirupsen/logrus" + "google.golang.org/grpc/codes" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -14,6 +15,7 @@ import ( "upper.io/db.v3/lib/sqlbuilder" wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" + sutils "github.com/argoproj/argo-workflows/v3/server/utils" "github.com/argoproj/argo-workflows/v3/util/instanceid" ) @@ -57,7 +59,7 @@ type WorkflowArchive interface { // list workflows, with the most recently started workflows at the beginning (i.e. index 0 is the most recent) ListWorkflows(namespace string, name string, namePrefix string, minStartAt, maxStartAt time.Time, labelRequirements labels.Requirements, limit, offset int) (wfv1.Workflows, error) CountWorkflows(namespace string, name string, namePrefix string, minStartAt, maxStartAt time.Time, labelRequirements labels.Requirements) (int64, error) - GetWorkflow(uid string) (*wfv1.Workflow, error) + GetWorkflow(uid string, namespace string, name string) (*wfv1.Workflow, error) DeleteWorkflow(uid string) error DeleteExpiredWorkflows(ttl time.Duration) error IsEnabled() bool @@ -257,14 +259,44 @@ func namePrefixClause(namePrefix string) db.Cond { } } -func (r *workflowArchive) GetWorkflow(uid string) (*wfv1.Workflow, error) { +func (r *workflowArchive) GetWorkflow(uid string, namespace string, name string) (*wfv1.Workflow, error) { + var err error archivedWf := &archivedWorkflowRecord{} - err := r.session. - Select("workflow"). - From(archiveTableName). - Where(r.clusterManagedNamespaceAndInstanceID()). - And(db.Cond{"uid": uid}). - One(archivedWf) + if uid != "" { + err = r.session. + Select("workflow"). + From(archiveTableName). + Where(r.clusterManagedNamespaceAndInstanceID()). + And(db.Cond{"uid": uid}). + One(archivedWf) + } else { + if name != "" && namespace != "" { + total := &archivedWorkflowCount{} + err = r.session. + Select(db.Raw("count(*) as total")). + From(archiveTableName). + Where(r.clusterManagedNamespaceAndInstanceID()). + And(namespaceEqual(namespace)). + And(nameEqual(name)). + One(total) + if err != nil { + return nil, err + } + num := int64(total.Total) + if num > 1 { + return nil, fmt.Errorf("found %d archived workflows with namespace/name: %s/%s", num, namespace, name) + } + err = r.session. + Select("workflow"). + From(archiveTableName). + Where(r.clusterManagedNamespaceAndInstanceID()). + And(namespaceEqual(namespace)). + And(nameEqual(name)). + One(archivedWf) + } else { + return nil, sutils.ToStatusError(fmt.Errorf("both name and namespace are required if uid is not specified"), codes.InvalidArgument) + } + } if err != nil { if err == db.ErrNoMoreRows { return nil, nil diff --git a/pkg/apiclient/argo-kube-client.go b/pkg/apiclient/argo-kube-client.go index 8fbbdb39fb27..f1e43b1cf4f1 100644 --- a/pkg/apiclient/argo-kube-client.go +++ b/pkg/apiclient/argo-kube-client.go @@ -23,6 +23,7 @@ import ( cronworkflowserver "github.com/argoproj/argo-workflows/v3/server/cronworkflow" "github.com/argoproj/argo-workflows/v3/server/types" workflowserver "github.com/argoproj/argo-workflows/v3/server/workflow" + "github.com/argoproj/argo-workflows/v3/server/workflowarchive" workflowtemplateserver "github.com/argoproj/argo-workflows/v3/server/workflowtemplate" "github.com/argoproj/argo-workflows/v3/util/help" "github.com/argoproj/argo-workflows/v3/util/instanceid" @@ -83,7 +84,9 @@ func newArgoKubeClient(ctx context.Context, clientConfig clientcmd.ClientConfig, } func (a *argoKubeClient) NewWorkflowServiceClient() workflowpkg.WorkflowServiceClient { - return &errorTranslatingWorkflowServiceClient{&argoKubeWorkflowServiceClient{workflowserver.NewWorkflowServer(a.instanceIDService, argoKubeOffloadNodeStatusRepo)}} + wfArchive := sqldb.NullWorkflowArchive + wfaServer := workflowarchive.NewWorkflowArchiveServer(wfArchive) + return &errorTranslatingWorkflowServiceClient{&argoKubeWorkflowServiceClient{workflowserver.NewWorkflowServer(a.instanceIDService, argoKubeOffloadNodeStatusRepo, wfaServer)}} } func (a *argoKubeClient) NewCronWorkflowServiceClient() (cronworkflow.CronWorkflowServiceClient, error) { diff --git a/pkg/apiclient/workflowarchive/workflow-archive.pb.go b/pkg/apiclient/workflowarchive/workflow-archive.pb.go index fd9678804303..8b6939b1c19f 100644 --- a/pkg/apiclient/workflowarchive/workflow-archive.pb.go +++ b/pkg/apiclient/workflowarchive/workflow-archive.pb.go @@ -95,6 +95,7 @@ func (m *ListArchivedWorkflowsRequest) GetNamespace() string { type GetArchivedWorkflowRequest struct { Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -147,6 +148,13 @@ func (m *GetArchivedWorkflowRequest) GetNamespace() string { return "" } +func (m *GetArchivedWorkflowRequest) GetName() string { + if m != nil { + return m.Name + } + return "" +} + type DeleteArchivedWorkflowRequest struct { Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"` @@ -527,57 +535,57 @@ func init() { } var fileDescriptor_95ca9a2d33e8bb19 = []byte{ - // 786 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x96, 0x4d, 0x6f, 0xe3, 0x44, - 0x18, 0xc7, 0x35, 0x7d, 0x53, 0x3b, 0x3d, 0x00, 0x83, 0x0a, 0x91, 0x95, 0xa6, 0xc1, 0x82, 0x36, - 0x6d, 0xc9, 0xb8, 0x69, 0x8b, 0x40, 0x3d, 0x01, 0xaa, 0x40, 0xa2, 0x69, 0x8b, 0x1c, 0x09, 0x24, - 0x2e, 0x68, 0x62, 0x3f, 0x4d, 0x86, 0xd8, 0x1e, 0x33, 0x33, 0x76, 0x29, 0x88, 0x0b, 0x7c, 0x04, - 0x8e, 0x9c, 0x90, 0xf8, 0x02, 0xdc, 0x10, 0x77, 0x24, 0x4e, 0x68, 0xb5, 0x7b, 0xdb, 0xc3, 0x6a, - 0x55, 0xed, 0x07, 0x59, 0xd9, 0x79, 0x6b, 0x1d, 0xe7, 0x45, 0xda, 0xf4, 0x36, 0x7e, 0x66, 0xfc, - 0x9f, 0xdf, 0x7f, 0xfc, 0xf8, 0xaf, 0xc1, 0xc7, 0x61, 0xa7, 0x65, 0xb1, 0x90, 0x3b, 0x1e, 0x87,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, 0xf0, 0xd6, 0x94, 0xc8, 0x24, 0x1f, 0xce, 0x6e, 0xeb, 0x5e, 0xc8, - 0x1a, 0xe7, 0x73, 0x32, 0xd6, 0x55, 0x35, 0xad, 0xd4, 0xda, 0x2e, 0xd9, 0x99, 0x6a, 0x2d, 0xee, - 0x82, 0xff, 0x8b, 0xf0, 0x46, 0x6e, 0xe2, 0xe6, 0xfc, 0xd0, 0x93, 0x92, 0x79, 0xae, 0xff, 0x45, - 0x2d, 0x75, 0xb1, 0x6f, 0x6c, 0x4f, 0x6b, 0x38, 0x4b, 0x26, 0x48, 0x27, 0x68, 0x8f, 0xfc, 0x8f, - 0x70, 0x61, 0x5c, 0xb0, 0x92, 0x83, 0x1c, 0x2b, 0x13, 0x33, 0x78, 0xae, 0x6e, 0x8e, 0x53, 0x37, - 0xd4, 0xd8, 0x9d, 0xc1, 0x4d, 0x97, 0xea, 0x04, 0xed, 0x7d, 0x7a, 0xf1, 0xdf, 0x6d, 0x09, 0x3d, - 0xba, 0x2d, 0xa1, 0xe7, 0xb7, 0x25, 0xf4, 0xcd, 0xc7, 0xb3, 0xdf, 0xe0, 0xf2, 0xef, 0x9f, 0xcd, - 0x95, 0xf4, 0xee, 0x76, 0xf4, 0x32, 0x00, 0x00, 0xff, 0xff, 0xc8, 0x6c, 0x67, 0x07, 0xa7, 0x0a, - 0x00, 0x00, + // 793 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x96, 0xcf, 0x6f, 0xf3, 0x34, + 0x18, 0xc7, 0xe5, 0xee, 0x7d, 0x5f, 0xbd, 0xf3, 0x0e, 0x80, 0xd1, 0xa0, 0x8a, 0xba, 0xae, 0x44, + 0xb0, 0x75, 0x1b, 0x75, 0xd6, 0x6d, 0x08, 0xb4, 0x13, 0xa0, 0x09, 0x24, 0xf6, 0x0b, 0xa5, 0x12, + 0x48, 0x5c, 0xc0, 0x4d, 0x9e,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 0xff, 0x0b, 0x00, 0x00, 0xff, + 0xff, 0xd4, 0x50, 0x60, 0x0e, 0xbb, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -953,6 +961,13 @@ func (m *GetArchivedWorkflowRequest) MarshalToSizedBuffer(dAtA []byte) (int, err i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintWorkflowArchive(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x1a + } if len(m.Namespace) > 0 { i -= len(m.Namespace) copy(dAtA[i:], m.Namespace) @@ -1308,6 +1323,10 @@ func (m *GetArchivedWorkflowRequest) Size() (n int) { if l > 0 { n += 1 + l + sovWorkflowArchive(uint64(l)) } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovWorkflowArchive(uint64(l)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -1702,6 +1721,38 @@ func (m *GetArchivedWorkflowRequest) Unmarshal(dAtA []byte) error { } m.Namespace = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWorkflowArchive + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWorkflowArchive + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWorkflowArchive + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipWorkflowArchive(dAtA[iNdEx:]) diff --git a/pkg/apiclient/workflowarchive/workflow-archive.proto b/pkg/apiclient/workflowarchive/workflow-archive.proto index 825e5a0db2e1..efcb1f405537 100644 --- a/pkg/apiclient/workflowarchive/workflow-archive.proto +++ b/pkg/apiclient/workflowarchive/workflow-archive.proto @@ -15,6 +15,7 @@ message ListArchivedWorkflowsRequest { message GetArchivedWorkflowRequest { string uid = 1; string namespace = 2; + string name = 3; } message DeleteArchivedWorkflowRequest { string uid = 1; diff --git a/sdks/java/client/docs/ArchivedWorkflowServiceApi.md b/sdks/java/client/docs/ArchivedWorkflowServiceApi.md index 4cb983e23952..a58d43147006 100644 --- a/sdks/java/client/docs/ArchivedWorkflowServiceApi.md +++ b/sdks/java/client/docs/ArchivedWorkflowServiceApi.md @@ -85,7 +85,7 @@ Name | Type | Description | Notes # **archivedWorkflowServiceGetArchivedWorkflow** -> IoArgoprojWorkflowV1alpha1Workflow archivedWorkflowServiceGetArchivedWorkflow(uid, namespace) +> IoArgoprojWorkflowV1alpha1Workflow archivedWorkflowServiceGetArchivedWorkflow(uid, namespace, name) @@ -113,8 +113,9 @@ public class Example { ArchivedWorkflowServiceApi apiInstance = new ArchivedWorkflowServiceApi(defaultClient); String uid = "uid_example"; // String | String namespace = "namespace_example"; // String | + String name = "name_example"; // String | try { - IoArgoprojWorkflowV1alpha1Workflow result = apiInstance.archivedWorkflowServiceGetArchivedWorkflow(uid, namespace); + IoArgoprojWorkflowV1alpha1Workflow result = apiInstance.archivedWorkflowServiceGetArchivedWorkflow(uid, namespace, name); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ArchivedWorkflowServiceApi#archivedWorkflowServiceGetArchivedWorkflow"); @@ -133,6 +134,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **uid** | **String**| | **namespace** | **String**| | [optional] + **name** | **String**| | [optional] ### Return type diff --git a/sdks/python/client/argo_workflows/api/archived_workflow_service_api.py b/sdks/python/client/argo_workflows/api/archived_workflow_service_api.py index 5f361bcd2156..7c498027bb10 100644 --- a/sdks/python/client/argo_workflows/api/archived_workflow_service_api.py +++ b/sdks/python/client/argo_workflows/api/archived_workflow_service_api.py @@ -112,6 +112,7 @@ def __init__(self, api_client=None): 'all': [ 'uid', 'namespace', + 'name', ], 'required': [ 'uid', @@ -133,14 +134,18 @@ def __init__(self, api_client=None): (str,), 'namespace': (str,), + 'name': + (str,), }, 'attribute_map': { 'uid': 'uid', 'namespace': 'namespace', + 'name': 'name', }, 'location_map': { 'uid': 'path', 'namespace': 'query', + 'name': 'query', }, 'collection_format_map': { } @@ -608,6 +613,7 @@ def get_archived_workflow( Keyword Args: namespace (str): [optional] + name (str): [optional] _return_http_data_only (bool): response data without head status code and headers. Default is True. _preload_content (bool): if False, the urllib3.HTTPResponse object diff --git a/sdks/python/client/docs/ArchivedWorkflowServiceApi.md b/sdks/python/client/docs/ArchivedWorkflowServiceApi.md index e9f0559051d3..228c380586b8 100644 --- a/sdks/python/client/docs/ArchivedWorkflowServiceApi.md +++ b/sdks/python/client/docs/ArchivedWorkflowServiceApi.md @@ -138,6 +138,7 @@ with argo_workflows.ApiClient(configuration) as api_client: api_instance = archived_workflow_service_api.ArchivedWorkflowServiceApi(api_client) uid = "uid_example" # str | namespace = "namespace_example" # str | (optional) + name = "name_example" # str | (optional) # example passing only required values which don't have defaults set try: @@ -149,7 +150,7 @@ with argo_workflows.ApiClient(configuration) as api_client: # example passing only required values which don't have defaults set # and optional values try: - api_response = api_instance.get_archived_workflow(uid, namespace=namespace) + api_response = api_instance.get_archived_workflow(uid, namespace=namespace, name=name) pprint(api_response) except argo_workflows.ApiException as e: print("Exception when calling ArchivedWorkflowServiceApi->get_archived_workflow: %s\n" % e) @@ -162,6 +163,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **uid** | **str**| | **namespace** | **str**| | [optional] + **name** | **str**| | [optional] ### Return type diff --git a/server/apiserver/argoserver.go b/server/apiserver/argoserver.go index bcd8a3d76301..2d22a805040c 100644 --- a/server/apiserver/argoserver.go +++ b/server/apiserver/argoserver.go @@ -304,15 +304,15 @@ func (as *argoServer) newGRPCServer(instanceIDService instanceid.Service, offloa } grpcServer := grpc.NewServer(sOpts...) - + wfArchiveServer := workflowarchive.NewWorkflowArchiveServer(wfArchive) infopkg.RegisterInfoServiceServer(grpcServer, info.NewInfoServer(as.managedNamespace, links, columns, navColor)) eventpkg.RegisterEventServiceServer(grpcServer, eventServer) eventsourcepkg.RegisterEventSourceServiceServer(grpcServer, eventsource.NewEventSourceServer()) sensorpkg.RegisterSensorServiceServer(grpcServer, sensor.NewSensorServer()) - workflowpkg.RegisterWorkflowServiceServer(grpcServer, workflow.NewWorkflowServer(instanceIDService, offloadNodeStatusRepo)) + workflowpkg.RegisterWorkflowServiceServer(grpcServer, workflow.NewWorkflowServer(instanceIDService, offloadNodeStatusRepo, wfArchiveServer)) workflowtemplatepkg.RegisterWorkflowTemplateServiceServer(grpcServer, workflowtemplate.NewWorkflowTemplateServer(instanceIDService)) cronworkflowpkg.RegisterCronWorkflowServiceServer(grpcServer, cronworkflow.NewCronWorkflowServer(instanceIDService)) - workflowarchivepkg.RegisterArchivedWorkflowServiceServer(grpcServer, workflowarchive.NewWorkflowArchiveServer(wfArchive)) + workflowarchivepkg.RegisterArchivedWorkflowServiceServer(grpcServer, wfArchiveServer) clusterwftemplatepkg.RegisterClusterWorkflowTemplateServiceServer(grpcServer, clusterworkflowtemplate.NewClusterWorkflowTemplateServer(instanceIDService)) grpc_prometheus.Register(grpcServer) return grpcServer diff --git a/server/artifacts/artifact_server.go b/server/artifacts/artifact_server.go index 2a3e8eca7544..6c46fbf8c280 100644 --- a/server/artifacts/artifact_server.go +++ b/server/artifacts/artifact_server.go @@ -124,7 +124,7 @@ func (a *ArtifactServer) GetArtifactFile(w http.ResponseWriter, r *http.Request) uid := id log.WithFields(log.Fields{"namespace": namespace, "uid": uid, "nodeId": nodeId, "artifactName": artifactName}).Info("Get artifact file") - wf, err = a.wfArchive.GetWorkflow(uid) + wf, err = a.wfArchive.GetWorkflow(uid, "", "") if err != nil { a.serverInternalError(err, w) return @@ -287,7 +287,7 @@ func (a *ArtifactServer) getArtifactByUID(w http.ResponseWriter, r *http.Request artifactName := requestPath[4] // We need to know the namespace before we can do gate keeping - wf, err := a.wfArchive.GetWorkflow(uid) + wf, err := a.wfArchive.GetWorkflow(uid, "", "") if err != nil { a.httpFromError(err, w) return diff --git a/server/artifacts/artifact_server_test.go b/server/artifacts/artifact_server_test.go index 9aa2ea9ca908..a9d9aa4577c2 100644 --- a/server/artifacts/artifact_server_test.go +++ b/server/artifacts/artifact_server_test.go @@ -346,7 +346,7 @@ func newServer() *ArtifactServer { ctx := context.WithValue(context.WithValue(context.Background(), auth.KubeKey, kube), auth.WfKey, argo) gatekeeper.On("ContextWithRequest", mock.Anything, mock.Anything).Return(ctx, nil) a := &sqldbmocks.WorkflowArchive{} - a.On("GetWorkflow", "my-uuid").Return(wf, nil) + a.On("GetWorkflow", "my-uuid", "", "").Return(wf, nil) fakeArtifactDriverFactory := func(_ context.Context, _ *wfv1.Artifact, _ resource.Interface) (artifactscommon.ArtifactDriver, error) { return &fakeArtifactDriver{data: []byte("my-data")}, nil diff --git a/server/workflow/workflow_server.go b/server/workflow/workflow_server.go index ef4a5b17cc60..b465e411f97e 100644 --- a/server/workflow/workflow_server.go +++ b/server/workflow/workflow_server.go @@ -18,10 +18,12 @@ import ( "github.com/argoproj/argo-workflows/v3/errors" "github.com/argoproj/argo-workflows/v3/persist/sqldb" workflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflow" + workflowarchivepkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/workflowarchive" "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow" 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" + sutils "github.com/argoproj/argo-workflows/v3/server/utils" argoutil "github.com/argoproj/argo-workflows/v3/util" "github.com/argoproj/argo-workflows/v3/util/fields" "github.com/argoproj/argo-workflows/v3/util/instanceid" @@ -32,21 +34,20 @@ import ( "github.com/argoproj/argo-workflows/v3/workflow/templateresolution" "github.com/argoproj/argo-workflows/v3/workflow/util" "github.com/argoproj/argo-workflows/v3/workflow/validate" - - sutils "github.com/argoproj/argo-workflows/v3/server/utils" ) type workflowServer struct { instanceIDService instanceid.Service offloadNodeStatusRepo sqldb.OffloadNodeStatusRepo hydrator hydrator.Interface + wfArchiveServer workflowarchivepkg.ArchivedWorkflowServiceServer } const latestAlias = "@latest" // NewWorkflowServer returns a new workflowServer -func NewWorkflowServer(instanceIDService instanceid.Service, offloadNodeStatusRepo sqldb.OffloadNodeStatusRepo) workflowpkg.WorkflowServiceServer { - return &workflowServer{instanceIDService, offloadNodeStatusRepo, hydrator.New(offloadNodeStatusRepo)} +func NewWorkflowServer(instanceIDService instanceid.Service, offloadNodeStatusRepo sqldb.OffloadNodeStatusRepo, wfArchiveServer workflowarchivepkg.ArchivedWorkflowServiceServer) workflowpkg.WorkflowServiceServer { + return &workflowServer{instanceIDService, offloadNodeStatusRepo, hydrator.New(offloadNodeStatusRepo), wfArchiveServer} } func (s *workflowServer) CreateWorkflow(ctx context.Context, req *workflowpkg.WorkflowCreateRequest) (*wfv1.Workflow, error) { @@ -590,8 +591,14 @@ func (s *workflowServer) getWorkflow(ctx context.Context, wfClient versioned.Int return latest, nil } wf, err := wfClient.ArgoprojV1alpha1().Workflows(namespace).Get(ctx, name, options) - if err != nil { - return nil, sutils.ToStatusError(err, codes.Internal) + if wf == nil || err != nil { + wf, err = s.wfArchiveServer.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{ + Namespace: namespace, + Name: name, + }) + if err != nil { + return nil, sutils.ToStatusError(err, codes.Internal) + } } return wf, nil } diff --git a/server/workflow/workflow_server_test.go b/server/workflow/workflow_server_test.go index 4cd92647ec40..1d17bba26bca 100644 --- a/server/workflow/workflow_server_test.go +++ b/server/workflow/workflow_server_test.go @@ -23,6 +23,7 @@ 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/workflowarchive" "github.com/argoproj/argo-workflows/v3/util" "github.com/argoproj/argo-workflows/v3/util/instanceid" "github.com/argoproj/argo-workflows/v3/workflow/common" @@ -584,7 +585,24 @@ func getWorkflowServer() (workflowpkg.WorkflowServiceServer, context.Context) { offloadNodeStatusRepo := &mocks.OffloadNodeStatusRepo{} offloadNodeStatusRepo.On("IsEnabled", mock.Anything).Return(true) offloadNodeStatusRepo.On("List", mock.Anything).Return(map[sqldb.UUIDVersion]v1alpha1.Nodes{}, nil) - server := NewWorkflowServer(instanceid.NewService("my-instanceid"), offloadNodeStatusRepo) + + archivedRepo := &mocks.WorkflowArchive{} + + wfaServer := workflowarchive.NewWorkflowArchiveServer(archivedRepo) + archivedRepo.On("GetWorkflow", "", "test", "hello-world-9tql2-test").Return(&v1alpha1.Workflow{ + ObjectMeta: metav1.ObjectMeta{Name: "hello-world-9tql2-test", Namespace: "test"}, + Spec: v1alpha1.WorkflowSpec{ + Entrypoint: "my-entrypoint", + Templates: []v1alpha1.Template{ + {Name: "my-entrypoint", Container: &corev1.Container{}}, + }, + }, + }, nil) + archivedRepo.On("GetWorkflow", "", "test", "not-found").Return(nil, nil) + archivedRepo.On("GetWorkflow", "", "test", "unlabelled").Return(nil, nil) + archivedRepo.On("GetWorkflow", "", "workflows", "latest").Return(nil, nil) + archivedRepo.On("GetWorkflow", "", "workflows", "hello-world-9tql2-not").Return(nil, nil) + server := NewWorkflowServer(instanceid.NewService("my-instanceid"), offloadNodeStatusRepo, wfaServer) kubeClientSet := fake.NewSimpleClientset() wfClientset := v1alpha.NewSimpleClientset(&unlabelledObj, &wfObj1, &wfObj2, &wfObj3, &wfObj4, &wfObj5, &failedWfObj, &wftmpl, &cronwfObj, &cwfTmpl) wfClientset.PrependReactor("create", "workflows", generateNameReactor) @@ -665,7 +683,7 @@ func TestWatchLatestWorkflow(t *testing.T) { func TestGetWorkflowWithNotFound(t *testing.T) { server, ctx := getWorkflowServer() t.Run("Labelled", func(t *testing.T) { - wf, err := getWorkflow(ctx, server, "test", "NotFound") + wf, err := getWorkflow(ctx, server, "test", "not-found") if assert.Error(t, err) { assert.Nil(t, wf) } @@ -693,6 +711,10 @@ func TestGetWorkflow(t *testing.T) { if assert.NoError(t, err) { assert.NotNil(t, wf) } + wf, err = s.getWorkflow(ctx, wfClient, "test", "hello-world-9tql2-test", metav1.GetOptions{}) + if assert.NoError(t, err) { + assert.NotNil(t, wf) + } } func TestValidateWorkflow(t *testing.T) { diff --git a/server/workflowarchive/archived_workflow_server.go b/server/workflowarchive/archived_workflow_server.go index 3e0450ca9c58..6b538e0ab03e 100644 --- a/server/workflowarchive/archived_workflow_server.go +++ b/server/workflowarchive/archived_workflow_server.go @@ -165,7 +165,7 @@ func (w *archivedWorkflowServer) ListArchivedWorkflows(ctx context.Context, req } func (w *archivedWorkflowServer) GetArchivedWorkflow(ctx context.Context, req *workflowarchivepkg.GetArchivedWorkflowRequest) (*wfv1.Workflow, error) { - wf, err := w.wfArchive.GetWorkflow(req.Uid) + wf, err := w.wfArchive.GetWorkflow(req.Uid, req.Namespace, req.Name) if err != nil { return nil, sutils.ToStatusError(err, codes.Internal) } diff --git a/server/workflowarchive/archived_workflow_server_test.go b/server/workflowarchive/archived_workflow_server_test.go index 514c0a36c017..7d3f9c89fac2 100644 --- a/server/workflowarchive/archived_workflow_server_test.go +++ b/server/workflowarchive/archived_workflow_server_test.go @@ -60,8 +60,8 @@ func Test_archivedWorkflowServer(t *testing.T) { repo.On("ListWorkflows", "", "my-name", "my-", minStartAt, maxStartAt, labels.Requirements(nil), 2, 0).Return(wfv1.Workflows{{}}, nil) repo.On("ListWorkflows", "user-ns", "", "", time.Time{}, time.Time{}, labels.Requirements(nil), 2, 0).Return(wfv1.Workflows{{}, {}}, nil) repo.On("CountWorkflows", "", "my-name", "my-", minStartAt, maxStartAt, labels.Requirements(nil)).Return(int64(5), nil) - repo.On("GetWorkflow", "").Return(nil, nil) - repo.On("GetWorkflow", "my-uid").Return(&wfv1.Workflow{ + repo.On("GetWorkflow", "", "", "").Return(nil, nil) + repo.On("GetWorkflow", "my-uid", "", "").Return(&wfv1.Workflow{ ObjectMeta: metav1.ObjectMeta{Name: "my-name"}, Spec: wfv1.WorkflowSpec{ Entrypoint: "my-entrypoint", @@ -70,7 +70,7 @@ func Test_archivedWorkflowServer(t *testing.T) { }, }, }, nil) - repo.On("GetWorkflow", "failed-uid").Return(&wfv1.Workflow{ + repo.On("GetWorkflow", "failed-uid", "", "").Return(&wfv1.Workflow{ ObjectMeta: metav1.ObjectMeta{ Name: "failed-wf", Labels: map[string]string{ @@ -87,7 +87,7 @@ func Test_archivedWorkflowServer(t *testing.T) { "succeeded-node": {Name: "succeeded-node", StartedAt: createdTime, FinishedAt: finishedTime, Phase: wfv1.NodeSucceeded, Message: "succeeded"}}, }, }, nil) - repo.On("GetWorkflow", "resubmit-uid").Return(&wfv1.Workflow{ + repo.On("GetWorkflow", "resubmit-uid", "", "").Return(&wfv1.Workflow{ ObjectMeta: metav1.ObjectMeta{Name: "resubmit-wf"}, Spec: wfv1.WorkflowSpec{ Entrypoint: "my-entrypoint", @@ -200,6 +200,19 @@ func Test_archivedWorkflowServer(t *testing.T) { wf, err := w.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{Uid: "my-uid"}) assert.NoError(t, err) assert.NotNil(t, wf) + + repo.On("GetWorkflow", "", "my-ns", "my-name").Return(&wfv1.Workflow{ + ObjectMeta: metav1.ObjectMeta{Name: "my-name", Namespace: "my-ns"}, + Spec: wfv1.WorkflowSpec{ + Entrypoint: "my-entrypoint", + Templates: []wfv1.Template{ + {Name: "my-entrypoint", Container: &apiv1.Container{}}, + }, + }, + }, nil) + wf, err = w.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{Uid: "", Name: "my-name", Namespace: "my-ns"}) + assert.NoError(t, err) + assert.NotNil(t, wf) }) t.Run("DeleteArchivedWorkflow", func(t *testing.T) { allowed = false