tektoncd/pipeline
View on GitHubRefactor: extract shared cleanup-after-resolve helper from taskref.go and pipelineref.go
Open
#9,493 opened on Mar 4, 2026
good first issuehelp wantedkind/cleanup
Repository metrics
- Stars
- (9,013 stars)
- PR merge metrics
- (PR metrics pending)
Description
Summary
There are 6 nearly identical code blocks across taskref.go and pipelineref.go that perform the same post-resolve cleanup pattern:
- Clear
ObjectMeta.OwnerReferences - Optionally call
SetDefaults(ctx) - Verify the resource via
trustedresources.VerifyResource() - Dry-run validate via
apiserver.DryRunValidate() - Restore
ObjectMetaon the mutated object
Each block has a // FIXME: extract this in a function comment.
Locations
pkg/reconciler/taskrun/resources/taskref.go — 4 occurrences:
- Line 236:
resolveStepAction— v1beta1.StepAction case - Line 249:
resolveStepAction— v1alpha1.StepAction case - Line 287:
readRuntimeObjectAsTask— v1beta1.Task case - Line 315:
readRuntimeObjectAsTask— v1.Task case
pkg/reconciler/pipelinerun/resources/pipelineref.go — 2 occurrences:
- Line 155:
readRuntimeObjectAsPipeline— v1beta1.Pipeline case - Line 180:
readRuntimeObjectAsPipeline— v1.Pipeline case
What to do
Extract a shared helper function, something like:
// cleanupAndValidateResolvedObject clears OwnerReferences, sets defaults,
// verifies trusted resources, and dry-run validates the resolved object.
func cleanupAndValidateResolvedObject(ctx context.Context, namespace string, obj client.Object, ...) (runtime.Object, *trustedresources.VerificationResult, error) {
obj.SetOwnerReferences(nil)
obj.SetDefaults(ctx)
vr := trustedresources.VerifyResource(ctx, obj, k8s, refSource, verificationPolicies)
mutated, err := apiserver.DryRunValidate(ctx, namespace, obj, tekton)
if err != nil {
return nil, nil, err
}
// Restore ObjectMeta on the mutated object
...
return mutated, &vr, nil
}
The helper could live in a shared package like pkg/reconciler/internal/resolution/ or alongside the existing files.
How to verify
go build ./...passesgo test ./pkg/reconciler/taskrun/resources/... ./pkg/reconciler/pipelinerun/resources/...passes- No behavior change — this is a pure refactor
/kind cleanup