Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): add PR name substitution for scheduled runs. #128

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/src/apiserver/template/tekton_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (t *Tekton) ScheduledWorkflow(apiJob *api.Job, namespace string) (*schedule
Workflow: &scheduledworkflow.WorkflowResource{
Parameters: toCRDParameter(apiJob.GetPipelineSpec().GetParameters()),
Spec: workflow.Spec,
ObjectMeta: metav1.ObjectMeta{
Annotations: workflow.Annotations,
Labels: workflow.Labels,
},
},
NoCatchup: util.BoolPointer(apiJob.NoCatchup),
},
Expand Down
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,10 +153,10 @@ 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 = "Workflow"
workflowKind = "PipelineRun"
workflowApiVersion = "tekton.dev/v1beta1"
)

Expand All @@ -165,6 +166,8 @@ func (s *ScheduledWorkflow) NewWorkflow(
}
workflow.Kind = workflowKind
workflow.APIVersion = workflowApiVersion
workflow.Annotations = s.Spec.Workflow.Annotations
workflow.Labels = s.Spec.Workflow.Labels
result := commonutil.NewWorkflow(workflow)

uuid, err := s.uuid.NewRandom()
Expand All @@ -183,7 +186,12 @@ func (s *ScheduledWorkflow) NewWorkflow(
result.OverrideParameters(formattedParams)

result.SetCannonicalLabels(s.Name, nextScheduledEpoch, s.nextIndex())
result.SetLabels(commonutil.LabelKeyWorkflowRunId, uuid.String())
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
3 changes: 3 additions & 0 deletions backend/src/crd/pkg/apis/scheduledworkflow/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ type WorkflowResource struct {

// Specification of the workflow to start.
Spec v1beta1.PipelineRunSpec `json:"spec,omitempty"`

// Metadata from main pipelinerun
metav1.ObjectMeta `json:"metadata,omitempty"`
}

type Parameter struct {
Expand Down

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

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/tidwall/pretty v1.1.0 // indirect
go.uber.org/zap v1.23.0
golang.org/x/net v0.1.0
google.golang.org/api v0.100.0
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a
google.golang.org/grpc v1.50.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum

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

Loading