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
100109func (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
115130func (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
178198func (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
306344func (s * WorkflowServer ) TerminateWorkflowExecution (ctx context.Context , req * api.TerminateWorkflowExecutionRequest ) (* empty.Empty , error ) {
0 commit comments