@@ -108,6 +108,7 @@ type handler struct {
108
108
logger log.Logger
109
109
newCredentialsProvider func (a Authorization ) (credentialsProvider , error )
110
110
argo workflow.Workflow
111
+ argoCtx context.Context
111
112
config * Config
112
113
gitClient gitClient
113
114
}
@@ -150,15 +151,14 @@ func (h handler) healthCheck(w http.ResponseWriter, r *http.Request) {
150
151
func (h handler ) listWorkflows (w http.ResponseWriter , r * http.Request ) {
151
152
// TODO authenticate user can list this workflow once auth figured out
152
153
// TODO fail if project / target does not exist or are not valid format
153
- ctx := r .Context ()
154
154
vars := mux .Vars (r )
155
155
projectName := vars ["projectName" ]
156
156
targetName := vars ["targetName" ]
157
157
158
158
l := h .requestLogger (r , "op" , "list-workflows" , "project" , projectName , "target" , targetName )
159
159
160
160
level .Debug (l ).Log ("message" , "listing workflows" )
161
- workflowIDs , err := h .argo .List (ctx )
161
+ workflowIDs , err := h .argo .List (h . argoCtx )
162
162
if err != nil {
163
163
level .Error (l ).Log ("message" , "error listing workflows" , "error" , err )
164
164
h .errorResponse (w , "error listing workflows" , http .StatusBadRequest , err )
@@ -170,7 +170,7 @@ func (h handler) listWorkflows(w http.ResponseWriter, r *http.Request) {
170
170
prefix := fmt .Sprintf ("%s-%s" , projectName , targetName )
171
171
for _ , workflowID := range workflowIDs {
172
172
if strings .HasPrefix (workflowID , prefix ) {
173
- workflow , err := h .argo .Status (ctx , workflowID )
173
+ workflow , err := h .argo .Status (h . argoCtx , workflowID )
174
174
if err != nil {
175
175
level .Error (l ).Log ("message" , "error retrieving workflows" , "error" , err )
176
176
h .errorResponse (w , "error retrieving workflows" , http .StatusBadRequest , err )
@@ -400,7 +400,7 @@ func (h handler) createWorkflowFromRequest(ctx context.Context, w http.ResponseW
400
400
parameters := workflow .NewParameters (environmentVariablesString , executeCommand , executeContainerImageURI , cwr .TargetName , cwr .ProjectName , cwr .Parameters , credentialsToken )
401
401
402
402
level .Debug (l ).Log ("message" , "creating workflow" )
403
- workflowName , err := h .argo .Submit (ctx , workflowFrom , parameters )
403
+ workflowName , err := h .argo .Submit (h . argoCtx , workflowFrom , parameters )
404
404
if err != nil {
405
405
level .Error (l ).Log ("message" , "error creating workflow" , "error" , err )
406
406
h .errorResponse (w , "error creating workflow" , http .StatusInternalServerError , err )
@@ -425,7 +425,6 @@ func (h handler) createWorkflowFromRequest(ctx context.Context, w http.ResponseW
425
425
426
426
// Gets a workflow
427
427
func (h handler ) getWorkflow (w http.ResponseWriter , r * http.Request ) {
428
- ctx := r .Context ()
429
428
vars := mux .Vars (r )
430
429
workflowName := vars ["workflowName" ]
431
430
// TODO: Workflow name must include -
@@ -436,7 +435,7 @@ func (h handler) getWorkflow(w http.ResponseWriter, r *http.Request) {
436
435
l := h .requestLogger (r , "op" , "get-workflow" , "workflow" , workflowName )
437
436
438
437
level .Debug (l ).Log ("message" , "getting workflow status" )
439
- status , err := h .argo .Status (ctx , workflowName )
438
+ status , err := h .argo .Status (h . argoCtx , workflowName )
440
439
if err != nil {
441
440
level .Error (l ).Log ("message" , "error getting workflow" , "error" , err )
442
441
h .errorResponse (w , "error getting workflow" , http .StatusBadRequest , err )
@@ -506,7 +505,6 @@ func (h handler) getTarget(w http.ResponseWriter, r *http.Request) {
506
505
507
506
// Returns the logs for a workflow
508
507
func (h handler ) getWorkflowLogs (w http.ResponseWriter , r * http.Request ) {
509
- ctx := r .Context ()
510
508
vars := mux .Vars (r )
511
509
workflowName := vars ["workflowName" ]
512
510
// TODO: Workflow name must include -
@@ -517,7 +515,7 @@ func (h handler) getWorkflowLogs(w http.ResponseWriter, r *http.Request) {
517
515
l := h .requestLogger (r , "op" , "get-workflow-logs" , "workflow" , workflowName )
518
516
519
517
level .Debug (l ).Log ("message" , "retrieving workflow logs" )
520
- argoWorkflowLogs , err := h .argo .Logs (ctx , workflowName )
518
+ argoWorkflowLogs , err := h .argo .Logs (h . argoCtx , workflowName )
521
519
if err != nil {
522
520
level .Error (l ).Log ("message" , "error getting workflow logs" , "error" , err )
523
521
h .errorResponse (w , "error getting workflow logs" , http .StatusBadRequest , err )
@@ -535,7 +533,6 @@ func (h handler) getWorkflowLogs(w http.ResponseWriter, r *http.Request) {
535
533
536
534
// Streams workflow logs
537
535
func (h handler ) getWorkflowLogStream (w http.ResponseWriter , r * http.Request ) {
538
- ctx := r .Context ()
539
536
w .Header ().Set ("Content-Type" , "text/plain" )
540
537
vars := mux .Vars (r )
541
538
workflowName := vars ["workflowName" ]
@@ -547,7 +544,7 @@ func (h handler) getWorkflowLogStream(w http.ResponseWriter, r *http.Request) {
547
544
l := h .requestLogger (r , "op" , "get-workflow-log-stream" , "workflow" , workflowName )
548
545
549
546
level .Debug (l ).Log ("message" , "retrieving workflow logs" , "workflow" , workflowName )
550
- err := h .argo .LogStream (ctx , workflowName , w )
547
+ err := h .argo .LogStream (h . argoCtx , workflowName , w )
551
548
if err != nil {
552
549
level .Error (l ).Log ("message" , "error getting workflow logstream" , "error" , err )
553
550
h .errorResponse (w , "error getting workflow logs" , http .StatusBadRequest , err )
0 commit comments