diff --git a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go index 98ea54d6355..d92233488f2 100644 --- a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go +++ b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go @@ -27,7 +27,7 @@ import ( ) // GetPipeline is a function used to retrieve Pipelines. -type GetPipeline func(context.Context, string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) +type GetPipeline func(context.Context, string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) // GetPipelineData will retrieve the Pipeline metadata and Spec associated with the // provided PipelineRun. This can come from a reference Pipeline or from the PipelineRun's diff --git a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go index f88073f8204..a4d0a0c8129 100644 --- a/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go +++ b/pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go @@ -52,7 +52,7 @@ func TestGetPipelineSpec_Ref(t *testing.T) { }, }, } - gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return pipeline, nil, nil } resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt) @@ -90,7 +90,7 @@ func TestGetPipelineSpec_Embedded(t *testing.T) { }, }, } - gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return nil, nil, errors.New("shouldn't be called") } resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt) @@ -118,7 +118,7 @@ func TestGetPipelineSpec_Invalid(t *testing.T) { Name: "mypipelinerun", }, } - gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return nil, nil, errors.New("shouldn't be called") } _, _, err := GetPipelineData(context.Background(), tr, gt) @@ -216,7 +216,7 @@ func TestGetPipelineData_ResolutionSuccess(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { ctx := cfgtesting.SetDefaults(context.Background(), t, tc.defaults) - getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return &v1beta1.Pipeline{ ObjectMeta: *tc.sourceMeta.DeepCopy(), Spec: *tc.sourceSpec.DeepCopy(), @@ -252,7 +252,7 @@ func TestGetPipelineSpec_Error(t *testing.T) { }, }, } - gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return nil, nil, errors.New("something went wrong") } _, _, err := GetPipelineData(context.Background(), tr, gt) @@ -274,7 +274,7 @@ func TestGetPipelineData_ResolutionError(t *testing.T) { }, }, } - getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return nil, nil, errors.New("something went wrong") } ctx := context.Background() @@ -297,7 +297,7 @@ func TestGetPipelineData_ResolvedNilPipeline(t *testing.T) { }, }, } - getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { return nil, nil, nil } ctx := context.Background() diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref.go b/pkg/reconciler/pipelinerun/resources/pipelineref.go index a571f43a70a..e1ab2444283 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref.go @@ -48,7 +48,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien // if the spec is already in the status, do not try to fetch it again, just use it as source of truth. // Same for the Source field in the Status.Provenance. if pipelineRun.Status.PipelineSpec != nil { - return func(_ context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + return func(_ context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { var configSource *v1beta1.ConfigSource if pipelineRun.Status.Provenance != nil { configSource = pipelineRun.Status.Provenance.ConfigSource @@ -67,7 +67,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien case cfg.FeatureFlags.EnableTektonOCIBundles && pr != nil && pr.Bundle != "": // Return an inline function that implements GetTask by calling Resolver.Get with the specified task type and // casting it to a PipelineObject. - return func(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + return func(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { // If there is a bundle url at all, construct an OCI resolver to fetch the pipeline. kc, err := k8schain.New(ctx, k8s, k8schain.Options{ Namespace: namespace, @@ -80,7 +80,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien return resolvePipeline(ctx, resolver, name) } case pr != nil && pr.Resolver != "" && requester != nil: - return func(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + return func(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { stringReplacements, arrayReplacements, objectReplacements := paramsFromPipelineRun(ctx, pipelineRun) for k, v := range GetContextReplacements("", pipelineRun) { stringReplacements[k] = v @@ -103,7 +103,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien // verify the pipeline if there are matching verification policies func GetVerifiedPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset.Interface, requester remoteresource.Requester, pipelineRun *v1beta1.PipelineRun, verificationpolicies []*v1alpha1.VerificationPolicy) rprp.GetPipeline { get := GetPipelineFunc(ctx, k8s, tekton, requester, pipelineRun) - return func(context.Context, string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { + return func(context.Context, string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { p, s, err := get(ctx, pipelineRun.Spec.PipelineRef.Name) if err != nil { return nil, nil, fmt.Errorf("failed to get pipeline: %w", err) @@ -133,7 +133,7 @@ type LocalPipelineRefResolver struct { // return an error if it can't find an appropriate Pipeline for any reason. // TODO: if we want to set source for in-cluster pipeline, set it here. // https://github.com/tektoncd/pipeline/issues/5522 -func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { +func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, 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 pipeline %s", name) @@ -149,8 +149,8 @@ func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string) // resolvePipeline accepts an impl of remote.Resolver and attempts to // fetch a pipeline with given name. An error is returned if the // resolution doesn't work or the returned data isn't a valid -// v1beta1.PipelineObject. -func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) { +// *v1beta1.Pipeline. +func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) { obj, configSource, err := resolver.Get(ctx, "pipeline", name) if err != nil { return nil, nil, err @@ -163,15 +163,15 @@ func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string) } // readRuntimeObjectAsPipeline tries to convert a generic runtime.Object -// into a v1beta1.PipelineObject type so that its meta and spec fields +// into a *v1beta1.Pipeline type so that its meta and spec fields // can be read. v1 object will be converted to v1beta1 and returned. // An error is returned if the given object is not a // PipelineObject or if there is an error validating or upgrading an // older PipelineObject into its v1beta1 equivalent. // TODO(#5541): convert v1beta1 obj to v1 once we use v1 as the stored version -func readRuntimeObjectAsPipeline(ctx context.Context, obj runtime.Object) (v1beta1.PipelineObject, error) { +func readRuntimeObjectAsPipeline(ctx context.Context, obj runtime.Object) (*v1beta1.Pipeline, error) { switch obj := obj.(type) { - case v1beta1.PipelineObject: + case *v1beta1.Pipeline: return obj, nil case *v1.Pipeline: t := &v1beta1.Pipeline{ diff --git a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go index ea7a66ef7f5..903aa8824e3 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelineref_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelineref_test.go @@ -696,43 +696,43 @@ func TestGetVerifiedPipelineFunc_VerifyError(t *testing.T) { name: "unsigned pipeline fails verification with fail no match policy", requester: requesterUnsigned, verificationNoMatchPolicy: config.FailNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "unsigned pipeline fails verification with warn no match policy", requester: requesterUnsigned, verificationNoMatchPolicy: config.WarnNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "unsigned pipeline fails verification with ignore no match policy", requester: requesterUnsigned, verificationNoMatchPolicy: config.IgnoreNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "modified pipeline fails verification with fail no match policy", requester: requesterModified, verificationNoMatchPolicy: config.FailNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "modified pipeline fails verification with warn no match policy", requester: requesterModified, verificationNoMatchPolicy: config.WarnNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "modified pipeline fails verification with ignore no match policy", requester: requesterModified, verificationNoMatchPolicy: config.IgnoreNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, { name: "unmatched pipeline fails with fail no match policy", requester: requesterUnmatched, verificationNoMatchPolicy: config.FailNoMatchPolicy, - expected: nil, + expected: (*v1beta1.Pipeline)(nil), expectedErr: trustedresources.ErrResourceVerificationFailed, }, } diff --git a/pkg/trustedresources/verify.go b/pkg/trustedresources/verify.go index f64b29a9561..4fa43d63e15 100644 --- a/pkg/trustedresources/verify.go +++ b/pkg/trustedresources/verify.go @@ -82,7 +82,7 @@ func VerifyTask(ctx context.Context, taskObj v1beta1.TaskObject, k8s kubernetes. // Return an error when no policies are found and trusted-resources-verification-no-match-policy is set to fail, // or the resource fails to pass matched enforce verification policy // source is from ConfigSource.URI, which will be used to match policy patterns. k8s is used to fetch secret from cluster -func VerifyPipeline(ctx context.Context, pipelineObj v1beta1.PipelineObject, k8s kubernetes.Interface, source string, verificationpolicies []*v1alpha1.VerificationPolicy) error { +func VerifyPipeline(ctx context.Context, pipelineObj *v1beta1.Pipeline, k8s kubernetes.Interface, source string, verificationpolicies []*v1alpha1.VerificationPolicy) error { matchedPolicies, err := getMatchedPolicies(pipelineObj.PipelineMetadata().Name, source, verificationpolicies) if err != nil { if errors.Is(err, ErrNoMatchedPolicies) { diff --git a/pkg/trustedresources/verify_test.go b/pkg/trustedresources/verify_test.go index 70c2731aae1..a94b3d9bb22 100644 --- a/pkg/trustedresources/verify_test.go +++ b/pkg/trustedresources/verify_test.go @@ -368,7 +368,7 @@ func TestVerifyPipeline_Success(t *testing.T) { mismatchedSource := "wrong source" tcs := []struct { name string - pipeline v1beta1.PipelineObject + pipeline *v1beta1.Pipeline source string verificationNoMatchPolicy string }{{ @@ -421,7 +421,7 @@ func TestVerifyPipeline_Error(t *testing.T) { mismatchedSource := "wrong source" tcs := []struct { name string - pipeline v1beta1.PipelineObject + pipeline *v1beta1.Pipeline source string verificationPolicy []*v1alpha1.VerificationPolicy }{{