Skip to content

Commit

Permalink
feat: Support GetWorkflow regardless of its archival status (#11055)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrytangyuan committed May 22, 2023
1 parent 1e4a376 commit 1f6d1ba
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 92 deletions.
5 changes: 5 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@
"type": "string",
"name": "namespace",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
}
],
"responses": {
Expand Down
18 changes: 9 additions & 9 deletions persist/sqldb/mocks/WorkflowArchive.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion persist/sqldb/null_workflow_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
48 changes: 40 additions & 8 deletions persist/sqldb/workflow_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ 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"
"upper.io/db.v3"
"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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/apiclient/argo-kube-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
153 changes: 102 additions & 51 deletions pkg/apiclient/workflowarchive/workflow-archive.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apiclient/workflowarchive/workflow-archive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ message ListArchivedWorkflowsRequest {
message GetArchivedWorkflowRequest {
string uid = 1;
string namespace = 2;
string name = 3;
}
message DeleteArchivedWorkflowRequest {
string uid = 1;
Expand Down
6 changes: 4 additions & 2 deletions sdks/java/client/docs/ArchivedWorkflowServiceApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Name | Type | Description | Notes

<a name="archivedWorkflowServiceGetArchivedWorkflow"></a>
# **archivedWorkflowServiceGetArchivedWorkflow**
> IoArgoprojWorkflowV1alpha1Workflow archivedWorkflowServiceGetArchivedWorkflow(uid, namespace)
> IoArgoprojWorkflowV1alpha1Workflow archivedWorkflowServiceGetArchivedWorkflow(uid, namespace, name)


Expand Down Expand Up @@ -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");
Expand All @@ -133,6 +134,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**uid** | **String**| |
**namespace** | **String**| | [optional]
**name** | **String**| | [optional]

### Return type

Expand Down
Loading

0 comments on commit 1f6d1ba

Please sign in to comment.