Skip to content

Commit e244b8e

Browse files
Merge pull request #437 from onepanelio/feat/onepanelio.core.391-create.workflow.link
feat: add workflow execution metadata fields
2 parents 819c57b + b0ec319 commit e244b8e

File tree

9 files changed

+528
-341
lines changed

9 files changed

+528
-341
lines changed

api/api.swagger.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,6 +3171,17 @@
31713171
"items": {
31723172
"$ref": "#/definitions/KeyValue"
31733173
}
3174+
},
3175+
"metadata": {
3176+
"$ref": "#/definitions/WorkflowExecutionMetadata"
3177+
}
3178+
}
3179+
},
3180+
"WorkflowExecutionMetadata": {
3181+
"type": "object",
3182+
"properties": {
3183+
"url": {
3184+
"type": "string"
31743185
}
31753186
}
31763187
},

api/workflow.pb.go

Lines changed: 402 additions & 326 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/workflow.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ message LogEntry {
184184
string content = 2;
185185
}
186186

187+
message WorkflowExecutionMetadata {
188+
string url = 1;
189+
}
190+
187191
message WorkflowExecution {
188192
string createdAt = 1;
189193
string uid = 2;
@@ -198,6 +202,8 @@ message WorkflowExecution {
198202
WorkflowTemplate workflowTemplate = 9;
199203

200204
repeated KeyValue labels = 10;
205+
206+
WorkflowExecutionMetadata metadata = 11;
201207
}
202208

203209
message ArtifactResponse {

pkg/client.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package v1
22

33
import (
4+
"fmt"
45
sq "github.com/Masterminds/squirrel"
56
argoprojv1alpha1 "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
67
"github.com/onepanelio/core/pkg/util/gcs"
8+
"github.com/onepanelio/core/pkg/util/router"
79
"github.com/onepanelio/core/pkg/util/s3"
810
log "github.com/sirupsen/logrus"
911
"k8s.io/client-go/kubernetes"
@@ -89,3 +91,25 @@ func (c *Client) GetS3Client(namespace string, config *ArtifactRepositoryS3Provi
8991
func (c *Client) GetGCSClient(namespace string, config *ArtifactRepositoryGCSProvider) (gcsClient *gcs.Client, err error) {
9092
return gcs.NewClient(namespace, config.ServiceAccountJSON)
9193
}
94+
95+
// GetWebRouter creates a new web router using the system configuration
96+
func (c *Client) GetWebRouter() (router.Web, error) {
97+
sysConfig, err := c.GetSystemConfig()
98+
if err != nil {
99+
return nil, err
100+
}
101+
102+
fqdn := sysConfig.FQDN()
103+
if fqdn == nil {
104+
return nil, fmt.Errorf("unable to get fqdn")
105+
}
106+
107+
protocol := sysConfig.APIProtocol()
108+
if protocol == nil {
109+
return nil, fmt.Errorf("unable to get protcol")
110+
}
111+
112+
webRouter, err := router.NewWebRouter(*protocol, *fqdn)
113+
114+
return webRouter, err
115+
}

pkg/util/router/router.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package router
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// Web provides methods to generate urls for the web client
8+
// this can be used to generate urls for workspaces or workflows when they are ready.
9+
type Web interface {
10+
WorkflowExecution(namespace, uid string) string
11+
}
12+
13+
// web is a basic implementation of WebRouter
14+
type web struct {
15+
protocol string
16+
fqdn string
17+
}
18+
19+
// WorkflowExecution generates a url to view a specific workflow
20+
func (w *web) WorkflowExecution(namespace, uid string) string {
21+
// <protocol>:<fqdn>/<namespace>/workflows/<uid>
22+
return fmt.Sprintf("%v%v/%v/workflows/%v", w.protocol, w.fqdn, namespace, uid)
23+
}
24+
25+
// NewWebRouter creates a new web router used to generate urls for the web client
26+
func NewWebRouter(protocol, fqdn string) (Web, error) {
27+
return &web{
28+
protocol: protocol,
29+
fqdn: fqdn,
30+
}, nil
31+
}

pkg/workflow_execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ func (c *Client) WatchWorkflowExecution(namespace, uid string) (<-chan *Workflow
805805
CreatedAt: workflow.CreationTimestamp.UTC(),
806806
StartedAt: ptr.Time(workflow.Status.StartedAt.UTC()),
807807
FinishedAt: ptr.Time(workflow.Status.FinishedAt.UTC()),
808-
UID: string(workflow.UID),
808+
UID: workflow.Name,
809809
Name: workflow.Name,
810810
Manifest: string(manifest),
811811
}

pkg/workflow_execution_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type WorkflowExecution struct {
1414
CreatedAt time.Time `db:"created_at"`
1515
UID string
1616
Name string
17+
Namespace string
1718
GenerateName string
1819
Parameters []Parameter
1920
ParametersBytes []byte `db:"parameters"` // to load from database

server/cron_workflow_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
3131
}
3232

3333
if cwf.WorkflowExecution != nil {
34-
cronWorkflow.WorkflowExecution = GenApiWorkflowExecution(cwf.WorkflowExecution)
34+
cronWorkflow.WorkflowExecution = apiWorkflowExecution(cwf.WorkflowExecution, nil)
3535
for _, param := range cwf.WorkflowExecution.Parameters {
3636
convertedParam := &api.Parameter{
3737
Name: param.Name,

server/workflow_server.go

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
77
"github.com/onepanelio/core/pkg/util"
88
"github.com/onepanelio/core/pkg/util/pagination"
9+
"github.com/onepanelio/core/pkg/util/router"
910
"github.com/onepanelio/core/server/converter"
1011
"google.golang.org/grpc/codes"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -26,11 +27,9 @@ func NewWorkflowServer() *WorkflowServer {
2627
return &WorkflowServer{}
2728
}
2829

29-
func GenApiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecution) {
30-
return apiWorkflowExecution(wf)
31-
}
32-
33-
func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecution) {
30+
// apiWorkflowExecution converts a package workflow execution to the api version
31+
// router is optional
32+
func apiWorkflowExecution(wf *v1.WorkflowExecution, router router.Web) (workflow *api.WorkflowExecution) {
3433
workflow = &api.WorkflowExecution{
3534
CreatedAt: wf.CreatedAt.Format(time.RFC3339),
3635
Uid: wf.UID,
@@ -46,11 +45,9 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
4645
if wf.FinishedAt != nil && !wf.FinishedAt.IsZero() {
4746
workflow.FinishedAt = wf.FinishedAt.Format(time.RFC3339)
4847
}
49-
5048
if wf.WorkflowTemplate != nil {
5149
workflow.WorkflowTemplate = apiWorkflowTemplate(wf.WorkflowTemplate)
5250
}
53-
5451
if wf.ParametersBytes != nil {
5552
parameters, err := wf.LoadParametersFromBytes()
5653
if err != nil {
@@ -60,6 +57,12 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
6057
workflow.Parameters = converter.ParametersToAPI(parameters)
6158
}
6259

60+
if router != nil {
61+
workflow.Metadata = &api.WorkflowExecutionMetadata{
62+
Url: router.WorkflowExecution(wf.Namespace, wf.UID),
63+
}
64+
}
65+
6366
return
6467
}
6568

@@ -93,8 +96,14 @@ func (s *WorkflowServer) CreateWorkflowExecution(ctx context.Context, req *api.C
9396
if err != nil {
9497
return nil, err
9598
}
99+
wf.Namespace = req.Namespace
96100

97-
return apiWorkflowExecution(wf), nil
101+
webRouter, err := client.GetWebRouter()
102+
if err != nil {
103+
return nil, err
104+
}
105+
106+
return apiWorkflowExecution(wf, webRouter), nil
98107
}
99108

100109
func (s *WorkflowServer) CloneWorkflowExecution(ctx context.Context, req *api.CloneWorkflowExecutionRequest) (*api.WorkflowExecution, error) {
@@ -108,8 +117,14 @@ func (s *WorkflowServer) CloneWorkflowExecution(ctx context.Context, req *api.Cl
108117
if err != nil {
109118
return nil, err
110119
}
120+
wf.Namespace = req.Namespace
121+
122+
webRouter, err := client.GetWebRouter()
123+
if err != nil {
124+
return nil, err
125+
}
111126

112-
return apiWorkflowExecution(wf), nil
127+
return apiWorkflowExecution(wf, webRouter), nil
113128
}
114129

115130
func (s *WorkflowServer) AddWorkflowExecutionStatistics(ctx context.Context, req *api.AddWorkflowExecutionStatisticRequest) (*empty.Empty, error) {
@@ -171,8 +186,13 @@ func (s *WorkflowServer) GetWorkflowExecution(ctx context.Context, req *api.GetW
171186
if labels, ok := mappedLabels[wf.ID]; ok {
172187
wf.Labels = labels
173188
}
189+
wf.Namespace = req.Namespace
174190

175-
return apiWorkflowExecution(wf), nil
191+
webRouter, err := client.GetWebRouter()
192+
if err != nil {
193+
return nil, err
194+
}
195+
return apiWorkflowExecution(wf, webRouter), nil
176196
}
177197

178198
func (s *WorkflowServer) WatchWorkflowExecution(req *api.WatchWorkflowExecutionRequest, stream api.WorkflowService_WatchWorkflowExecutionServer) error {
@@ -187,11 +207,17 @@ func (s *WorkflowServer) WatchWorkflowExecution(req *api.WatchWorkflowExecutionR
187207
return err
188208
}
189209

210+
webRouter, err := client.GetWebRouter()
211+
if err != nil {
212+
return err
213+
}
214+
190215
for wf := range watcher {
191216
if wf == nil {
192217
break
193218
}
194-
if err := stream.Send(apiWorkflowExecution(wf)); err != nil {
219+
wf.Namespace = req.Namespace
220+
if err := stream.Send(apiWorkflowExecution(wf, webRouter)); err != nil {
195221
return err
196222
}
197223
}
@@ -269,9 +295,15 @@ func (s *WorkflowServer) ListWorkflowExecutions(ctx context.Context, req *api.Li
269295
return nil, err
270296
}
271297

298+
webRouter, err := client.GetWebRouter()
299+
if err != nil {
300+
return nil, err
301+
}
302+
272303
var apiWorkflowExecutions []*api.WorkflowExecution
273304
for _, wf := range workflows {
274-
apiWorkflowExecutions = append(apiWorkflowExecutions, apiWorkflowExecution(wf))
305+
wf.Namespace = req.Namespace
306+
apiWorkflowExecutions = append(apiWorkflowExecutions, apiWorkflowExecution(wf, webRouter))
275307
}
276308

277309
count, err := client.CountWorkflowExecutions(req.Namespace, req.WorkflowTemplateUid, req.WorkflowTemplateVersion)
@@ -300,7 +332,13 @@ func (s *WorkflowServer) ResubmitWorkflowExecution(ctx context.Context, req *api
300332
return nil, err
301333
}
302334

303-
return apiWorkflowExecution(wf), nil
335+
wf.Namespace = req.Namespace
336+
webRouter, err := client.GetWebRouter()
337+
if err != nil {
338+
return nil, err
339+
}
340+
341+
return apiWorkflowExecution(wf, webRouter), nil
304342
}
305343

306344
func (s *WorkflowServer) TerminateWorkflowExecution(ctx context.Context, req *api.TerminateWorkflowExecutionRequest) (*empty.Empty, error) {

0 commit comments

Comments
 (0)