Skip to content
Open
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
16 changes: 11 additions & 5 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const (
var (
// Check that our Reconciler implements taskrunreconciler.Interface
_ taskrunreconciler.Interface = (*Reconciler)(nil)

// Pod failure reasons that trigger failure of the TaskRun
// Note: ErrImagePull is intentionally not included as it's a transient state
// that Kubernetes will automatically retry before transitioning to ImagePullBackOff
Expand Down Expand Up @@ -753,7 +752,7 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1.TaskRun, rtr *resourc
// Get the randomized volume names assigned to workspace bindings
workspaceVolumes := workspace.CreateVolumes(tr.Spec.Workspaces)

ts, err := applyParamsContextsResultsAndWorkspaces(ctx, tr, rtr, workspaceVolumes)
ts, err := applyParamsContextsResultsAndWorkspaces(ctx, c, tr, rtr, workspaceVolumes)
if err != nil {
logger.Errorf("Error updating task spec parameters, contexts, results and workspaces: %s", err)
return err
Expand Down Expand Up @@ -1142,15 +1141,21 @@ func (c *Reconciler) createPod(ctx context.Context, ts *v1.TaskSpec, tr *v1.Task
return pod, nil
}

// applyParamsContextsResultsAndWorkspaces applies paramater, context, results and workspace substitutions to the TaskSpec.
func applyParamsContextsResultsAndWorkspaces(ctx context.Context, tr *v1.TaskRun, rtr *resources.ResolvedTask, workspaceVolumes map[string]corev1.Volume) (*v1.TaskSpec, error) {
// applyParamsContextsResultsAndWorkspaces applies parameter, context, results and workspace substitutions to the TaskSpec.
func applyParamsContextsResultsAndWorkspaces(ctx context.Context, c *Reconciler, tr *v1.TaskRun, rtr *resources.ResolvedTask, workspaceVolumes map[string]corev1.Volume) (*v1.TaskSpec, error) {
tracer := c.tracerProvider.Tracer(TracerName)
ctx, span := tracer.Start(ctx, "applyParamsContextsResultsAndWorkspaces")
defer span.End()

ts := rtr.TaskSpec.DeepCopy()
var defaults []v1.ParamSpec
if len(ts.Params) > 0 {
defaults = append(defaults, ts.Params...)
}
// Apply parameter substitution from the taskrun.
_, paramSpan := tracer.Start(ctx, "ApplyParameters")
ts = resources.ApplyParameters(ts, tr, defaults...)
paramSpan.End()

// Apply context substitution from the taskrun
ts = resources.ApplyContexts(ts, rtr.TaskName, tr)
Expand Down Expand Up @@ -1182,8 +1187,9 @@ func applyParamsContextsResultsAndWorkspaces(ctx context.Context, tr *v1.TaskRun
ts.Workspaces = append(ts.Workspaces, v1.WorkspaceDeclaration{Name: trw.Name})
}
}
_, workspaceSpan := tracer.Start(ctx, "ApplyWorkspaces")
ts = resources.ApplyWorkspaces(ctx, ts, ts.Workspaces, tr.Spec.Workspaces, workspaceVolumes)

workspaceSpan.End()
return ts, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4406,7 +4406,7 @@ spec:
}
ctx := cfgtesting.EnableAlphaAPIFields(t.Context())
workspaceVolumes := workspace.CreateVolumes(taskRun.Spec.Workspaces)
taskSpec, err := applyParamsContextsResultsAndWorkspaces(ctx, taskRun, rtr, workspaceVolumes)
taskSpec, err := applyParamsContextsResultsAndWorkspaces(ctx, r, taskRun, rtr, workspaceVolumes)
if err != nil {
t.Fatalf("update task spec threw error %v", err)
}
Expand Down Expand Up @@ -4514,7 +4514,7 @@ spec:

workspaceVolumes := workspace.CreateVolumes(taskRun.Spec.Workspaces)
ctx := cfgtesting.EnableAlphaAPIFields(t.Context())
taskSpec, err := applyParamsContextsResultsAndWorkspaces(ctx, taskRun, rtr, workspaceVolumes)
taskSpec, err := applyParamsContextsResultsAndWorkspaces(ctx, r, taskRun, rtr, workspaceVolumes)
if err != nil {
t.Errorf("update task spec threw an error: %v", err)
}
Expand Down Expand Up @@ -4760,7 +4760,7 @@ spec:
}

workspaceVolumes := workspace.CreateVolumes(tr.Spec.Workspaces)
taskSpec, err := applyParamsContextsResultsAndWorkspaces(testAssets.Ctx, tr, rtr, workspaceVolumes)
taskSpec, err := applyParamsContextsResultsAndWorkspaces(testAssets.Ctx, r, tr, rtr, workspaceVolumes)
if err != nil {
t.Fatalf("update task spec threw error %v", err)
}
Expand Down
56 changes: 56 additions & 0 deletions pkg/reconciler/taskrun/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ limitations under the License.
package taskrun

import (
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
"testing"

v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -121,3 +124,56 @@ func TestInitTracing(t *testing.T) {
})
}
}

func TestReconcilerApplyPathsEmitSpans(t *testing.T) {
exporter := tracetest.NewInMemoryExporter()
tp := tracesdk.NewTracerProvider(tracesdk.WithSyncer(exporter))

taskSpec := &v1.TaskSpec{
Steps: []v1.Step{{Name: "s", Image: "foo"}},
}

tr := &v1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "tr",
Namespace: "ns",
},
Spec: v1.TaskRunSpec{
TaskSpec: taskSpec,
},
}

rtr := &resources.ResolvedTask{
TaskName: "my-task",
TaskSpec: taskSpec,
}

r := &Reconciler{
tracerProvider: tp,
}

_, err := applyParamsContextsResultsAndWorkspaces(
t.Context(),
r,
tr,
rtr,
map[string]corev1.Volume{},
)
if err != nil {
t.Fatalf("applyParamsContextsResultsAndWorkspaces() = %v", err)
}

spans := exporter.GetSpans()

found := false
for _, s := range spans {
if s.Name == "applyParamsContextsResultsAndWorkspaces" {
found = true
break
}
}

if !found {
t.Fatal("applyParamsContextsResultsAndWorkspaces span not exported")
}
}