Skip to content

Commit

Permalink
fix(backend): add PR name substitution for scheduled runs. (#1344)
Browse files Browse the repository at this point in the history
Signed-off-by: Humair Khan <[email protected]>
  • Loading branch information
HumairAK authored Sep 11, 2023
1 parent 84f2a85 commit 79272ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/src/crd/controller/scheduledworkflow/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func (c *Controller) submitNewWorkflowIfNotAlreadySubmitted(
}

// If the workflow is not found, we need to create it.
newWorkflow, err := swf.NewWorkflow(nextScheduledEpoch, nowEpoch)
newWorkflow, err := swf.NewWorkflow(nextScheduledEpoch, nowEpoch, workflowName)
createdWorkflow, err := c.workflowClient.Create(ctx, swf.Namespace, newWorkflow)
if err != nil {
return false, "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package util

import (
"fmt"
"github.com/pkg/errors"
"hash/fnv"
"math"
"sort"
Expand Down Expand Up @@ -152,7 +153,7 @@ func (s *ScheduledWorkflow) getWorkflowParametersAsMap() map[string]string {
// the appropriate OwnerReferences on the resource so handleObject can discover
// the Schedule resource that 'owns' it.
func (s *ScheduledWorkflow) NewWorkflow(
nextScheduledEpoch int64, nowEpoch int64) (*commonutil.Workflow, error) {
nextScheduledEpoch int64, nowEpoch int64, workflowName string) (*commonutil.Workflow, error) {

const (
workflowKind = "PipelineRun"
Expand Down Expand Up @@ -185,6 +186,12 @@ func (s *ScheduledWorkflow) NewWorkflow(
result.OverrideParameters(formattedParams)

result.SetCannonicalLabels(s.Name, nextScheduledEpoch, s.nextIndex())
result.SetLabels(commonutil.LabelOriginalPipelineRunName, workflowName)
err = result.ReplaceOrignalPipelineRunName(workflow.Name)
if err != nil {
return nil, errors.Wrap(err, "Failed to replace workflow original pipelineRun name")
}

// Pod pipeline/runid label is used by v2 compatible mode.
result.SetLabels(commonutil.LabelKeyWorkflowRunId, uuid.String())
// Replace {{workflow.uid}} with runId
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/tidwall/pretty v1.1.0 // indirect
go.uber.org/zap v1.24.0
golang.org/x/net v0.11.0
google.golang.org/api v0.128.0
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc
google.golang.org/grpc v1.56.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum

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

0 comments on commit 79272ef

Please sign in to comment.