From 2fe69bea9e11f246217dfc14b7bd6b5b1ead82ab Mon Sep 17 00:00:00 2001 From: Yongxuan Zhang Date: Thu, 2 Nov 2023 17:23:04 +0000 Subject: [PATCH] revert change --- pkg/reconciler/taskrun/resources/taskref.go | 12 ++++++------ pkg/reconciler/taskrun/resources/taskref_test.go | 10 +++++----- pkg/reconciler/taskrun/resources/taskspec.go | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/reconciler/taskrun/resources/taskref.go b/pkg/reconciler/taskrun/resources/taskref.go index d1683f6250b..5539f2cf62a 100644 --- a/pkg/reconciler/taskrun/resources/taskref.go +++ b/pkg/reconciler/taskrun/resources/taskref.go @@ -131,9 +131,9 @@ func GetStepActionFunc(tekton clientset.Interface, k8s kubernetes.Interface, req if step.Ref != nil && step.Ref.Resolver != "" && requester != nil { // Return an inline function that implements GetTask by calling Resolver.Get with the specified task type and // casting it to a TaskObject. - return func(ctx context.Context, ref *v1.Ref) (*v1alpha1.StepAction, *v1.RefSource, error) { - resolver := resolution.NewResolver(requester, tr, string(ref.Resolver), trName, namespace, v1.Params{}) - return resolveStepAction(ctx, resolver, ref.Name, namespace, kind, k8s, tekton) + return func(ctx context.Context, name string) (*v1alpha1.StepAction, *v1.RefSource, error) { + resolver := resolution.NewResolver(requester, tr, string(step.Ref.Resolver), trName, namespace, v1.Params{}) + return resolveStepAction(ctx, resolver, name, namespace, kind, k8s, tekton) } } local := &LocalStepActionRefResolver{ @@ -262,12 +262,12 @@ type LocalStepActionRefResolver struct { // GetStepAction will resolve a StepAction from the local cluster using a versioned Tekton client. // It will return an error if it can't find an appropriate StepAction for any reason. -func (l *LocalStepActionRefResolver) GetStepAction(ctx context.Context, ref *v1.Ref) (*v1alpha1.StepAction, *v1.RefSource, error) { +func (l *LocalStepActionRefResolver) GetStepAction(ctx context.Context, name string) (*v1alpha1.StepAction, *v1.RefSource, error) { // If we are going to resolve this reference locally, we need a namespace scope. if l.Namespace == "" { - return nil, nil, fmt.Errorf("must specify namespace to resolve reference to step action %s", ref.Name) + return nil, nil, fmt.Errorf("must specify namespace to resolve reference to step action %s", name) } - stepAction, err := l.Tektonclient.TektonV1alpha1().StepActions(l.Namespace).Get(ctx, ref.Name, metav1.GetOptions{}) + stepAction, err := l.Tektonclient.TektonV1alpha1().StepActions(l.Namespace).Get(ctx, name, metav1.GetOptions{}) if err != nil { return nil, nil, err } diff --git a/pkg/reconciler/taskrun/resources/taskref_test.go b/pkg/reconciler/taskrun/resources/taskref_test.go index 2ccd01e3d9b..80ebe121fb6 100644 --- a/pkg/reconciler/taskrun/resources/taskref_test.go +++ b/pkg/reconciler/taskrun/resources/taskref_test.go @@ -372,7 +372,7 @@ func TestStepActionRef(t *testing.T) { Tektonclient: tektonclient, } - task, refSource, err := lc.GetStepAction(ctx, tc.ref) + task, refSource, err := lc.GetStepAction(ctx, tc.ref.Name) if err != nil { t.Fatalf("Received unexpected error ( %#v )", err) } @@ -435,7 +435,7 @@ func TestStepActionRef_Error(t *testing.T) { Tektonclient: tektonclient, } - _, _, err := lc.GetStepAction(ctx, tc.ref) + _, _, err := lc.GetStepAction(ctx, tc.ref.Name) if err == nil { t.Fatal("Expected error but found nil instead") } @@ -591,7 +591,7 @@ func TestGetStepActionFunc_Local(t *testing.T) { tektonclient := fake.NewSimpleClientset(tc.localStepActions...) fn := resources.GetStepActionFunc(tektonclient, nil, nil, tc.taskRun, &tc.taskRun.Spec.TaskSpec.Steps[0]) - stepAction, refSource, err := fn(ctx, tc.taskRun.Spec.TaskSpec.Steps[0].Ref) + stepAction, refSource, err := fn(ctx, tc.taskRun.Spec.TaskSpec.Steps[0].Ref.Name) if err != nil { t.Fatalf("failed to call stepActionfn: %s", err.Error()) } @@ -644,7 +644,7 @@ func TestGetStepActionFunc_RemoteResolution(t *testing.T) { tektonclient := fake.NewSimpleClientset() fn := resources.GetStepActionFunc(tektonclient, nil, requester, tr, &tr.Spec.TaskSpec.Steps[0]) - resolvedStepAction, resolvedRefSource, err := fn(ctx, tr.Spec.TaskSpec.Steps[0].Ref) + resolvedStepAction, resolvedRefSource, err := fn(ctx, tr.Spec.TaskSpec.Steps[0].Ref.Name) if tc.wantErr { if err == nil { t.Fatalf("expected an error when calling GetStepActionFunc but got none") @@ -703,7 +703,7 @@ func TestGetStepActionFunc_RemoteResolutionInvalidData(t *testing.T) { } tektonclient := fake.NewSimpleClientset() fn := resources.GetStepActionFunc(tektonclient, nil, requester, tr, &tr.Spec.TaskSpec.Steps[0]) - if _, _, err := fn(ctx, tr.Spec.TaskSpec.Steps[0].Ref); err == nil { + if _, _, err := fn(ctx, tr.Spec.TaskSpec.Steps[0].Ref.Name); err == nil { t.Fatalf("expected error due to invalid pipeline data but saw none") } }) diff --git a/pkg/reconciler/taskrun/resources/taskspec.go b/pkg/reconciler/taskrun/resources/taskspec.go index 8b312b8dbb6..59d6dee6f81 100644 --- a/pkg/reconciler/taskrun/resources/taskspec.go +++ b/pkg/reconciler/taskrun/resources/taskspec.go @@ -42,7 +42,7 @@ type ResolvedTask struct { } // GetStepAction is a function used to retrieve StepActions. -type GetStepAction func(context.Context, *v1.Ref) (*v1alpha1.StepAction, *v1.RefSource, error) +type GetStepAction func(context.Context, string) (*v1alpha1.StepAction, *v1.RefSource, error) // GetTask is a function used to retrieve Tasks. // VerificationResult is the result from trusted resources if the feature is enabled. @@ -108,7 +108,7 @@ func GetStepActionsData(ctx context.Context, taskSpec v1.TaskSpec, taskRun *v1.T if step.Ref != nil { s.Ref = nil getStepAction := GetStepActionFunc(tekton, k8s, requester, taskRun, &step) - stepAction, _, err := getStepAction(ctx, step.Ref) + stepAction, _, err := getStepAction(ctx, step.Ref.Name) if err != nil { return nil, err }