Skip to content

Commit 3d63cf7

Browse files
committed
[TEP-0142] Refactor extractStepActions
This commit moves extractStepActions to a dedicated function called in Taskrun Reconciler, this can help the work for remote resolution of StepAction and also decouple the functions. Signed-off-by: Yongxuan Zhang [email protected]
1 parent 8fd372f commit 3d63cf7

File tree

5 files changed

+134
-101
lines changed

5 files changed

+134
-101
lines changed

pkg/reconciler/pipelinerun/pipelinerun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func (c *Reconciler) resolvePipelineState(
361361
pst,
362362
)
363363
if err != nil {
364-
if tresources.IsGetTaskErrTransient(err) {
364+
if tresources.IsErrTransient(err) {
365365
return nil, err
366366
}
367367
if errors.Is(err, remote.ErrRequestInProgress) {

pkg/reconciler/taskrun/resources/taskref.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func (l *LocalStepActionRefResolver) GetStepAction(ctx context.Context, name str
251251
return stepAction, nil, nil
252252
}
253253

254-
// IsGetTaskErrTransient returns true if an error returned by GetTask is retryable.
255-
func IsGetTaskErrTransient(err error) bool {
254+
// IsErrTransient returns true if an error returned by GetTask/GetStepAction is retryable.
255+
func IsErrTransient(err error) bool {
256256
return strings.Contains(err.Error(), errEtcdLeaderChange)
257257
}
258258

pkg/reconciler/taskrun/resources/taskspec.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2525
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
26+
clientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
2627
resolutionutil "github.com/tektoncd/pipeline/pkg/internal/resolution"
2728
"github.com/tektoncd/pipeline/pkg/trustedresources"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -51,7 +52,7 @@ type GetTaskRun func(string) (*v1.TaskRun, error)
5152
// GetTaskData will retrieve the Task metadata and Spec associated with the
5253
// provided TaskRun. This can come from a reference Task or from the TaskRun's
5354
// metadata and embedded TaskSpec.
54-
func GetTaskData(ctx context.Context, taskRun *v1.TaskRun, getTask GetTask, getStepAction GetStepAction) (*resolutionutil.ResolvedObjectMeta, *v1.TaskSpec, error) {
55+
func GetTaskData(ctx context.Context, taskRun *v1.TaskRun, getTask GetTask) (*resolutionutil.ResolvedObjectMeta, *v1.TaskSpec, error) {
5556
taskMeta := metav1.ObjectMeta{}
5657
taskSpec := v1.TaskSpec{}
5758
var refSource *v1.RefSource
@@ -89,13 +90,6 @@ func GetTaskData(ctx context.Context, taskRun *v1.TaskRun, getTask GetTask, getS
8990
return nil, nil, fmt.Errorf("taskRun %s not providing TaskRef or TaskSpec", taskRun.Name)
9091
}
9192

92-
steps, err := extractStepActions(ctx, taskSpec, getStepAction)
93-
if err != nil {
94-
return nil, nil, err
95-
} else {
96-
taskSpec.Steps = steps
97-
}
98-
9993
taskSpec.SetDefaults(ctx)
10094
return &resolutionutil.ResolvedObjectMeta{
10195
ObjectMeta: &taskMeta,
@@ -104,13 +98,14 @@ func GetTaskData(ctx context.Context, taskRun *v1.TaskRun, getTask GetTask, getS
10498
}, &taskSpec, nil
10599
}
106100

107-
// extractStepActions extracts the StepActions and merges them with the inlined Step specification.
108-
func extractStepActions(ctx context.Context, taskSpec v1.TaskSpec, getStepAction GetStepAction) ([]v1.Step, error) {
101+
// GetStepActionsData extracts the StepActions and merges them with the inlined Step specification.
102+
func GetStepActionsData(ctx context.Context, taskSpec v1.TaskSpec, tr *v1.TaskRun, tekton clientset.Interface) ([]v1.Step, error) {
109103
steps := []v1.Step{}
110104
for _, step := range taskSpec.Steps {
111105
s := step.DeepCopy()
112106
if step.Ref != nil {
113107
s.Ref = nil
108+
getStepAction := GetStepActionFunc(tekton, tr.Namespace)
114109
stepAction, _, err := getStepAction(ctx, step.Ref.Name)
115110
if err != nil {
116111
return nil, err

0 commit comments

Comments
 (0)